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
10 #include <afsconfig.h>
11 #include <afs/param.h>
27 /* map a partition id from any partition-style name */
29 volutil_GetPartitionID(char *aname)
37 return -1; /* unknown */
38 /* numbers go straight through */
39 if (tc >= '0' && tc <= '9') {
41 /* this next check is to make the syntax less ambiguous when discriminating
42 * between volume numbers and partition IDs. This less things like
43 * bos salvage do some reasonability checks its input w/o checking
44 * to see if the partition is really on the server.
46 if (temp < 0 || temp > 25)
51 /* otherwise check for vicepa or /vicepa, or just plain "a" */
53 if (strlen(aname) <= 2) {
55 } else if (!strncmp(aname, "/vicep", 6)) {
56 strncpy(ascii, aname + 6, 2);
57 } else if (!strncmp(aname, "vicep", 5)) {
58 strncpy(ascii, aname + 5, 2);
60 return -1; /* bad partition name */
61 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
62 * and are numbered from 0. Do the appropriate conversion */
64 /* one char name, 0..25 */
65 if (ascii[0] < 'a' || ascii[0] > 'z')
66 return -1; /* wrongo */
67 return ascii[0] - 'a';
69 /* two char name, 26 .. <whatever> */
70 if (ascii[0] < 'a' || ascii[0] > 'z')
71 return -1; /* wrongo */
72 if (ascii[1] < 'a' || ascii[1] > 'z')
73 return -1; /* just as bad */
74 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
78 /* map a partition number back into a partition string */
79 #define BAD_VID "BAD VOLUME ID"
80 #define BAD_VID_LEN (sizeof(BAD_VID))
82 volutil_PartitionName_r(int avalue, char *tbuffer, int buflen)
87 if (buflen < BAD_VID_LEN) {
89 (void)strcpy(tbuffer, "SPC");
94 memset(tbuffer, 0, buflen);
95 tempString[1] = tempString[2] = 0;
96 strcpy(tbuffer, "/vicep");
97 if (avalue < 0 || avalue >= (26 * 26 + 26)) {
98 strcpy(tbuffer, "BAD VOLUME ID");
99 } else if (avalue <= 25) {
100 tempString[0] = 'a' + avalue;
101 strcat(tbuffer, tempString);
105 tempString[0] = i + 'a';
106 tempString[1] = (avalue % 26) + 'a';
107 strcat(tbuffer, tempString);
113 volutil_PartitionName(int avalue)
115 #define VPN_TBUFLEN 64
116 static char tbuffer[VPN_TBUFLEN];
117 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN - 1);
120 /* is this a digit or a digit-like thing? */
122 ismeta(register int ac, register int abase)
124 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
125 if (ac >= '0' && ac <= '7')
129 if (ac >= '8' && ac <= '9')
133 if (ac >= 'a' && ac <= 'f')
135 if (ac >= 'A' && ac <= 'F')
140 /* given that this is a digit or a digit-like thing, compute its value */
142 getmeta(register int ac)
144 if (ac >= '0' && ac <= '9')
146 if (ac >= 'a' && ac <= 'f')
147 return ac - 'a' + 10;
148 if (ac >= 'A' && ac <= 'F')
149 return ac - 'A' + 10;
154 util_GetInt32(register char *as, afs_int32 * aval)
156 register afs_int32 total;
161 total = 0; /* initialize things */
164 /* skip over leading spaces */
166 if (tc != ' ' && tc != '\t')
173 as++; /* skip over character */
176 /* compute the base */
179 if (*as == 'x' || *as == 'X') {
187 /* compute the # itself */
189 if (!ismeta(tc, base))
192 total += getmeta(tc);
204 util_GetUInt32(register char *as, afs_uint32 * aval)
206 register afs_uint32 total;
210 total = 0; /* initialize things */
212 /* skip over leading spaces */
214 if (tc != ' ' && tc != '\t')
218 /* compute the base */
221 if (*as == 'x' || *as == 'X') {
229 /* compute the # itself */
231 if (!ismeta(tc, base))
234 total += getmeta(tc);