2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
15 #include <afsconfig.h>
27 /* map a partition id from any partition-style name */
28 afs_int32 volutil_GetPartitionID(aname)
35 if (tc == 0) return -1; /* unknown */
36 /* numbers go straight through */
37 if (tc >= '0' && tc <= '9') {
39 /* this next check is to make the syntax less ambiguous when discriminating
40 * between volume numbers and partition IDs. This less things like
41 * bos salvage do some reasonability checks its input w/o checking
42 * to see if the partition is really on the server.
44 if (temp < 0 || temp > 25) return -1;
47 /* otherwise check for vicepa or /vicepa, or just plain "a" */
49 if (strlen(aname) <= 2) {
52 else if (!strncmp(aname, "/vicep", 6)) {
53 strncpy(ascii, aname+6, 2);
55 else if (!strncmp(aname, "vicep", 5)) {
56 strncpy(ascii, aname+5, 2);
58 else return -1; /* bad partition name */
59 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
60 and are numbered from 0. Do the appropriate conversion */
62 /* one char name, 0..25 */
63 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
64 return ascii[0] - 'a';
67 /* two char name, 26 .. <whatever> */
68 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
69 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
70 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
74 /* map a partition number back into a partition string */
75 #define BAD_VID "BAD VOLUME ID"
76 #define BAD_VID_LEN (sizeof(BAD_VID))
77 char *volutil_PartitionName_r(int avalue, char *tbuffer, int buflen)
82 if (buflen < BAD_VID_LEN) {
84 (void) strcpy(tbuffer, "SPC");
89 bzero(tbuffer, buflen);
90 tempString[1] = tempString[2] = 0;
91 strcpy(tbuffer, "/vicep");
92 if (avalue < 0 || avalue >= (26*26+26)) {
93 strcpy(tbuffer, "BAD VOLUME ID");
95 else if (avalue <= 25) {
96 tempString[0] = 'a'+avalue;
97 strcat(tbuffer, tempString);
102 tempString[0] = i + 'a';
103 tempString[1] = (avalue % 26) + 'a';
104 strcat(tbuffer, tempString);
109 char *volutil_PartitionName(int avalue)
111 #define VPN_TBUFLEN 64
112 static char tbuffer[VPN_TBUFLEN];
113 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN-1);
116 /* is this a digit or a digit-like thing? */
117 static int ismeta(ac, abase)
120 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
121 if (ac >= '0' && ac <= '7') return 1;
122 if (abase <= 8) return 0;
123 if (ac >= '8' && ac <= '9') return 1;
124 if (abase <= 10) return 0;
125 if (ac >= 'a' && ac <= 'f') return 1;
126 if (ac >= 'A' && ac <= 'F') return 1;
130 /* given that this is a digit or a digit-like thing, compute its value */
131 static int getmeta(ac)
133 if (ac >= '0' && ac <= '9') return ac - '0';
134 if (ac >= 'a' && ac <= 'f') return ac - 'a' + 10;
135 if (ac >= 'A' && ac <= 'F') return ac - 'A' + 10;
139 afs_int32 util_GetInt32 (as, aval)
143 register afs_int32 total;
148 total = 0; /* initialize things */
151 /* skip over leading spaces */
153 if (tc != ' ' && tc != '\t') break;
159 as++; /* skip over character */
162 /* compute the base */
165 if (*as == 'x' || *as == 'X') {
173 /* compute the # itself */
175 if (!ismeta(tc, base)) return -1;
177 total += getmeta(tc);
181 if (negative) *aval = -total;
191 register afs_uint32 total;
195 total = 0; /* initialize things */
197 /* skip over leading spaces */
199 if (tc != ' ' && tc != '\t') break;
202 /* compute the base */
205 if (*as == 'x' || *as == 'X') {
213 /* compute the # itself */
215 if (!ismeta(tc, base)) return -1;
217 total += getmeta(tc);