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>
22 * map a partition id from any partition-style name.
24 * @param[in] aname partition name string
26 * @return partition index number
27 * @retval -1 invalid partition name
29 * @see volutil_PartitionName2_r
30 * @see volutil_PartitionName_r
31 * @see volutil_PartitionName
34 volutil_GetPartitionID(char *aname)
42 return -1; /* unknown */
43 /* numbers go straight through */
44 if (tc >= '0' && tc <= '9') {
46 /* this next check is to make the syntax less ambiguous when discriminating
47 * between volume numbers and partition IDs. This less things like
48 * bos salvage do some reasonability checks its input w/o checking
49 * to see if the partition is really on the server.
51 if (temp < 0 || temp > 25)
56 /* otherwise check for vicepa or /vicepa, or just plain "a" */
58 if (strlen(aname) <= 2) {
60 } else if (!strncmp(aname, "/vicep", 6)) {
61 strncpy(ascii, aname + 6, 2);
62 } else if (!strncmp(aname, "vicep", 5)) {
63 strncpy(ascii, aname + 5, 2);
65 return -1; /* bad partition name */
66 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz,
67 * and are numbered from 0. Do the appropriate conversion */
69 /* one char name, 0..25 */
70 if (ascii[0] < 'a' || ascii[0] > 'z')
71 return -1; /* wrongo */
72 return ascii[0] - 'a';
74 /* two char name, 26 .. <whatever> */
75 if (ascii[0] < 'a' || ascii[0] > 'z')
76 return -1; /* wrongo */
77 if (ascii[1] < 'a' || ascii[1] > 'z')
78 return -1; /* just as bad */
79 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
84 * convert a partition index number into a partition name string (/vicepXX).
86 * @param[in] part partition index number
87 * @param[out] tbuffer buffer in which to store name
88 * @param[in] buflen length of tbuffer
90 * @return operation status
92 * @retval -1 buffer too short
93 * @retval -2 invalid partition id
95 * @see volutil_PartitionName_r
96 * @see volutil_PartitionName
97 * @see volutil_GetPartitionID
100 volutil_PartitionName2_r(afs_int32 part, char *tbuffer, size_t buflen)
105 if (part < 0 || part >= (26 * 26 + 26)) {
109 tempString[1] = tempString[2] = 0;
110 strncpy(tbuffer, "/vicep", buflen);
112 tempString[0] = 'a' + part;
116 tempString[0] = i + 'a';
117 tempString[1] = (part % 26) + 'a';
119 if (strlcat(tbuffer, tempString, buflen) >= buflen) {
125 #define BAD_VID "BAD VOLUME ID"
126 #define BAD_VID_LEN (sizeof(BAD_VID))
128 * convert a partition index number into a partition name string (/vicepXX).
130 * @param[in] part partition index number
131 * @param[out] tbuffer buffer in which to store name
132 * @param[in] buflen length of tbuffer
134 * @return partition name string
135 * @retval "" buffer too short
136 * @retval "SPC" buffer too short
137 * @retval "BAD VOLUME ID" avalue contains an invalid partition index
139 * @note you may wish to consider using volutil_PartitionName2_r, as its
140 * error handling is more standard
142 * @see volutil_PartitionName2_r
143 * @see volutil_PartitionName
144 * @see volutil_GetPartitionID
147 volutil_PartitionName_r(int part, char *tbuffer, int buflen)
151 if (buflen < BAD_VID_LEN) {
152 strlcpy(tbuffer, "SPC", buflen);
156 code = volutil_PartitionName2_r(part, tbuffer, buflen);
159 strlcpy(tbuffer, BAD_VID, buflen);
166 * convert a partition index number into a partition name string (/vicepXX).
168 * @param[in] avalue partition index number
170 * @return partition name string
171 * @retval "BAD VOLUME ID" avalue contains an invalid partition index
173 * @warning this interface is not re-entrant
175 * @see volutil_PartitionName2_r
176 * @see volutil_PartitionName_r
177 * @see volutil_GetPartitionID
180 volutil_PartitionName(int avalue)
182 #define VPN_TBUFLEN 64
183 static char tbuffer[VPN_TBUFLEN];
184 return volutil_PartitionName_r(avalue, tbuffer, VPN_TBUFLEN - 1);
187 /* is this a digit or a digit-like thing? */
189 ismeta(register int ac, register int abase)
191 /* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
192 if (ac >= '0' && ac <= '7')
196 if (ac >= '8' && ac <= '9')
200 if (ac >= 'a' && ac <= 'f')
202 if (ac >= 'A' && ac <= 'F')
207 /* given that this is a digit or a digit-like thing, compute its value */
209 getmeta(register int ac)
211 if (ac >= '0' && ac <= '9')
213 if (ac >= 'a' && ac <= 'f')
214 return ac - 'a' + 10;
215 if (ac >= 'A' && ac <= 'F')
216 return ac - 'A' + 10;
221 util_GetInt32(register char *as, afs_int32 * aval)
223 register afs_int32 total;
228 total = 0; /* initialize things */
231 /* skip over leading spaces */
233 if (tc != ' ' && tc != '\t')
240 as++; /* skip over character */
243 /* compute the base */
246 if (*as == 'x' || *as == 'X') {
254 /* compute the # itself */
256 if (!ismeta(tc, base))
259 total += getmeta(tc);
271 util_GetUInt32(register char *as, afs_uint32 * aval)
273 register afs_uint32 total;
277 total = 0; /* initialize things */
279 /* skip over leading spaces */
281 if (tc != ' ' && tc != '\t')
285 /* compute the base */
288 if (*as == 'x' || *as == 'X') {
296 /* compute the # itself */
298 if (!ismeta(tc, base))
301 total += getmeta(tc);