Expand ProgramType enumeration
[openafs.git] / src / volser / vol-dump.c
index 47ee1fa..e389c5b 100644 (file)
@@ -17,8 +17,9 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#ifdef IGNORE_SOME_GCC_WARNINGS
+# pragma GCC diagnostic warning "-Wformat"
+#endif
 
 #include <ctype.h>
 #include <errno.h>
@@ -38,18 +39,20 @@ RCSID
 
 #include <rx/xdr.h>
 #include <afs/afsint.h>
-#include "nfs.h"
+#include <afs/nfs.h>
 #include <afs/errors.h>
-#include "lock.h"
-#include "lwp.h"
+#include <lock.h>
+#include <lwp.h>
 #include <afs/afssyscalls.h>
-#include "ihandle.h"
-#include "vnode.h"
-#include "volume.h"
-#include "partition.h"
-#include "viceinode.h"
+#include <afs/ihandle.h>
+#include <afs/vnode.h>
+#include <afs/volume.h>
+#include <afs/partition.h>
+#include <afs/viceinode.h>
 #include <afs/afssyscalls.h>
-#include "acl.h"
+#include <afs/acl.h>
+#include <afs/dir.h>
+#include <afs/com_err.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -69,9 +72,9 @@ RCSID
 
 #include <dirent.h>
 
-#include "volser/volser.h"
-#include "volser/volint.h"
-#include "volser/dump.h"
+#include "volser.h"
+#include "volint.h"
+#include "dump.h"
 
 #define putint32(p, v)  *p++ = v>>24, *p++ = v>>16, *p++ = v>>8, *p++ = v
 #define putshort(p, v) *p++ = v>>8, *p++ = v
@@ -90,11 +93,11 @@ int VolumeChanged;          /* needed by physio - leave alone */
 int verbose = 0;
 
 /* Forward Declarations */
-void HandleVolume(struct DiskPartition *partP, char *name, char *filename);
-Volume *AttachVolume(struct DiskPartition *dp, char *volname,
+void HandleVolume(struct DiskPartition64 *partP, char *name, char *filename, int fromtime);
+Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
                     register struct VolumeHeader *header);
-static void DoMyVolDump(Volume * vp, struct DiskPartition *dp,
-                       char *dumpfile);
+static void DoMyVolDump(Volume * vp, struct DiskPartition64 *dp,
+                       char *dumpfile, int fromtime);
 
 #ifndef AFS_NT40_ENV
 #include "AFS_component_version_number.c"
@@ -106,7 +109,6 @@ char name[VMAXPATHLEN];
 int
 ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
 {
-    int bad = 0;
     int code;
 
     code = IH_IREAD(ih, 0, to, size);
@@ -118,7 +120,7 @@ ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
 
 
 Volume *
-AttachVolume(struct DiskPartition * dp, char *volname,
+AttachVolume(struct DiskPartition64 * dp, char *volname,
             register struct VolumeHeader * header)
 {
     register Volume *vp;
@@ -166,16 +168,18 @@ AttachVolume(struct DiskPartition * dp, char *volname,
 
 
 static int
-handleit(struct cmd_syndesc *as, char *arock)
+handleit(struct cmd_syndesc *as, void *arock)
 {
     register struct cmd_item *ti;
     int err = 0;
-    int volumeId = 0;
+    afs_uint32 volumeId = 0;
     char *partName = 0;
     char *fileName = NULL;
-    struct DiskPartition *partP = NULL;
+    struct DiskPartition64 *partP = NULL;
     char name1[128];
     char tmpPartName[20];
+    int fromtime = 0;
+    afs_int32 code;
 
 
 #ifndef AFS_NT40_ENV
@@ -190,11 +194,19 @@ handleit(struct cmd_syndesc *as, char *arock)
     if ((ti = as->parms[0].items))
        partName = ti->data;
     if ((ti = as->parms[1].items))
-       volumeId = atoi(ti->data);
+       volumeId = (afs_uint32)atoi(ti->data);
     if ((ti = as->parms[2].items))
        fileName = ti->data;
     if ((ti = as->parms[3].items))
        verbose = 1;
+    if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) {
+       code = ktime_DateToInt32(as->parms[4].items->data, &fromtime);
+       if (code) {
+           fprintf(STDERR, "failed to parse date '%s' (error=%d))\n",
+               as->parms[4].items->data, code);
+               return code;
+       }
+    }
 
     DInit(10);
 
@@ -232,19 +244,18 @@ handleit(struct cmd_syndesc *as, char *arock)
     }
 
     (void)afs_snprintf(name1, sizeof name1, VFORMAT, (unsigned long)volumeId);
-    HandleVolume(partP, name1, fileName);
+    HandleVolume(partP, name1, fileName, fromtime);
     return 0;
 }
 
 void
-HandleVolume(struct DiskPartition *dp, char *name, char *filename)
+HandleVolume(struct DiskPartition64 *dp, char *name, char *filename, int fromtime)
 {
     struct VolumeHeader header;
     struct VolumeDiskHeader diskHeader;
-    struct afs_stat status, stat;
+    struct afs_stat status;
     register int fd;
     Volume *vp;
-    IHandle_t *ih;
     char headerName[1024];
 
     afs_int32 n;
@@ -279,7 +290,7 @@ HandleVolume(struct DiskPartition *dp, char *name, char *filename)
        exit(1);
     }
 
-    DoMyVolDump(vp, dp, filename);
+    DoMyVolDump(vp, dp, filename, fromtime);
 }
 
 
@@ -288,16 +299,19 @@ main(int argc, char **argv)
 {
     register struct cmd_syndesc *ts;
     afs_int32 code;
+    VolumePackageOptions opts;
 
-    VInitVolumePackage(volumeUtility, 5, 5, DONT_CONNECT_FS, 0);
+    VOptDefaults(volumeUtility, &opts);
+    VInitVolumePackage2(volumeUtility, &opts);
 
-    ts = cmd_CreateSyntax(NULL, handleit, 0,
+    ts = cmd_CreateSyntax(NULL, handleit, NULL,
                          "Dump a volume to a 'vos dump' format file without using volserver");
     cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name");
     cmd_AddParm(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id");
     cmd_AddParm(ts, "-file", CMD_LIST, CMD_OPTIONAL, "Dump filename");
     cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL,
                "Trace dump progress (very verbose)");
+    cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
     code = cmd_Dispatch(argc, argv);
     return code;
 }
@@ -508,8 +522,6 @@ DumpVolumeHeader(int dumpfd, register Volume * vp)
        code = DumpInt32(dumpfd, 'D', V_dayUseDate(vp));
     if (!code)
        code = DumpInt32(dumpfd, 'Z', V_dayUse(vp));
-    if (!code)
-       code = DumpInt32(dumpfd, 'V', V_volUpCounter(vp));
     return code;
 }
 
@@ -543,13 +555,14 @@ static int
 DumpFile(int dumpfd, int vnode, FdHandle_t * handleP,  struct VnodeDiskObject *v)
 {
     int code = 0, failed_seek = 0, failed_write = 0;
-    afs_int32 pad = 0, offset;
+    afs_int32 pad = 0;
+    afs_int32 offset = 0;
     afs_sfsize_t n, nbytes, howMany, howBig;
     byte *p;
 #ifndef AFS_NT40_ENV
     struct afs_stat status;
 #endif
-    afs_sfsize_t size, tmpsize;
+    afs_sfsize_t size;
 #ifdef AFS_AIX_ENV
 #include <sys/statfs.h>
     struct statfs tstatfs;
@@ -582,7 +595,8 @@ DumpFile(int dumpfd, int vnode, FdHandle_t * handleP,  struct VnodeDiskObject *v
 
     if (verbose)
        fprintf(stderr, "  howBig = %u, howMany = %u, fdh size = %u\n",
-               howBig, howMany, size);
+               (unsigned int) howBig, (unsigned int) howMany,
+               (unsigned int) size);
 
 #ifdef AFS_LARGEFILE_ENV
     {
@@ -833,19 +847,19 @@ DumpPartial(int dumpfd, register Volume * vp, afs_int32 fromtime,
 
 
 static void
-DoMyVolDump(Volume * vp, struct DiskPartition *dp, char *dumpfile)
+DoMyVolDump(Volume * vp, struct DiskPartition64 *dp, char *dumpfile, int fromtime)
 {
     int code = 0;
-    int fromtime = 0;
     int dumpAllDirs = 0;
     int dumpfd = 0;
 
     if (dumpfile) {
        unlink(dumpfile);
        dumpfd =
-           open(dumpfile, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
+           afs_open(dumpfile, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
        if (dumpfd < 0) {
-           fprintf(stderr, "Failed to open dump file! Exiting.\n");
+           fprintf(stderr, "Failed to open dump file: %s. Exiting.\n",
+                   afs_error_message(errno));
            exit(1);
        }
     } else {