]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE14-volname-cleanup-20041207
authorHarald Barth <haba@pdc.kth.se>
Tue, 7 Dec 2004 16:37:09 +0000 (16:37 +0000)
committerDerrick Brashear <shadow@dementia.org>
Tue, 7 Dec 2004 16:37:09 +0000 (16:37 +0000)
cleanup how volname or id number is parsed
volname-cleanup-20041207

(cherry picked from commit d6c8b023bb580ccb48198fb4ee070b9e1f950f51)

src/volser/vsutils.c

index f103a27ed9a82d4d791aad1fecb01e00e9982b97..cd78bba4d686c4c6fc6bd17aaa50d8e4d43b2d09 100644 (file)
@@ -490,67 +490,34 @@ vsu_GetVolumeID(astring, acstruct, errp)
      afs_int32 *errp;
      char *astring;
 {
-    afs_uint32 tc, value;
-
-    char *str, *ptr, volname[VOLSER_OLDMAXVOLNAME + 1];
-    int tryname, curval;
+    afs_uint32 value;
+    char volname[VOLSER_OLDMAXVOLNAME + 1];
     struct nvldbentry entry;
     afs_int32 vcode = 0;
     int total;
 
     *errp = 0;
-    total = strlen(astring);
-    str = astring;
-    ptr = astring;
-    tryname = 0;
-    while ((curval = *str++)) {
-       if (curval < '0' || curval > '9')
-           tryname = 1;
-    }
 
-    if (tryname) {
-       vsu_ExtractName(volname, astring);
-       vcode = VLDB_GetEntryByName(volname, &entry);
-       if (!vcode) {
-           if (!strcmp(&astring[total - 9], ".readonly"))
-               return entry.volumeId[ROVOL];
-           else if ((!strcmp(&astring[total - 7], ".backup")))
-               return entry.volumeId[BACKVOL];
-           else
-               return (entry.volumeId[RWVOL]);
-       } else {
-           *errp = vcode;
-           return 0;           /* can't find volume */
-       }
+    if (isdigit(astring[0])) {
+       char *end;
+       afs_uint32 result;
+       result = strtoul(astring, &end, 10);
+       if (result != ULONG_MAX && *end == '\0')
+           return result;
     }
 
-    value = 0;
-    while ((tc = *astring++)) {
-       if (tc & 0x80) {
-           if (!tryname)
-               fprintf(STDERR, "goofed in volid \n");
-           else {
-               fprintf(STDERR, "Could not get entry from vldb for %s\n",
-                       ptr);
-               PrintError("", vcode);
-           }
-           *errp = EINVAL;
-           return 0;
-       }
-       if (tc < '0' || tc > '9') {
-           if (!tryname)
-               fprintf(STDERR,
-                       "internal error: out of range char in vol ID\n");
-           else {
-               fprintf(STDERR, "Could not get entry from vldb for %s\n",
-                       ptr);
-               PrintError("", vcode);
-           }
-           *errp = ERANGE;
-           return 0;
-       }
-       value *= 10;
-       value += (tc - '0');
+    /* It was not a volume number but something else */
+    total = strlen(astring);
+    vsu_ExtractName(volname, astring);
+    vcode = VLDB_GetEntryByName(volname, &entry);
+    if (!vcode) {
+      if (!strcmp(&astring[total - 9], ".readonly"))
+       return entry.volumeId[ROVOL];
+      else if ((!strcmp(&astring[total - 7], ".backup")))
+       return entry.volumeId[BACKVOL];
+      else
+       return (entry.volumeId[RWVOL]);
     }
-    return value;
+    *errp = vcode;
+    return 0;          /* can't find volume */
 }