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 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV)
24 /* map a partition id from any partition-style name */
25 afs_int32 volutil_GetPartitionID(aname)
32 if (tc == 0) return -1; /* unknown */
33 /* numbers go straight through */
34 if (tc >= '0' && tc <= '9') {
36 /* this next check is to make the syntax less ambiguous when discriminating
37 * between volume numbers and partition IDs. This less things like
38 * bos salvage do some reasonability checks its input w/o checking
39 * to see if the partition is really on the server.
41 if (temp < 0 || temp > 25) return -1;
44 /* otherwise check for vicepa or /vicepa, or just plain "a" */
46 if (strlen(aname) <= 2) {
49 else if (!strncmp(aname, "/vicep", 6)) {
50 strncpy(ascii, aname+6, 2);
52 else if (!strncmp(aname, "vicep", 5)) {
53 strncpy(ascii, aname+5, 2);
55 else return -1; /* bad partition name */
56 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
57 and are numbered from 0. Do the appropriate conversion */
59 /* one char name, 0..25 */
60 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
61 return ascii[0] - 'a';
64 /* two char name, 26 .. <whatever> */
65 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
66 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
67 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
71 /* map a partition number back into a partition string */
72 #define BAD_VID "BAD VOLUME ID"
73 #define BAD_VID_LEN (sizeof(BAD_VID))
74 char *volutil_PartitionName_r(int avalue, char *tbuffer, int buflen)
79 if (buflen < BAD_VID_LEN) {
81 (void) strcpy(tbuffer, "SPC");
86 bzero(tbuffer, buflen);
87 tempString[1] = tempString[2] = 0;
88 strcpy(tbuffer, "/vicep");
89 if (avalue < 0 || avalue >= (26*26+26)) {
90 strcpy(tbuffer, "BAD VOLUME ID");
92 else if (avalue <= 25) {
93 tempString[0] = 'a'+avalue;
94 strcat(tbuffer, tempString);
99 tempString[0] = i + 'a';
100 tempString[1] = (avalue % 26) + 'a';
101 strcat(tbuffer, tempString);
106 char *volutil_PartitionName(int avalue)
108 #define VPN_TBUFLEN 64
109 static char tbuffer[VPN_TBUFLEN];
110 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN-1);
113 /* is this a digit or a digit-like thing? */
114 static int ismeta(ac, abase)
117 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
118 if (ac >= '0' && ac <= '7') return 1;
119 if (abase <= 8) return 0;
120 if (ac >= '8' && ac <= '9') return 1;
121 if (abase <= 10) return 0;
122 if (ac >= 'a' && ac <= 'f') return 1;
123 if (ac >= 'A' && ac <= 'F') return 1;
127 /* given that this is a digit or a digit-like thing, compute its value */
128 static int getmeta(ac)
130 if (ac >= '0' && ac <= '9') return ac - '0';
131 if (ac >= 'a' && ac <= 'f') return ac - 'a' + 10;
132 if (ac >= 'A' && ac <= 'F') return ac - 'A' + 10;
136 afs_int32 util_GetInt32 (as, aval)
140 register afs_int32 total;
145 total = 0; /* initialize things */
148 /* skip over leading spaces */
150 if (tc != ' ' && tc != '\t') break;
156 as++; /* skip over character */
159 /* compute the base */
162 if (*as == 'x' || *as == 'X') {
170 /* compute the # itself */
172 if (!ismeta(tc, base)) return -1;
174 total += getmeta(tc);
178 if (negative) *aval = -total;