vos: Cleanup function definitions
[openafs.git] / src / volser / vos.c
index ac0ca41..e216445 100644 (file)
@@ -58,9 +58,9 @@
 #endif
 
 /* Local Prototypes */
-int PrintDiagnostics(char *astring, afs_int32 acode);
-int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
-                  afs_int32 *voltype, struct nvldbentry *rentry);
+static int PrintDiagnostics(char *astring, afs_int32 acode);
+static int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part,
+                 afs_int32 *voltype, struct nvldbentry *rentry);
 
 struct tqElem {
     afs_uint32 volid;
@@ -120,7 +120,6 @@ qInit(struct tqHead *ahead)
     return;
 }
 
-
 static void
 qPut(struct tqHead *ahead, afs_uint32 volid)
 {
@@ -175,7 +174,6 @@ VolNameOK(char *name)
 {
     size_t total;
 
-
     total = strlen(name);
     if (!strcmp(&name[total - 9], ".readonly")) {
        return 0;
@@ -208,11 +206,10 @@ IsNumeric(char *name)
     return result;
 }
 
-
 /*
  * Parse a server dotted address and return the address in network byte order
  */
-afs_uint32
+static afs_uint32
 GetServerNoresolve(char *aname)
 {
     int b1, b2, b3, b4;
@@ -230,7 +227,7 @@ GetServerNoresolve(char *aname)
 /*
  * Parse a server name/address and return a non-loopback address in network byte order
  */
-afs_uint32
+static afs_uint32
 GetServer(char *aname)
 {
     struct hostent *th;
@@ -286,21 +283,7 @@ GetServer(char *aname)
     return 0;
 }
 
-afs_int32
-GetVolumeType(char *aname)
-{
-
-    if (!strcmp(aname, "ro"))
-       return (ROVOL);
-    else if (!strcmp(aname, "rw"))
-       return (RWVOL);
-    else if (!strcmp(aname, "bk"))
-       return (BACKVOL);
-    else
-       return (-1);
-}
-
-int
+static int
 IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
 {
     struct partList dummyPartList;
@@ -320,11 +303,9 @@ IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
     return success;
 }
 
-
-
  /*sends the contents of file associated with <fd> and <blksize>  to Rx Stream
   * associated  with <call> */
-int
+static int
 SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
 {
     char *buffer = (char *)0;
@@ -351,7 +332,7 @@ SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
        error = USD_READ(ufd, buffer, blksize, &nbytes);
        if (error) {
            fprintf(STDERR, "File system read failed: %s\n",
-                   afs_error_message(error));
+                   afs_error_message(error));
            break;
        }
 
@@ -370,7 +351,7 @@ SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
 
 /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
  * writes it out to the volume. */
-afs_int32
+static afs_int32
 WriteData(struct rx_call *call, void *rock)
 {
     char *filename = (char *) rock;
@@ -396,7 +377,7 @@ WriteData(struct rx_call *call, void *rock)
        }
        if (code) {
            fprintf(STDERR, "Could not access file '%s': %s\n", filename,
-                   afs_error_message(code));
+                   afs_error_message(code));
            error = VOLSERBADOP;
            goto wfail;
        }
@@ -432,7 +413,7 @@ WriteData(struct rx_call *call, void *rock)
 /* Receive data from <call> stream into file associated
  * with <fd> <blksize>
  */
-int
+static int
 ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
 {
     char *buffer = NULL;
@@ -462,7 +443,7 @@ ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
                USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
            if (error) {
                fprintf(STDERR, "File system write failed: %s\n",
-                       afs_error_message(error));
+                       afs_error_message(error));
                ERROR_EXIT(-1);
            }
        }
@@ -474,7 +455,7 @@ ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
     return (error);
 }
 
-afs_int32
+static afs_int32
 DumpFunction(struct rx_call *call, void *rock)
 {
     char *filename = (char *)rock;
@@ -502,7 +483,7 @@ DumpFunction(struct rx_call *call, void *rock)
        }
        if (code) {
            fprintf(STDERR, "Could not create file '%s': %s\n", filename,
-                   afs_error_message(code));
+                   afs_error_message(code));
            ERROR_EXIT(VOLSERBADOP);
        }
     }
@@ -924,10 +905,10 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
             * Volume's status is OK - all the fields are valid.
             */
 
-                static long server_cache = -1, partition_cache = -1;
-                static char hostname[256], address[32], pname[16];
-                int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
-                              VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
+               static long server_cache = -1, partition_cache = -1;
+               static char hostname[256], address[32], pname[16];
+               int i,ai[] = {VOLINT_STATS_TIME_IDX_0,VOLINT_STATS_TIME_IDX_1,VOLINT_STATS_TIME_IDX_2,
+                             VOLINT_STATS_TIME_IDX_3,VOLINT_STATS_TIME_IDX_4,VOLINT_STATS_TIME_IDX_5};
 
                if (a_servID != server_cache) {
                        struct in_addr s;
@@ -946,7 +927,7 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
                fprintf(STDOUT, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid));
                fprintf(STDOUT, "serv\t\t%s\t%s\n", address, hostname);
                fprintf(STDOUT, "part\t\t%s\n", pname);
-                fprintf(STDOUT, "status\t\tOK\n");
+               fprintf(STDOUT, "status\t\tOK\n");
                fprintf(STDOUT, "backupID\t%lu\n",
                        afs_printable_uint32_lu(a_xInfoP->backupID));
                fprintf(STDOUT, "parentID\t%lu\n",
@@ -999,8 +980,6 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
                fprintf(STDOUT, "filecount\t%u\n", a_xInfoP->filecount);
                fprintf(STDOUT, "dayUse\t\t%u\n", a_xInfoP->dayUse);
 
-
-
                fprintf(STDOUT,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]);
                fprintf(STDOUT,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]);
                fprintf(STDOUT,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]);
@@ -1052,7 +1031,7 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID,
 
            fprintf(STDOUT, "inUse\t%d\n",a_xInfoP->inUse);
            if (a_xInfoP->inUse == 1)
-               (*a_totalOKP)++;
+               (*a_totalOKP)++;
            else
                (*a_totalNotOKP)++;
 
@@ -1095,7 +1074,7 @@ DisplayFormat2(long server, long partition, volintInfo *pntr)
     }
 
     if (pntr->status == VOK)
-        fprintf(STDOUT, "name\t\t%s\n", pntr->name);
+       fprintf(STDOUT, "name\t\t%s\n", pntr->name);
 
     fprintf(STDOUT, "id\t\t%lu\n",
            afs_printable_uint32_lu(pntr->volid));
@@ -1403,25 +1382,32 @@ XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
 
 }                              /*XDisplayVolumes2 */
 
-
-/* set <server> and <part> to the correct values depending on
- * <voltype> and <entry> */
-static void
+/**
+ * Retrieve the sites (i.e., server id, partition id) from a vldb entry for a
+ * given volume type.  May be called repeatedly to get each read-only site.
+ *
+ * @param[in] entry       vldb entry from a previous vldb query
+ * @param[in] voltype     type of volume of interest (rw, ro, bk)
+ * @param[out] server     vldb entry server number for voltype
+ * @param[out] part       vldb part id for voltype
+ * @param[inout] previdx  cursor; should be initialized to -1
+ *                        before first call on a given entry.
+ *
+ * @returns true when a volume site has been found
+ */
+static int
 GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
                 afs_int32 *part, int *previdx)
 {
     int i, istart, vtype;
 
-    *server = -1;
-    *part = -1;
-
-    /* Doesn't check for non-existance of backup volume */
+    /* Doesn't check for non-existence of backup volume */
     if ((voltype == RWVOL) || (voltype == BACKVOL)) {
        vtype = VLSF_RWVOL;
-       istart = 0;             /* seach the entire entry */
+       istart = 0;             /* search the entire entry */
     } else {
        vtype = VLSF_ROVOL;
-       /* Seach from beginning of entry or pick up where we left off */
+       /* Search from beginning of entry or pick up where we left off */
        istart = ((*previdx < 0) ? 0 : *previdx + 1);
     }
 
@@ -1430,13 +1416,13 @@ GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server,
            *server = entry->serverNumber[i];
            *part = entry->serverPartition[i];
            *previdx = i;
-           return;
+           return 1;
        }
     }
 
-    /* Didn't find any, return -1 */
+    /* Didn't find any more, reset index. */
     *previdx = -1;
-    return;
+    return 0;
 }
 
 static void
@@ -1575,7 +1561,6 @@ NukeVolume(struct cmd_syndesc *as)
     return code;
 }
 
-
 /*------------------------------------------------------------------------
  * PRIVATE ExamineVolume
  *
@@ -1652,17 +1637,14 @@ ExamineVolume(struct cmd_syndesc *as, void *arock)
         * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
         * If its a RO vol, get the next RO entry.
         */
-       GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
-                        &aserver, &apart, &previdx);
-       if (previdx == -1) {    /* searched all entries */
-           if (!foundentry) {
-               fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
-                       as->parms[0].items->data);
-               error = ENOENT;
-           }
+       foundentry = GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL),
+                                     &aserver, &apart, &previdx);
+       if (!foundentry) {      /* searched all entries */
+           fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
+                   as->parms[0].items->data);
+           error = ENOENT;
            break;
        }
-       foundentry = 1;
 
        /* Get information about the volume from the server */
        if (verbose) {
@@ -1761,6 +1743,7 @@ SetFields(struct cmd_syndesc *as, void *arock)
     afs_int32 apart;
     int previdx = -1;
     int have_field = 0;
+    int found;
 
     volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);  /* -id */
     if (volid == 0) {
@@ -1781,8 +1764,8 @@ SetFields(struct cmd_syndesc *as, void *arock)
     }
     MapHostToNetwork(&entry);
 
-    GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
-    if (previdx == -1) {
+    found = GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
+    if (!found) {
        fprintf(STDERR, "Volume %s does not exist in VLDB\n\n",
                as->parms[0].items->data);
        return (ENOENT);
@@ -2081,6 +2064,11 @@ DeleteVolume(struct cmd_syndesc *as, void *arock)
     char pname[10];
     afs_int32 idx, j;
 
+    if (as->parms[1].items && !as->parms[0].items) {
+       fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+       return EINVAL;
+    }
+
     if (as->parms[0].items) {
        server = GetServer(as->parms[0].items->data);
        if (!server) {
@@ -2179,7 +2167,6 @@ DeleteVolume(struct cmd_syndesc *as, void *arock)
        partition = entry.serverPartition[idx];
     }
 
-
     code = UV_DeleteVolume(server, partition, volid);
     if (code) {
        PrintDiagnostics("remove", code);
@@ -2469,7 +2456,6 @@ CopyVolume(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-
 static int
 ShadowVolume(struct cmd_syndesc *as, void *arock)
 {
@@ -2666,7 +2652,6 @@ ShadowVolume(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-
 static int
 CloneVolume(struct cmd_syndesc *as, void *arock)
 {
@@ -2713,7 +2698,7 @@ CloneVolume(struct cmd_syndesc *as, void *arock)
                    "vos : partition %s does not exist on the server\n",
                    as->parms[2].items->data);
            return ENOENT;
-        }
+       }
     } else {
        code = GetVolumeInfo(volid, &server, &part, &voltype, &entry);
        if (code)
@@ -2759,7 +2744,6 @@ CloneVolume(struct cmd_syndesc *as, void *arock)
     if (as->parms[6].items) flags |= RV_RDONLY;
     if (as->parms[7].items) flags |= RV_RWONLY;
 
-
     code =
        UV_CloneVolume(server, part, volid, cloneid, volname, flags);
 
@@ -2774,7 +2758,6 @@ CloneVolume(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-
 static int
 BackupVolume(struct cmd_syndesc *as, void *arock)
 {
@@ -2864,7 +2847,7 @@ ReleaseVolume(struct cmd_syndesc *as, void *arock)
        return EINVAL;
     }
     if (as->parms[3].items) /* -force-reclone */
-        flags |= REL_COMPLETE;
+       flags |= REL_COMPLETE;
 
     avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
     if (avolid == 0) {
@@ -3160,7 +3143,7 @@ RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
                   && entry.volumeId[voltype] != avolid) {
            avolid = entry.volumeId[voltype];
        }
-        aparentid = entry.volumeId[RWVOL];
+       aparentid = entry.volumeId[RWVOL];
     }
 
     else {                     /* volume exists - do we do a full incremental or abort */
@@ -3175,7 +3158,7 @@ RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
                   && entry.volumeId[voltype] != avolid) {
            avolid = entry.volumeId[voltype];
        }
-        aparentid = entry.volumeId[RWVOL];
+       aparentid = entry.volumeId[RWVOL];
 
        /* A file name was specified  - check if volume is on another partition */
        vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
@@ -3280,20 +3263,15 @@ RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
        restoreflags |= RV_NODEL;
     }
 
-
     code =
        UV_RestoreVolume2(aserver, apart, avolid, aparentid,
-                          avolname, restoreflags, WriteData, afilename);
+                         avolname, restoreflags, WriteData, afilename);
     if (code) {
        PrintDiagnostics("restore", code);
        exit(1);
     }
     MapPartIdIntoName(apart, apartName);
 
-    /*
-     * patch typo here - originally "parms[1]", should be "parms[0]"
-     */
-
     fprintf(STDOUT, "Restored volume %s on %s %s\n", avolname,
            as->parms[0].items->data, apartName);
     return 0;
@@ -3419,17 +3397,11 @@ RemoveSite(struct cmd_syndesc *as, void *arock)
                as->parms[1].items->data);
        exit(1);
     }
-/*
- *skip the partition validity check, since it is possible that the partition
- *has since been decomissioned.
- */
-/*
-       if (!IsPartValid(apart,aserver,&code)){
-           if(code) PrintError("",code);
-           else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data);
-           exit(1);
-       }
-*/
+    /*
+     * The partition validity check is skipped, since it is possible that the
+     * partition has already been decomissioned.
+     */
+
     code = UV_RemoveSite(aserver, apart, avolid);
     if (code) {
        PrintDiagnostics("remsite", code);
@@ -3507,7 +3479,6 @@ ListPartitions(struct cmd_syndesc *as, void *arock)
        exit(1);
     }
 
-
     code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
     if (code) {
        PrintDiagnostics("listpart", code);
@@ -3812,6 +3783,12 @@ SyncVldb(struct cmd_syndesc *as, void *arock)
     afs_uint32 tserver;
 
     tserver = 0;
+
+    if (as->parms[1].items && !as->parms[0].items) {
+       fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+       exit(1);
+    }
+
     if (as->parms[0].items) {
        tserver = GetServer(as->parms[0].items->data);
        if (!tserver) {
@@ -3838,12 +3815,6 @@ SyncVldb(struct cmd_syndesc *as, void *arock)
            exit(1);
        }
        flags = 1;
-
-       if (!tserver) {
-           fprintf(STDERR,
-                   "The -partition option requires a -server option\n");
-           exit(1);
-       }
     }
 
     if (as->parms[3].items) {
@@ -3918,7 +3889,7 @@ SyncServer(struct cmd_syndesc *as, void *arock)
        }
        flags = 1;
     } else {
-        pnum = -1;
+       pnum = -1;
     }
 
     if (as->parms[2].items) {
@@ -4095,33 +4066,32 @@ VolserStatus(struct cmd_syndesc *as, void *arock)
        }
        if (pntr->iflags) {
            fprintf(STDOUT, "attachFlags:  ");
-           switch (pntr->iflags) {
-           case ITOffline:
+           if ((pntr->iflags & ITOffline) != 0) {
                fprintf(STDOUT, "offline ");
-               break;
-           case ITBusy:
+           }
+           if ((pntr->iflags & ITBusy) != 0) {
                fprintf(STDOUT, "busy ");
-               break;
-           case ITReadOnly:
+           }
+           if ((pntr->iflags & ITReadOnly) != 0) {
                fprintf(STDOUT, "readonly ");
-               break;
-           case ITCreate:
+           }
+           if ((pntr->iflags & ITCreate) != 0) {
                fprintf(STDOUT, "create ");
-               break;
-           case ITCreateVolID:
+           }
+           if ((pntr->iflags & ITCreateVolID) != 0) {
                fprintf(STDOUT, "create volid ");
-               break;
            }
            fprintf(STDOUT, "\n");
        }
        if (pntr->vflags) {
            fprintf(STDOUT, "volumeStatus: ");
-           switch (pntr->vflags) {
-           case VTDeleteOnSalvage:
+           if ((pntr->vflags & VTDeleteOnSalvage) != 0) {
                fprintf(STDOUT, "deleteOnSalvage ");
-           case VTOutOfService:
+           }
+           if ((pntr->vflags & VTOutOfService) != 0) {
                fprintf(STDOUT, "outOfService ");
-           case VTDeleted:
+           }
+           if ((pntr->vflags & VTDeleted) != 0) {
                fprintf(STDOUT, "deleted ");
            }
            fprintf(STDOUT, "\n");
@@ -4153,25 +4123,39 @@ VolserStatus(struct cmd_syndesc *as, void *arock)
 static int
 RenameVolume(struct cmd_syndesc *as, void *arock)
 {
-    afs_int32 code1, code2, code;
+    afs_int32 code;
     struct nvldbentry entry;
+    struct nvldbentry entry2;
 
-    code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
-    if (code1) {
+    /* Get the entry of the volume to be renamed (-oldname), by name or id. */
+    code = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
+    if (code) {
        fprintf(STDERR, "vos: Could not find entry for volume %s\n",
                as->parms[0].items->data);
+       PrintError("", code);
        exit(1);
     }
-    code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
-    if ((!code1) && (!code2)) {        /*the newname already exists */
-       fprintf(STDERR, "vos: volume %s already exists\n",
+
+    /*
+     * Verify the new name is available before attempting to rename.
+     * Allow renaming of the same volume in order to complete a
+     * previously interrupted rename.
+     */
+    code = VLDB_GetEntryByName(as->parms[1].items->data, &entry2);
+    if (code != 0 && code != VL_NOENT) {
+       fprintf(STDERR, "vos: Could not check entry for volume %s\n",
                as->parms[1].items->data);
+       PrintError("", code);
        exit(1);
     }
-
-    if (code1 && code2) {
-       fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
-               as->parms[0].items->data, as->parms[1].items->data);
+    if (code == 0 && entry.volumeId[RWVOL] != entry2.volumeId[RWVOL]) {
+       fprintf(STDERR, "vos: Cannot rename volume %s (%lu) to %s;"
+                       " volume %s (%lu) already exists\n",
+                       as->parms[0].items->data,
+                       (unsigned long)entry.volumeId[RWVOL],
+                       as->parms[1].items->data,
+                       as->parms[1].items->data,
+                       (unsigned long)entry2.volumeId[RWVOL]);
        exit(1);
     }
     if (!VolNameOK(as->parms[0].items->data)) {
@@ -4210,9 +4194,9 @@ RenameVolume(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-int
+static int
 GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype,
-              struct nvldbentry *rentry)
+             struct nvldbentry *rentry)
 {
     afs_int32 vcode;
     int i, index = -1;
@@ -4265,8 +4249,8 @@ GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *
        return 0;
     }
     fprintf(STDERR,
-            "unexpected volume type for volume %lu\n",
-            (unsigned long)volid);
+           "unexpected volume type for volume %lu\n",
+           (unsigned long)volid);
     return -1;
 }
 
@@ -4447,7 +4431,6 @@ DeleteEntry(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-
 static int
 CompareVldbEntryByName(const void *p1, const void *p2)
 {
@@ -4458,41 +4441,6 @@ CompareVldbEntryByName(const void *p1, const void *p2)
     return (strcmp(arg1->name, arg2->name));
 }
 
-/*
-static int CompareVldbEntry(char *p1, char *p2)
-{
-    struct nvldbentry *arg1,*arg2;
-    int i;
-    int pos1, pos2;
-    char comp1[100],comp2[100];
-    char temp1[20],temp2[20];
-
-    arg1 = (struct nvldbentry *)p1;
-    arg2 = (struct nvldbentry *)p2;
-    pos1 = -1;
-    pos2 = -1;
-
-    for(i = 0; i < arg1->nServers; i++)
-       if(arg1->serverFlags[i] & VLSF_RWVOL) pos1 = i;
-    for(i = 0; i < arg2->nServers; i++)
-       if(arg2->serverFlags[i] & VLSF_RWVOL) pos2 = i;
-    if(pos1 == -1 || pos2 == -1){
-       pos1 = 0;
-       pos2 = 0;
-    }
-    sprintf(comp1,"%10u",arg1->serverNumber[pos1]);
-    sprintf(comp2,"%10u",arg2->serverNumber[pos2]);
-    sprintf(temp1,"%10u",arg1->serverPartition[pos1]);
-    sprintf(temp2,"%10u",arg2->serverPartition[pos2]);
-    strcat(comp1,temp1);
-    strcat(comp2,temp2);
-    strcat(comp1,arg1->name);
-    strcat(comp1,arg2->name);
-    return(strcmp(comp1,comp2));
-
-}
-
-*/
 static int
 ListVLDB(struct cmd_syndesc *as, void *arock)
 {
@@ -4614,14 +4562,14 @@ ListVLDB(struct cmd_syndesc *as, void *arock)
        else if (centries > 0) {
            if (!tarray) {
                /* malloc the first bulk entries array */
-                tarraysize = centries * sizeof(struct nvldbentry);
-                tarray = malloc(tarraysize);
+               tarraysize = centries * sizeof(struct nvldbentry);
+               tarray = malloc(tarraysize);
                if (!tarray) {
                    fprintf(STDERR,
                            "Could not allocate enough space for the VLDB entries\n");
                    goto bypass;
                }
-                memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
+               memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize);
            } else {
                /* Grow the tarray to keep the extra entries */
                parraysize = (centries * sizeof(struct nvldbentry));
@@ -4641,7 +4589,7 @@ ListVLDB(struct cmd_syndesc *as, void *arock)
        }
 
        /* Free the bulk array */
-        xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
+       xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries);
     }
 
     /* Here is where we now sort all the entries and print them */
@@ -4689,6 +4637,7 @@ BackSys(struct cmd_syndesc *as, void *arock)
 #ifndef HAVE_POSIX_REGEX
     char *ccode;
 #endif
+    int found;
 
     memset(&attributes, 0, sizeof(struct VldbListByAttributes));
     attributes.Mask = 0;
@@ -4946,8 +4895,8 @@ BackSys(struct cmd_syndesc *as, void *arock)
 
        avolid = vllist->volumeId[RWVOL];
        MapHostToNetwork(vllist);
-       GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
-       if (aserver1 == -1 || apart1 == -1) {
+       found = GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
+       if (!found) {
            fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n",
                    vllist->name);
            totalFail++;
@@ -5034,14 +4983,17 @@ UnlockVLDB(struct cmd_syndesc *as, void *arock)
                    as->parms[1].items->data);
            exit(1);
        }
-       if (!IsPartValid(apart, aserver, &code)) {      /*check for validity of the partition */
-           if (code)
-               PrintError("", code);
-           else
-               fprintf(STDERR,
-                       "vos : partition %s does not exist on the server\n",
-                       as->parms[1].items->data);
-           exit(1);
+       if (aserver) {
+           /* Check for validity of the partition if a server was given. */
+           if (!IsPartValid(apart, aserver, &code)) {
+               if (code)
+                   PrintError("", code);
+               else
+                   fprintf(STDERR,
+                           "vos : partition %s does not exist on the server\n",
+                           as->parms[1].items->data);
+               exit(1);
+           }
        }
        attributes.partition = apart;
        attributes.Mask |= VLLIST_PARTITION;
@@ -5108,19 +5060,19 @@ PrintInt64Size(afs_uint64 in)
     SplitInt64(in,hi,lo);
 
     if (hi == 0) {
-        units = "KB";
+       units = "KB";
     } else if (!(hi & 0xFFFFFC00)) {
-        units = "MB";
-        lo = (hi << 22) | (lo >> 10);
+       units = "MB";
+       lo = (hi << 22) | (lo >> 10);
     } else if (!(hi & 0xFFF00000)) {
-        units = "GB";
-        lo = (hi << 12) | (lo >> 20);
+       units = "GB";
+       lo = (hi << 12) | (lo >> 20);
     } else if (!(hi & 0xC0000000)) {
-        units = "TB";
-        lo = (hi << 2) | (lo >> 30);
+       units = "TB";
+       lo = (hi << 2) | (lo >> 30);
     } else {
-        units = "PB";
-        lo = (hi >> 8);
+       units = "PB";
+       lo = (hi >> 8);
     }
     sprintf(output,"%u %s", lo, units);
     return output;
@@ -5160,7 +5112,7 @@ PartitionInfo(struct cmd_syndesc *as, void *arock)
        cnt = 1;
     }
     if (as->parms[2].items) {
-        printSummary = 1;
+       printSummary = 1;
     }
     if (apart != -1) {
        if (!IsPartValid(apart, aserver, &code)) {      /*check for validity of the partition */
@@ -5193,18 +5145,18 @@ PartitionInfo(struct cmd_syndesc *as, void *arock)
                    "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
                    pname, partition.free, partition.minFree);
            sumPartitions++;
-            AddUInt64(sumFree,partition.free,&sumFree);
-            AddUInt64(sumStorage,partition.minFree,&sumStorage);
+           AddUInt64(sumFree,partition.free,&sumFree);
+           AddUInt64(sumStorage,partition.minFree,&sumStorage);
        }
     }
     if (printSummary) {
-        fprintf(STDOUT,
+       fprintf(STDOUT,
                "Summary: %s free out of ",
                PrintInt64Size(sumFree));
-        fprintf(STDOUT,
-                "%s on %d partitions\n",
-                PrintInt64Size(sumStorage),
-                sumPartitions);
+       fprintf(STDOUT,
+               "%s on %d partitions\n",
+               PrintInt64Size(sumStorage),
+               sumPartitions);
     }
     return 0;
 }
@@ -5261,12 +5213,11 @@ ChangeAddr(struct cmd_syndesc *as, void *arock)
        afs_int32 m_uniq = 0;
        afsUUID m_uuid;
        ListAddrByAttributes m_attrs;
-       char buffer[128];
+       struct uuid_fmtbuf buffer;
 
        memset(&m_attrs, 0, sizeof(m_attrs));
        memset(&m_uuid, 0, sizeof(m_uuid));
        memset(&m_addrs, 0, sizeof(m_addrs));
-       memset(buffer, 0, sizeof(buffer));
 
        m_attrs.Mask = VLADDR_IPADDR;
        m_attrs.ipaddr = ntohl(ip1);    /* -oldaddr */
@@ -5277,9 +5228,10 @@ ChangeAddr(struct cmd_syndesc *as, void *arock)
        xdr_free((xdrproc_t) xdr_bulkaddrs, &m_addrs);
        switch (vcode) {
        case 0:         /* mh entry detected */
-           afsUUID_to_string(&m_uuid, buffer, sizeof(buffer) - 1);
+           afsUUID_to_string(&m_uuid, &buffer);
            fprintf(STDERR, "vos: Refusing to change address in multi-homed server entry.\n");
-           fprintf(STDERR, "     -oldaddr address is registered to file server UUID %s\n", buffer);
+           fprintf(STDERR, "     -oldaddr address is registered to file server UUID %s\n",
+                           buffer.buffer);
            fprintf(STDERR, "     Please restart the file server or use vos setaddrs.\n");
            return EINVAL;
        case VL_NOENT:
@@ -5328,11 +5280,11 @@ print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
 {
     int i;
     afs_uint32 addr;
-    char buf[1024];
+    struct uuid_fmtbuf buf;
 
     if (print) {
-       afsUUID_to_string(m_uuid, buf, sizeof(buf));
-       printf("UUID: %s\n", buf);
+       afsUUID_to_string(m_uuid, &buf);
+       printf("UUID: %s\n", buf.buffer);
     }
 
     /* print out the list of all the server */
@@ -5365,15 +5317,15 @@ ListAddrs(struct cmd_syndesc *as, void *arock)
     afs_int32 m_nentries;
 
     if (as->parms[0].items && as->parms[1].items) {
-        fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
-        exit(-1);
+       fprintf(STDERR, "vos: Can't use the -uuid and -host flags together\n");
+       exit(-1);
     }
 
     memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes));
     memset(&askuuid, 0, sizeof(afsUUID));
     if (as->parms[0].items) {
        /* -uuid */
-        if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
+       if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
            fprintf(STDERR, "vos: invalid UUID '%s'\n",
                    as->parms[0].items->data);
            exit(-1);
@@ -5394,8 +5346,8 @@ ListAddrs(struct cmd_syndesc *as, void *arock)
        m_attrs.Mask = VLADDR_IPADDR;
        m_attrs.ipaddr = ntohl(saddr);
     } else {
-        /* by index */
-        m_attrs.Mask = VLADDR_INDEX;
+       /* by index */
+       m_attrs.Mask = VLADDR_INDEX;
     }
 
     if (as->parms[2].items) {
@@ -5415,43 +5367,43 @@ ListAddrs(struct cmd_syndesc *as, void *arock)
     }
 
     for (i = 1, m_nentries = 0; nentries; i++) {
-        m_attrs.index = i;
-
-        xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
-        vcode =
-            ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
-                              &m_uniq, &m_nentries, &m_addrs);
-        switch (vcode) {
-        case 0: /* success */
-            print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
-            nentries--;
-            break;
-
-        case VL_NOENT:
-            if (m_attrs.Mask == VLADDR_UUID) {
-                fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
-                        as->parms[0].items->data);
-                exit(-1);
-            } else if (m_attrs.Mask == VLADDR_IPADDR) {
-                fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
-                        as->parms[1].items->data, m_attrs.ipaddr);
-                exit(-1);
-            }
-            continue;
-
-        case VL_INDEXERANGE:
-            vcode = 0; /* not an error, just means we're done */
-            goto out;
-
-        default: /* any other error */
-            fprintf(STDERR, "vos: could not list the server addresses\n");
-            PrintError("", vcode);
-            goto out;
-        }
-
-        /* if -uuid or -host, only list one response */
-        if (as->parms[1].items || as->parms[0].items)
-            break;
+       m_attrs.index = i;
+
+       xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */
+       vcode =
+           ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
+                             &m_uniq, &m_nentries, &m_addrs);
+       switch (vcode) {
+       case 0: /* success */
+           print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
+           nentries--;
+           break;
+
+       case VL_NOENT:
+           if (m_attrs.Mask == VLADDR_UUID) {
+               fprintf(STDERR, "vos: no entry for UUID '%s' found in VLDB\n",
+                       as->parms[0].items->data);
+               exit(-1);
+           } else if (m_attrs.Mask == VLADDR_IPADDR) {
+               fprintf(STDERR, "vos: no entry for host '%s' [0x%08x] found in VLDB\n",
+                       as->parms[1].items->data, m_attrs.ipaddr);
+               exit(-1);
+           }
+           continue;
+
+       case VL_INDEXERANGE:
+           vcode = 0; /* not an error, just means we're done */
+           goto out;
+
+       default: /* any other error */
+           fprintf(STDERR, "vos: could not list the server addresses\n");
+           PrintError("", vcode);
+           goto out;
+       }
+
+       /* if -uuid or -host, only list one response */
+       if (as->parms[1].items || as->parms[0].items)
+           break;
     }
 
 out:
@@ -5459,7 +5411,6 @@ out:
     return vcode;
 }
 
-
 static int
 SetAddrs(struct cmd_syndesc *as, void *arock)
 {
@@ -5472,7 +5423,7 @@ SetAddrs(struct cmd_syndesc *as, void *arock)
     memset(&askuuid, 0, sizeof(afsUUID));
     if (as->parms[0].items) {
        /* -uuid */
-        if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
+       if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
            fprintf(STDERR, "vos: invalid UUID '%s'\n",
                    as->parms[0].items->data);
            exit(-1);
@@ -5585,7 +5536,6 @@ RemoveAddrs(struct cmd_syndesc *as, void *arock)
     return code;
 }
 
-
 static int
 LockEntry(struct cmd_syndesc *as, void *arock)
 {
@@ -5846,7 +5796,7 @@ EndTrans(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-int
+static int
 PrintDiagnostics(char *astring, afs_int32 acode)
 {
     switch (acode) {
@@ -5867,7 +5817,6 @@ PrintDiagnostics(char *astring, afs_int32 acode)
     return 0;
 }
 
-
 #ifdef AFS_NT40_ENV
 static DWORD
 win32_enableCrypt(void)
@@ -5879,11 +5828,11 @@ win32_enableCrypt(void)
 
     /* Look up configuration parameters in Registry */
     code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                        0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
+                       0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
     if (code != ERROR_SUCCESS) {
-        dummyLen = sizeof(cryptall);
-        RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
-                        (BYTE *) &cryptall, &dummyLen);
+       dummyLen = sizeof(cryptall);
+       RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
+                       (BYTE *) &cryptall, &dummyLen);
     }
     RegCloseKey (parmKey);
 
@@ -5918,9 +5867,9 @@ MyBeforeProc(struct cmd_syndesc *as, void *arock)
 
     if (as->parms[COMMONPARM_OFFSET_ENCRYPT].items     /* -encrypt specified */
 #ifdef AFS_NT40_ENV
-        || win32_enableCrypt()
+       || win32_enableCrypt()
 #endif /* AFS_NT40_ENV */
-         )
+        )
        secFlags |= AFSCONF_SECOPTS_ALWAYSENCRYPT;
 
     if (as->parms[COMMONPARM_OFFSET_CONFIG].items)   /* -config flag set */
@@ -5962,14 +5911,6 @@ MyBeforeProc(struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-int
-osi_audit(void)
-{
-/* this sucks but it works for now.
-*/
-    return 0;
-}
-
 #include "AFS_component_version_number.c"
 
 int