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 <afs/param.h>
11 #include <afsconfig.h>
26 /* map a partition id from any partition-style name */
27 afs_int32 volutil_GetPartitionID(aname)
34 if (tc == 0) return -1; /* unknown */
35 /* numbers go straight through */
36 if (tc >= '0' && tc <= '9') {
38 /* this next check is to make the syntax less ambiguous when discriminating
39 * between volume numbers and partition IDs. This less things like
40 * bos salvage do some reasonability checks its input w/o checking
41 * to see if the partition is really on the server.
43 if (temp < 0 || temp > 25) return -1;
46 /* otherwise check for vicepa or /vicepa, or just plain "a" */
48 if (strlen(aname) <= 2) {
51 else if (!strncmp(aname, "/vicep", 6)) {
52 strncpy(ascii, aname+6, 2);
54 else if (!strncmp(aname, "vicep", 5)) {
55 strncpy(ascii, aname+5, 2);
57 else return -1; /* bad partition name */
58 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
59 and are numbered from 0. Do the appropriate conversion */
61 /* one char name, 0..25 */
62 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
63 return ascii[0] - 'a';
66 /* two char name, 26 .. <whatever> */
67 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
68 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
69 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
73 /* map a partition number back into a partition string */
74 #define BAD_VID "BAD VOLUME ID"
75 #define BAD_VID_LEN (sizeof(BAD_VID))
76 char *volutil_PartitionName_r(int avalue, char *tbuffer, int buflen)
81 if (buflen < BAD_VID_LEN) {
83 (void) strcpy(tbuffer, "SPC");
88 bzero(tbuffer, 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");
94 else if (avalue <= 25) {
95 tempString[0] = 'a'+avalue;
96 strcat(tbuffer, tempString);
101 tempString[0] = i + 'a';
102 tempString[1] = (avalue % 26) + 'a';
103 strcat(tbuffer, tempString);
108 char *volutil_PartitionName(int avalue)
110 #define VPN_TBUFLEN 64
111 static char tbuffer[VPN_TBUFLEN];
112 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN-1);
115 /* is this a digit or a digit-like thing? */
116 static int ismeta(ac, abase)
119 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
120 if (ac >= '0' && ac <= '7') return 1;
121 if (abase <= 8) return 0;
122 if (ac >= '8' && ac <= '9') return 1;
123 if (abase <= 10) return 0;
124 if (ac >= 'a' && ac <= 'f') return 1;
125 if (ac >= 'A' && ac <= 'F') return 1;
129 /* given that this is a digit or a digit-like thing, compute its value */
130 static int getmeta(ac)
132 if (ac >= '0' && ac <= '9') return ac - '0';
133 if (ac >= 'a' && ac <= 'f') return ac - 'a' + 10;
134 if (ac >= 'A' && ac <= 'F') return ac - 'A' + 10;
138 afs_int32 util_GetInt32 (as, aval)
142 register afs_int32 total;
147 total = 0; /* initialize things */
150 /* skip over leading spaces */
152 if (tc != ' ' && tc != '\t') break;
158 as++; /* skip over character */
161 /* compute the base */
164 if (*as == 'x' || *as == 'X') {
172 /* compute the # itself */
174 if (!ismeta(tc, base)) return -1;
176 total += getmeta(tc);
180 if (negative) *aval = -total;
190 register afs_uint32 total;
194 total = 0; /* initialize things */
196 /* skip over leading spaces */
198 if (tc != ' ' && tc != '\t') break;
201 /* compute the base */
204 if (*as == 'x' || *as == 'X') {
212 /* compute the # itself */
214 if (!ismeta(tc, base)) return -1;
216 total += getmeta(tc);