DEVEL15-windows-64bit-printf-sanity-20090218
[openafs.git] / src / volser / vos.c
index cc63064..765b777 100644 (file)
@@ -58,11 +58,18 @@ RCSID
 #include <signal.h>
 #endif
 #include "volser_prototypes.h"
+#include "vsutils_prototypes.h"
+#include "lockprocs_prototypes.h"
 
 #ifdef HAVE_POSIX_REGEX
 #include <regex.h>
 #endif
 
+/* Local Prototypes */
+int PrintDiagnostics(char *astring, afs_int32 acode);
+int GetVolumeInfo(afs_int32 volid, afs_int32 *server, afs_int32 *part, 
+                  afs_int32 *voltype, struct nvldbentry *rentry);
+
 struct tqElem {
     afs_int32 volid;
     struct tqElem *next;
@@ -79,10 +86,10 @@ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate");\
 cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
 cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
+cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses"); \
 
 #define ERROR_EXIT(code) {error=(code); goto error_exit;}
 
-extern int verbose;
 int rxInitDone = 0;
 struct rx_connection *tconn;
 afs_int32 tserver;
@@ -280,8 +287,12 @@ SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
        FD_ZERO(&in);
        FD_SET((int)(ufd->handle), &in);
        /* don't timeout if read blocks */
+#if defined(AFS_PTHREAD_ENV)
+       select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
+#else
        IOMGR_Select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
 #endif
+#endif
        error = USD_READ(ufd, buffer, blksize, &nbytes);
        if (error) {
            fprintf(STDERR, "File system read failed\n");
@@ -338,7 +349,7 @@ WriteData(struct rx_call *call, char *rock)
        USD_SEEK(ufd, filesize, SEEK_END, &currOffset);
        hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32));
        USD_SEEK(ufd, filesize, SEEK_SET, &currOffset);
-       USD_READ(ufd, &buffer, sizeof(afs_uint32), &got);
+       USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got);
        if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) {
            fprintf(STDERR, "Signature missing from end of file '%s'\n", filename);
            error = VOLSERBADOP;
@@ -390,8 +401,12 @@ ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
            FD_ZERO(&out);
            FD_SET((int)(ufd->handle), &out);
            /* don't timeout if write blocks */
+#if defined(AFS_PTHREAD_ENV)
+           select(((int)(ufd->handle)) + 1, &out, 0, 0, 0);
+#else
            IOMGR_Select(((int)(ufd->handle)) + 1, 0, &out, 0, 0);
 #endif
+#endif
            error =
                USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
            if (error) {
@@ -457,16 +472,12 @@ DumpFunction(struct rx_call *call, char *filename)
     return (error);
 }
 
-#if SIZEOF_TIME_T!=4
 static char *
 vos_ctime(afs_int32 *timep)
 {
     time_t foo = *timep;
     return ctime(&foo);
 }
-#else
-#define vos_ctime ctime
-#endif
 
 static void
 DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
@@ -496,7 +507,7 @@ DisplayFormat(pntr, server, part, totalOK, totalNotOK, totalBusy, fast,
                *totalOK += 1;
            } else {
                fprintf(STDOUT, "Off-line");
-               *totalNotOK++;
+               *totalNotOK += 1;
            }
            if (pntr->needsSalvaged == 1)
                fprintf(STDOUT, "**needs salvage**");
@@ -1122,7 +1133,7 @@ DisplayVolumes(server, part, pntr, count, longlist, fast, quiet)
      int quiet;
 {
     int totalOK, totalNotOK, totalBusy, i;
-    afs_int32 volid;
+    afs_int32 volid = 0;
 
     totalOK = 0;
     totalNotOK = 0;
@@ -1199,7 +1210,7 @@ XDisplayVolumes(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
     int totalNotOK;            /*Total screwed volumes */
     int totalBusy;             /*Total busy volumes */
     int i;                     /*Loop variable */
-    afs_int32 volid;           /*Current volume ID */
+    afs_int32 volid = 0;       /*Current volume ID */
 
     /*
      * Initialize counters and (global!!) queues.
@@ -1290,7 +1301,7 @@ XDisplayVolumes2(a_servID, a_partID, a_xInfoP, a_count, a_int32, a_fast,
     int totalNotOK;            /*Total screwed volumes */
     int totalBusy;             /*Total busy volumes */
     int i;                     /*Loop variable */
-    afs_int32 volid;           /*Current volume ID */
+    afs_int32 volid = 0;       /*Current volume ID */
 
     /*
      * Initialize counters and (global!!) queues.
@@ -1382,8 +1393,7 @@ GetServerAndPart(entry, voltype, server, part, previdx)
 }
 
 static void
-PostVolumeStats(entry)
-     struct nvldbentry *entry;
+PostVolumeStats(struct nvldbentry *entry)
 {
     SubEnumerateEntry(entry);
     /* Check for VLOP_ALLOPERS */
@@ -1441,11 +1451,8 @@ XVolumeStats(a_xInfoP, a_entryP, a_srvID, a_partID, a_volType)
 }                              /*XVolumeStats */
 
 static void
-VolumeStats(pntr, entry, server, part, voltype)
-     volintInfo *pntr;
-     struct nvldbentry *entry;
-     int voltype;
-     afs_int32 server, part;
+VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_int32 server, 
+            afs_int32 part, int voltype)
 {
     int totalOK, totalNotOK, totalBusy;
 
@@ -1627,7 +1634,7 @@ ExamineVolume(register struct cmd_syndesc *as, void *arock)
                EnumerateEntry(&entry);
            } else
 #endif /* FULL_LISTVOL_SWITCH */
-               VolumeStats(pntr, &entry, aserver, apart, voltype);
+               VolumeStats_int(pntr, &entry, aserver, apart, voltype);
 
            if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
                /* The VLDB says there is no backup volume yet we found one on disk */
@@ -2102,7 +2109,7 @@ MoveVolume(register struct cmd_syndesc *as, void *arock)
     afs_int32 flags, code, err;
     char fromPartName[10], toPartName[10];
 
-    struct diskPartition partition;    /* for space check */
+    struct diskPartition64 partition;  /* for space check */
     volintInfo *p;
 
     volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
@@ -2171,13 +2178,13 @@ MoveVolume(register struct cmd_syndesc *as, void *arock)
      * check target partition for space to move volume
      */
 
-    code = UV_PartitionInfo(toserver, toPartName, &partition);
+    code = UV_PartitionInfo64(toserver, toPartName, &partition);
     if (code) {
        fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
        exit(1);
     }
     if (TESTM)
-       fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
+       fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
                partition.free);
 
     p = (volintInfo *) 0;
@@ -2227,7 +2234,7 @@ CopyVolume(register struct cmd_syndesc *as, void *arock)
     afs_int32 volid, fromserver, toserver, frompart, topart, code, err, flags;
     char fromPartName[10], toPartName[10], *tovolume;
     struct nvldbentry entry;
-    struct diskPartition partition;    /* for space check */
+    struct diskPartition64 partition;  /* for space check */
     volintInfo *p;
 
     volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err);
@@ -2322,13 +2329,13 @@ CopyVolume(register struct cmd_syndesc *as, void *arock)
      * check target partition for space to move volume
      */
 
-    code = UV_PartitionInfo(toserver, toPartName, &partition);
+    code = UV_PartitionInfo64(toserver, toPartName, &partition);
     if (code) {
        fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
        exit(1);
     }
     if (TESTM)
-       fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
+       fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
                partition.free);
 
     p = (volintInfo *) 0;
@@ -2373,8 +2380,7 @@ ShadowVolume(register struct cmd_syndesc *as, void *arock)
     afs_int32 volid, fromserver, toserver, frompart, topart, tovolid;
     afs_int32 code, err, flags;
     char fromPartName[10], toPartName[10], toVolName[32], *tovolume;
-    struct nvldbentry entry;
-    struct diskPartition partition;    /* for space check */
+    struct diskPartition64 partition;  /* for space check */
     volintInfo *p, *q;
 
     p = (volintInfo *) 0;
@@ -2507,13 +2513,13 @@ ShadowVolume(register struct cmd_syndesc *as, void *arock)
      * check target partition for space to move volume
      */
 
-    code = UV_PartitionInfo(toserver, toPartName, &partition);
+    code = UV_PartitionInfo64(toserver, toPartName, &partition);
     if (code) {
        fprintf(STDERR, "vos: cannot access partition %s\n", toPartName);
        exit(1);
     }
     if (TESTM)
-       fprintf(STDOUT, "target partition %s free space %d\n", toPartName,
+       fprintf(STDOUT, "target partition %s free space %" AFS_INT64_FMT "\n", toPartName,
                partition.free);
 
     /* Don't do this again if we did it above */
@@ -2895,7 +2901,8 @@ RestoreVolume(register struct cmd_syndesc *as, void *arock)
     afs_int32 avolid, aparentid, aserver, apart, code, vcode, err;
     afs_int32 aoverwrite = ASK;
     afs_int32 acreation = 0, alastupdate = 0;
-    int restoreflags, readonly = 0, offline = 0, voltype = RWVOL;
+    int restoreflags = 0;
+    int readonly = 0, offline = 0, voltype = RWVOL;
     char prompt;
     char afilename[MAXPATHLEN], avolname[VOLSER_MAXVOLNAME + 1], apartName[10];
     char volname[VOLSER_MAXVOLNAME + 1];
@@ -3526,11 +3533,13 @@ ListVolumes(register struct cmd_syndesc *as, void *arock)
 {
     afs_int32 apart, int32list, fast;
     afs_int32 aserver, code;
-    volintInfo *pntr, *oldpntr;
+    volintInfo *pntr;
+    volintInfo *oldpntr = NULL;
     afs_int32 count;
     int i;
     char *base;
-    volintXInfo *xInfoP, *origxInfoP;  /*Ptr to current/orig extended vol info */
+    volintXInfo *xInfoP;
+    volintXInfo *origxInfoP = NULL; /*Ptr to current/orig extended vol info */
     int wantExtendedInfo;      /*Do we want extended vol info? */
 
     char pname[10];
@@ -4077,9 +4086,9 @@ RenameVolume(register struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-GetVolumeInfo(volid, server, part, voltype, rentry)
-     afs_int32 *server, volid, *part, *voltype;
-     register struct nvldbentry *rentry;
+int
+GetVolumeInfo(afs_int32 volid, afs_int32 *server, afs_int32 *part, afs_int32 *voltype, 
+              struct nvldbentry *rentry)
 {
     afs_int32 vcode;
     int i, index = -1;
@@ -4140,7 +4149,7 @@ GetVolumeInfo(volid, server, part, voltype, rentry)
 static int
 DeleteEntry(register struct cmd_syndesc *as, void *arock)
 {
-    afs_int32 apart;
+    afs_int32 apart = 0;
     afs_int32 avolid;
     afs_int32 vcode;
     struct VldbListByAttributes attributes;
@@ -4369,7 +4378,9 @@ ListVLDB(struct cmd_syndesc *as, void *arock)
     struct VldbListByAttributes attributes;
     nbulkentries arrayEntries;
     struct nvldbentry *vllist, *tarray = 0, *ttarray;
-    afs_int32 centries, nentries = 0, tarraysize, parraysize;
+    afs_int32 centries, nentries = 0;
+    afs_int32 tarraysize = 0;
+    afs_int32 parraysize;
     int j;
     char pname[10];
     int quiet, sort, lock;
@@ -4549,7 +4560,7 @@ BackSys(register struct cmd_syndesc *as, void *arock)
     int comp = 0;
     struct cmd_item *ti;
     char *ccode;
-    int match;
+    int match = 0;
 
     memset(&attributes, 0, sizeof(struct VldbListByAttributes));
     attributes.Mask = 0;
@@ -4863,7 +4874,8 @@ static int
 UnlockVLDB(register struct cmd_syndesc *as, void *arock)
 {
     afs_int32 apart;
-    afs_int32 aserver, code;
+    afs_int32 aserver = NULL;
+    afs_int32 code;
     afs_int32 vcode;
     struct VldbListByAttributes attributes;
     nbulkentries arrayEntries;
@@ -4994,11 +5006,11 @@ PartitionInfo(register struct cmd_syndesc *as, void *arock)
     afs_int32 apart;
     afs_int32 aserver, code;
     char pname[10];
-    struct diskPartition partition;
+    struct diskPartition64 partition;
     struct partList dummyPartList;
     int i, cnt;
     int printSummary=0, sumPartitions=0;
-    afs_uint64 sumFree, sumStorage, tmp;
+    afs_uint64 sumFree, sumStorage;
 
     ZeroInt64(sumFree);
     ZeroInt64(sumStorage);
@@ -5043,7 +5055,7 @@ PartitionInfo(register struct cmd_syndesc *as, void *arock)
     for (i = 0; i < cnt; i++) {
        if (dummyPartList.partFlags[i] & PARTVALID) {
            MapPartIdIntoName(dummyPartList.partId[i], pname);
-           code = UV_PartitionInfo(aserver, pname, &partition);
+           code = UV_PartitionInfo64(aserver, pname, &partition);
            if (code) {
                fprintf(STDERR, "Could not get information on partition %s\n",
                        pname);
@@ -5051,13 +5063,11 @@ PartitionInfo(register struct cmd_syndesc *as, void *arock)
                exit(1);
            }
            fprintf(STDOUT,
-                   "Free space on partition %s: %d K blocks out of total %d\n",
+                   "Free space on partition %s: %" AFS_INT64_FMT " K blocks out of total %" AFS_INT64_FMT "\n",
                    pname, partition.free, partition.minFree);
            sumPartitions++;
-            FillInt64(tmp,0,partition.free);
-            AddUInt64(sumFree,tmp,&sumFree);
-            FillInt64(tmp,0,partition.minFree);
-            AddUInt64(sumStorage,tmp,&sumStorage);
+            AddUInt64(sumFree,partition.free,&sumFree);
+            AddUInt64(sumStorage,partition.minFree,&sumStorage);
        }
     }
     if (printSummary) {
@@ -5136,7 +5146,7 @@ ChangeAddr(register struct cmd_syndesc *as, void *arock)
 
 static void
 print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
-           int print, int noresolve)
+           int print)
 {
     afs_int32 vcode;
     afs_int32 i, j;
@@ -5174,7 +5184,7 @@ print_addrs(const bulkaddrs * addrs, const afsUUID * m_uuid, int nentries,
                m_addrs.bulkaddrs_len = 0;
                vcode =
                    ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, &m_uuid,
-                                     &vlcb, &m_nentries, &m_addrs);
+                                     (afs_int32 *)&vlcb, &m_nentries, &m_addrs);
                if (vcode) {
                    fprintf(STDERR,
                            "vos: could not list the multi-homed server addresses\n");
@@ -5224,7 +5234,7 @@ static int
 ListAddrs(register struct cmd_syndesc *as, void *arock)
 {
     afs_int32 vcode;
-    afs_int32 i, noresolve = 0, printuuid = 0;
+    afs_int32 i, printuuid = 0;
     struct VLCallBack vlcb;
     afs_int32 nentries;
     bulkaddrs m_addrs;
@@ -5262,9 +5272,6 @@ ListAddrs(register struct cmd_syndesc *as, void *arock)
        m_attrs.ipaddr = ntohl(saddr);
     }
     if (as->parms[2].items) {
-       noresolve = 1;
-    }
-    if (as->parms[3].items) {
        printuuid = 1;
     }
 
@@ -5317,7 +5324,7 @@ ListAddrs(register struct cmd_syndesc *as, void *arock)
            return (vcode);
        }
 
-       print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
+       print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
        i++;
 
        if ((as->parms[1].items) || (as->parms[0].items) || (i > nentries))
@@ -5360,12 +5367,12 @@ ConvertRO(register struct cmd_syndesc *as, void *arock)
     afs_int32 server, volid, code, i, same;
     struct nvldbentry entry, storeEntry;
     afs_int32 vcode;
-    afs_int32 rwindex;
+    afs_int32 rwindex = 0;
     afs_int32 rwserver = 0;
-    afs_int32 rwpartition;
-    afs_int32 roindex;
+    afs_int32 rwpartition = 0;
+    afs_int32 roindex = 0;
     afs_int32 roserver = 0;
-    afs_int32 ropartition;
+    afs_int32 ropartition = 0;
     int force = 0;
     struct rx_connection *aconn;
     char c, dc;
@@ -5601,9 +5608,8 @@ Sizes(register struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
-PrintDiagnostics(astring, acode)
-     char *astring;
-     afs_int32 acode;
+int
+PrintDiagnostics(char *astring, afs_int32 acode)
 {
     if (acode == EACCES) {
        fprintf(STDERR,
@@ -5648,6 +5654,10 @@ MyBeforeProc(struct cmd_syndesc *as, void *arock)
        verbose = 1;
     else
        verbose = 0;
+    if (as->parms[17].items)   /* -noresolve flag set */
+       noresolve = 1;
+    else
+       noresolve = 0;
     return 0;
 }
 
@@ -6005,8 +6015,6 @@ main(argc, argv)
                          "list the IP address of all file servers registered in the VLDB");
     cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
     cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
-    cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL,
-               "don't resolve addresses");
     cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL,
                "print uuid of hosts");
     COMMONPARMS;