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>
21 /* map a partition id from any partition-style name */
23 volutil_GetPartitionID(char *aname)
31 return -1; /* unknown */
32 /* numbers go straight through */
33 if (tc >= '0' && tc <= '9') {
35 /* this next check is to make the syntax less ambiguous when discriminating
36 * between volume numbers and partition IDs. This less things like
37 * bos salvage do some reasonability checks its input w/o checking
38 * to see if the partition is really on the server.
40 if (temp < 0 || temp > 25)
45 /* otherwise check for vicepa or /vicepa, or just plain "a" */
47 if (strlen(aname) <= 2) {
49 } else if (!strncmp(aname, "/vicep", 6)) {
50 strncpy(ascii, aname + 6, 2);
51 } else if (!strncmp(aname, "vicep", 5)) {
52 strncpy(ascii, aname + 5, 2);
54 return -1; /* bad partition name */
55 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
56 * and are numbered from 0. Do the appropriate conversion */
58 /* one char name, 0..25 */
59 if (ascii[0] < 'a' || ascii[0] > 'z')
60 return -1; /* wrongo */
61 return ascii[0] - 'a';
63 /* two char name, 26 .. <whatever> */
64 if (ascii[0] < 'a' || ascii[0] > 'z')
65 return -1; /* wrongo */
66 if (ascii[1] < 'a' || ascii[1] > 'z')
67 return -1; /* just as bad */
68 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
72 /* map a partition number back into a partition string */
73 #define BAD_VID "BAD VOLUME ID"
74 #define BAD_VID_LEN (sizeof(BAD_VID))
76 volutil_PartitionName_r(int avalue, char *tbuffer, int buflen)
81 if (buflen < BAD_VID_LEN) {
83 (void)strcpy(tbuffer, "SPC");
88 memset(tbuffer, 0, buflen);
89 tempString[1] = tempString[2] = 0;
90 strcpy(tbuffer, "/vicep");
91 if (avalue < 0 || avalue >= (26 * 26 + 26)) {
92 strcpy(tbuffer, "BAD VOLUME ID");
93 } else if (avalue <= 25) {
94 tempString[0] = 'a' + avalue;
95 strcat(tbuffer, tempString);
99 tempString[0] = i + 'a';
100 tempString[1] = (avalue % 26) + 'a';
101 strcat(tbuffer, tempString);
107 volutil_PartitionName(int avalue)
109 #define VPN_TBUFLEN 64
110 static char tbuffer[VPN_TBUFLEN];
111 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN - 1);
114 /* is this a digit or a digit-like thing? */
116 ismeta(register int ac, register int abase)
118 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
119 if (ac >= '0' && ac <= '7')
123 if (ac >= '8' && ac <= '9')
127 if (ac >= 'a' && ac <= 'f')
129 if (ac >= 'A' && ac <= 'F')
134 /* given that this is a digit or a digit-like thing, compute its value */
136 getmeta(register int ac)
138 if (ac >= '0' && ac <= '9')
140 if (ac >= 'a' && ac <= 'f')
141 return ac - 'a' + 10;
142 if (ac >= 'A' && ac <= 'F')
143 return ac - 'A' + 10;
148 util_GetInt32(register char *as, afs_int32 * aval)
150 register afs_int32 total;
155 total = 0; /* initialize things */
158 /* skip over leading spaces */
160 if (tc != ' ' && tc != '\t')
167 as++; /* skip over character */
170 /* compute the base */
173 if (*as == 'x' || *as == 'X') {
181 /* compute the # itself */
183 if (!ismeta(tc, base))
186 total += getmeta(tc);
198 util_GetUInt32(register char *as, afs_uint32 * aval)
200 register afs_uint32 total;
204 total = 0; /* initialize things */
206 /* skip over leading spaces */
208 if (tc != ' ' && tc != '\t')
212 /* compute the base */
215 if (*as == 'x' || *as == 'X') {
223 /* compute the # itself */
225 if (!ismeta(tc, base))
228 total += getmeta(tc);