From d6c8b023bb580ccb48198fb4ee070b9e1f950f51 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 7 Dec 2004 16:36:43 +0000 Subject: [PATCH] volname-cleanup-20041207 cleanup how volname or id number is parsed --- src/volser/vsutils.c | 75 +++++++++++++------------------------------- 1 file changed, 21 insertions(+), 54 deletions(-) diff --git a/src/volser/vsutils.c b/src/volser/vsutils.c index f103a27ed..cd78bba4d 100644 --- a/src/volser/vsutils.c +++ b/src/volser/vsutils.c @@ -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 */ } -- 2.39.5