volinfo: refactor -sizeOnly printing
[openafs.git] / src / vol / vol-info.c
index 31ce4df..9aaf5c5 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
 #include <ctype.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <time.h>
-#include <io.h>
-#else
-#include <sys/param.h>
+
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#include <sys/time.h>
 #endif
+
 #include <afs/cmd.h>
 #include <afs/dir.h>
 
 #include <afs/afssyscalls.h>
 #include <afs/afsutil.h>
 
-#ifdef _AIX
-#include <time.h>
-#endif
-
-#include <dirent.h>
-
-#ifdef O_LARGEFILE
-#define afs_stat       stat64
-#define afs_fstat      fstat64
-#define afs_open       open64
-#else /* !O_LARGEFILE */
-#define afs_stat       stat
-#define afs_fstat      fstat
-#define afs_open       open
-#endif /* !O_LARGEFILE */
+static const char *progname = "volinfo";
 
 int DumpVnodes = 0;            /* Dump everything, i.e. summary of all vnodes */
 int DumpInodeNumber = 0;       /* Dump inode numbers with vnodes */
@@ -92,10 +71,10 @@ struct DiskPartition64 *FindCurrentPartition(void);
 Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
                     struct VolumeHeader *header);
 #if defined(AFS_NAMEI_ENV)
-void PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
+void PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
                Inode ino, Volume * vp);
 #else
-void PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
+void PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
                Inode ino);
 #endif
 void PrintVnodes(Volume * vp, VnodeClass class);
@@ -110,8 +89,8 @@ date(time_t date)
     char buf[32];
 
     (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm);  /* NT does not have %T */
-    (void)afs_snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
-                      "%lu (%s)", (unsigned long)date, buf);
+    snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
+            "%lu (%s)", (unsigned long)date, buf);
     return results[next];
 }
 
@@ -123,6 +102,64 @@ char name[VMAXPATHLEN];
 
 char BU[1000];
 
+static int PrintingVolumeSizes = 0;    /* printing volume size lines */
+
+/**
+ * Print the volume size table heading line, if needed.
+ *
+ * @return none
+ */
+static void
+PrintVolumeSizeHeading(void)
+{
+    if (!PrintingVolumeSizes) {
+       printf
+           ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
+       PrintingVolumeSizes = 1;
+    }
+}
+
+/**
+ * Print the sizes for a volume.
+ *
+ * @return none
+ */
+static void
+PrintVolumeSizes(Volume * vp)
+{
+    PrintVolumeSizeHeading();
+    printf("%u\t%9d%9d%10d%10d%9d\t%24s\n", V_id(vp), Vdiskused,
+          Vauxsize_k, Vvnodesize_k, totvolsize, totvolsize - Vdiskused,
+          V_name(vp));
+}
+
+/**
+ * Print the size totals for the partition.
+ *
+ * @return none
+ */
+static void
+PrintPartitionTotals(int nvols)
+{
+    PrintVolumeSizeHeading();
+    printf("\nPart Totals  %12d%9d%10d%10d%9d (%d volumes)\n\n",
+          TVdiskused, TVauxsize, TVvnodesize, Totvolsize,
+          Totvolsize - TVdiskused, nvols);
+    PrintingVolumeSizes = 0;
+}
+
+/**
+ * Print the size totals for all the partitions.
+ *
+ * @return none
+ */
+static void
+PrintServerTotals(void)
+{
+    printf("\nServer Totals%12d%9d%10d%10d%9d\n", SVdiskused, SVauxsize,
+          SVvnodesize, Stotvolsize, Stotvolsize - SVdiskused);
+}
+
 int
 ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
 {
@@ -138,15 +175,16 @@ ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
 
     if (vsn->magic != magic) {
        bad++;
-       printf("Inode %s: Bad magic %x (%x): IGNORED\n",
-              PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
+       fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
+               progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
     }
 
     /* Check is conditional, in case caller wants to inspect version himself */
     if (version && vsn->version != version) {
        bad++;
-       printf("Inode %s: Bad version %x (%x): IGNORED\n",
-              PrintInode(NULL, ih->ih_ino), vsn->version, version);
+       fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
+               progname,
+               PrintInode(NULL, ih->ih_ino), vsn->version, version);
     }
     if (bad && fixheader) {
        vsn->magic = magic;
@@ -155,7 +193,9 @@ ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
               PrintInode(NULL, ih->ih_ino));
        code = IH_IWRITE(ih, 0, to, size);
        if (code != size) {
-           printf("Write failed; header left in damaged state\n");
+           fprintf(stderr,
+                   "%s: Write failed for inode %s; header left in damaged state\n",
+                   progname, PrintInode(NULL, ih->ih_ino));
        }
     } else {
        if (!dsizeOnly && !saveinodes) {
@@ -227,7 +267,7 @@ handleit(struct cmd_syndesc *as, void *arock)
 
 #ifndef AFS_NT40_ENV
     if (geteuid() != 0) {
-       printf("vol-info must be run as root; sorry\n");
+       fprintf(stderr, "%s: Must be run as root; sorry\n", progname);
        exit(1);
     }
 #endif
@@ -280,26 +320,28 @@ handleit(struct cmd_syndesc *as, void *arock)
        orphaned = 1;
        DumpVnodes = 1;
     } else
+       orphaned = 0;
 #if defined(AFS_NAMEI_ENV)
     if (as->parms[12].items) {
        PrintFileNames = 1;
        DumpVnodes = 1;
     } else
+       PrintFileNames = 0;
 #endif
-       orphaned = 0;
 
     DInit(10);
 
     err = VAttachPartitions();
     if (err) {
-       printf("%d partitions had errors during attach.\n", err);
+       fprintf(stderr, "%s: %d partitions had errors during attach.\n",
+               progname, err);
     }
 
     if (partName) {
        partP = VGetPartition(partName, 0);
        if (!partP) {
-           printf("%s is not an AFS partition name on this server.\n",
-                  partName);
+           fprintf(stderr, "%s: %s is not an AFS partition name on this server.\n",
+                  progname, partName);
            exit(1);
        }
     }
@@ -316,15 +358,14 @@ handleit(struct cmd_syndesc *as, void *arock)
        if (!partP) {
            partP = FindCurrentPartition();
            if (!partP) {
-               printf("Current partition is not a vice partition.\n");
+               fprintf(stderr,
+                       "%s: Current partition is not a vice partition.\n",
+                       progname);
                exit(1);
            }
        }
-       (void)afs_snprintf(name1, sizeof name1, VFORMAT,
-                          afs_printable_uint32_lu(volumeId));
-       if (dsizeOnly && !saveinodes)
-           printf
-               ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
+       snprintf(name1, sizeof name1, VFORMAT,
+                afs_printable_uint32_lu(volumeId));
        HandleVolume(partP, name1);
     }
     return 0;
@@ -344,7 +385,8 @@ FindCurrentPartition(void)
            break;
     }
     if (!dp) {
-       printf("Current drive is not a valid vice partition.\n");
+       fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
+               progname);
     }
     return dp;
 }
@@ -358,10 +400,12 @@ FindCurrentPartition(void)
     struct DiskPartition64 *dp;
 
     if (!getcwd(partName, 1023)) {
+       fprintf(stderr, "%s: Failed to get current working directory: ",
+               progname);
        perror("pwd");
        exit(1);
     }
-    p = strchr(&partName[1], '/');
+    p = strchr(&partName[1], OS_DIRSEPC);
     if (p) {
        tmp = *p;
        *p = '\0';
@@ -369,7 +413,8 @@ FindCurrentPartition(void)
     if (!(dp = VGetPartition(partName, 0))) {
        if (tmp)
            *p = tmp;
-       printf("%s is not a valid vice partition.\n", partName);
+       fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
+               partName);
        exit(1);
     }
     return dp;
@@ -392,8 +437,7 @@ HandleAllPart(void)
     }
 
     if (dsizeOnly) {
-       printf("\nServer Totals%12d%9d%10d%10d%9d\n", SVdiskused, SVauxsize,
-              SVvnodesize, Stotvolsize, Stotvolsize - SVdiskused);
+       PrintServerTotals();
     }
 }
 
@@ -413,12 +457,10 @@ HandlePart(struct DiskPartition64 *partP)
 #endif
 
     if ((dirp = opendir(p)) == NULL) {
-       printf("Can't read directory %s; giving up\n", p);
+       fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
+               p);
        exit(1);
     }
-    if (dsizeOnly && !saveinodes)
-       printf
-           ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
     while ((dp = readdir(dirp))) {
        p = (char *)strrchr(dp->d_name, '.');
        if (p != NULL && strcmp(p, VHDREXT) == 0) {
@@ -432,157 +474,157 @@ HandlePart(struct DiskPartition64 *partP)
     }
     closedir(dirp);
     if (dsizeOnly) {
-       printf("\nPart Totals  %12d%9d%10d%10d%9d (%d volumes)\n\n",
-              TVdiskused, TVauxsize, TVvnodesize, Totvolsize,
-              Totvolsize - TVdiskused, nvols);
+       PrintPartitionTotals(nvols);
     }
 }
 
+/**
+ * Inspect a volume header special file.
+ *
+ * @param[in]  name       descriptive name of the type of header special file
+ * @param[in]  dp         partition object for this volume
+ * @param[in]  header     header object for this volume
+ * @param[in]  inode      fileserver inode number for this header special file
+ * @param[out] psize      total of the header special file
+ *
+ * @return none
+ */
+void
+HandleSpecialFile(const char *name, struct DiskPartition64 *dp,
+                 struct VolumeHeader *header, Inode inode,
+                 afs_sfsize_t * psize)
+{
+    afs_sfsize_t size = 0;
+    IHandle_t *ih = NULL;
+    FdHandle_t *fdP = NULL;
+#ifdef AFS_NAMEI_ENV
+    namei_t filename;
+#endif /* AFS_NAMEI_ENV */
+
+    IH_INIT(ih, dp->device, header->parent, inode);
+    fdP = IH_OPEN(ih);
+    if (fdP == NULL) {
+       fprintf(stderr,
+               "%s: Error opening header file '%s' for volume %u", progname,
+               name, header->id);
+       perror("open");
+       goto error;
+    }
+    size = FDH_SIZE(fdP);
+    if (size == -1) {
+       fprintf(stderr,
+               "%s: Error getting size of header file '%s' for volume %u",
+               progname, name, header->id);
+       perror("fstat");
+       goto error;
+    }
+    if (!dsizeOnly && !saveinodes) {
+       printf("\t%s inode\t= %s (size = %lld)\n",
+              name, PrintInode(NULL, inode), size);
+#ifdef AFS_NAMEI_ENV
+       namei_HandleToName(&filename, ih);
+       printf("\t%s namei\t= %s\n", name, filename.n_path);
+#endif /* AFS_NAMEI_ENV */
+    }
+    *psize += size;
+
+  error:
+    if (fdP != NULL) {
+       FDH_REALLYCLOSE(fdP);
+    }
+    if (ih != NULL) {
+       IH_RELEASE(ih);
+    }
+}
+
+/**
+ * Inspect this volume header files.
+ *
+ * @param[in]  dp         partition object for this volume
+ * @param[in]  header_fd  volume header file descriptor
+ * @param[in]  header     volume header object
+ * @param[out] psize      total of the header special file
+ *
+ * @return none
+ */
+void
+HandleHeaderFiles(struct DiskPartition64 *dp, FD_t header_fd,
+                 struct VolumeHeader *header)
+{
+    afs_sfsize_t size = 0;
+
+    if (!dsizeOnly && !saveinodes) {
+       size = OS_SIZE(header_fd);
+       printf("Volume header (size = %lld):\n", size);
+       printf("\tstamp\t= 0x%x\n", header->stamp.version);
+       printf("\tVolId\t= %u\n", header->id);
+       printf("\tparent\t= %u\n", header->parent);
+    }
+
+    HandleSpecialFile("Info", dp, header, header->volumeInfo, &size);
+    HandleSpecialFile("Small", dp, header, header->smallVnodeIndex,
+                     &size);
+    HandleSpecialFile("Large", dp, header, header->largeVnodeIndex,
+                     &size);
+#ifdef AFS_NAMEI_ENV
+    HandleSpecialFile("Link", dp, header, header->linkTable, &size);
+#endif /* AFS_NAMEI_ENV */
+
+    if (!dsizeOnly && !saveinodes) {
+       printf("Total aux volume size = %lld\n\n", size);
+    }
+    Vauxsize = size;
+    Vauxsize_k = size / 1024;
+}
 
 void
 HandleVolume(struct DiskPartition64 *dp, char *name)
 {
     struct VolumeHeader header;
     struct VolumeDiskHeader diskHeader;
-    struct afs_stat status, stat;
-    int fd;
+    FD_t fd = INVALID_FD;
     Volume *vp;
-    IHandle_t *ih;
     char headerName[1024];
 
     if (online) {
-       printf("volinfo: -online not supported\n");
+       fprintf(stderr, "%s: -online not supported\n", progname);
        exit(1);
     } else {
-       afs_int32 n;
-
-       (void)afs_snprintf(headerName, sizeof headerName, "%s/%s",
-                          VPartitionPath(dp), name);
-       if ((fd = afs_open(headerName, O_RDONLY)) == -1
-           || afs_fstat(fd, &status) == -1) {
-           printf("Volinfo: Cannot read volume header %s\n", name);
-           close(fd);
+       afs_sfsize_t n;
+
+       snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
+                VPartitionPath(dp), name);
+       if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD
+           || OS_SIZE(fd) < 0) {
+           fprintf(stderr, "%s: Cannot read volume header %s\n", progname,
+                   name);
+           OS_CLOSE(fd);
            exit(1);
        }
-       n = read(fd, &diskHeader, sizeof(diskHeader));
+       n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
 
        if (n != sizeof(diskHeader)
            || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
-           printf("Volinfo: Error reading volume header %s\n", name);
+           fprintf(stderr, "%s: Error reading volume header %s\n", progname,
+                   name);
            exit(1);
        }
        if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
-           printf
-               ("Volinfo: Volume %s, version number is incorrect; volume needs salvage\n",
-                name);
+           fprintf(stderr,
+                   "%s: Volume %s, version number is incorrect; volume needs salvage\n",
+                   progname, name);
            exit(1);
        }
        DiskToVolumeHeader(&header, &diskHeader);
 
        if (dheader) {
-           FdHandle_t *fdP;
-           afs_sfsize_t size = 0;
-           afs_sfsize_t code;
-
-           if (afs_fstat(fd, &stat) == -1) {
-               perror("stat");
-               exit(1);
-           }
-           if (!dsizeOnly && !saveinodes) {
-               size = stat.st_size;
-               printf("Volume header (size = %d):\n", (int)size);
-               printf("\tstamp\t= 0x%x\n", header.stamp.version);
-               printf("\tVolId\t= %u\n", header.id);
-           }
-
-           IH_INIT(ih, dp->device, header.parent, header.volumeInfo);
-           fdP = IH_OPEN(ih);
-           if (fdP == NULL) {
-               perror("opening volume info");
-               exit(1);
-           }
-           code = FDH_SIZE(fdP);
-           if (code == -1) {
-               perror("fstat");
-               exit(1);
-           }
-           FDH_REALLYCLOSE(fdP);
-           IH_RELEASE(ih);
-           size += code;
-           if (!dsizeOnly && !saveinodes) {
-               printf("\tparent\t= %u\n", header.parent);
-               printf("\tInfo inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.volumeInfo), (int)code);
-           }
-
-           IH_INIT(ih, dp->device, header.parent, header.smallVnodeIndex);
-           fdP = IH_OPEN(ih);
-           if (fdP == NULL) {
-               perror("opening small vnode index");
-               exit(1);
-           }
-           code = FDH_SIZE(fdP);
-           if (code == -1) {
-               perror("fstat");
-               exit(1);
-           }
-           FDH_REALLYCLOSE(fdP);
-           IH_RELEASE(ih);
-           size += code;
-           if (!dsizeOnly && !saveinodes) {
-               printf("\tSmall inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.smallVnodeIndex), (int)code);
-           }
-
-           IH_INIT(ih, dp->device, header.parent, header.largeVnodeIndex);
-           fdP = IH_OPEN(ih);
-           if (fdP == NULL) {
-               perror("opening large vnode index");
-               exit(1);
-           }
-           code = FDH_SIZE(fdP);
-           if (code == -1) {
-               perror("fstat");
-               exit(1);
-           }
-           FDH_REALLYCLOSE(fdP);
-           IH_RELEASE(ih);
-           size += code;
-           if (!dsizeOnly && !saveinodes) {
-               printf("\tLarge inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.largeVnodeIndex), (int)code);
-#ifndef AFS_NT40_ENV
-               printf("Total aux volume size = %d\n\n", (int)size);
-#endif
-           }
-#ifdef AFS_NAMEI_ENV
-           IH_INIT(ih, dp->device, header.parent, header.linkTable);
-           fdP = IH_OPEN(ih);
-           if (fdP == NULL) {
-               perror("opening link table index");
-               exit(1);
-           }
-           code = FDH_SIZE(fdP);
-           if (code == -1) {
-               perror("fstat");
-               exit(1);
-           }
-           FDH_REALLYCLOSE(fdP);
-           IH_RELEASE(ih);
-           size += code;
-           if (!dsizeOnly && !saveinodes) {
-               printf("\tLink inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.linkTable), (int)code);
-               printf("Total aux volume size = %d\n\n", (int)size);
-           }
-#endif
-           Vauxsize = size;
-           Vauxsize_k = size / 1024;
+           HandleHeaderFiles(dp, fd, &header);
        }
-       close(fd);
+       OS_CLOSE(fd);
        vp = AttachVolume(dp, name, &header);
        if (!vp) {
-           printf("Volinfo: Error attaching volume header %s\n", name);
+           fprintf(stderr, "%s: Error attaching volume header %s\n",
+                   progname, name);
            return;
        }
     }
@@ -595,18 +637,15 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
            printf("\nSmall vnodes(files, symbolic links)\n");
            fflush(stdout);
        }
-       if (saveinodes)
+       if (saveinodes) {
            printf("Saving all volume files to current directory ...\n");
+           PrintingVolumeSizes = 0;    /* -saveinodes interfers with -sizeOnly */
+       }
        PrintVnodes(vp, vSmall);
     }
     if (dsizeOnly) {
        totvolsize = Vauxsize_k + Vvnodesize_k;
-       if (saveinodes)
-           printf
-               ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
-       printf("%u\t%9d%9d%10d%10d%9d\t%24s\n", V_id(vp), Vdiskused,
-              Vauxsize_k, Vvnodesize_k, totvolsize, totvolsize - Vdiskused,
-              V_name(vp));
+       PrintVolumeSizes(vp);
     }
     free(vp->header);
     free(vp);
@@ -625,7 +664,7 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL,
                "Also dump vnode's mod date");
     cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL,
-               "Dump vnode's inode number");
+               "Also dump vnode's inode number");
     cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL,
                "Dump special inode's mod times");
     cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL,
@@ -642,7 +681,7 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
                "List all dir/files without a parent");
 #if defined(AFS_NAMEI_ENV)
-    cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Print filenames");
+    cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's namei filename");
 #endif
     code = cmd_Dispatch(argc, argv);
     return code;
@@ -705,7 +744,7 @@ NT_date(FILETIME * ft)
 
     if (!FileTimeToLocalFileTime(ft, &lft)
        || !FileTimeToSystemTime(&lft, &st)) {
-       printf("Time conversion failed.\n");
+       fprintf(stderr, "%s: Time conversion failed.\n", progname);
        exit(1);
     }
     sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
@@ -720,7 +759,8 @@ GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime)
 #ifdef AFS_NT40_ENV
     BY_HANDLE_FILE_INFORMATION fi;
     if (!GetFileInformationByHandle(fd, &fi)) {
-       printf("GetFileInformationByHandle failed, exiting\n");
+       fprintf(stderr, "%s: GetFileInformationByHandle failed, exiting\n",
+               progname);
        exit(1);
     }
     *size = (int)fi.nFileSizeLow;
@@ -728,9 +768,9 @@ GetFileInfo(FD_t fd, int *size, char **ctime, char **mtime, char **atime)
     *mtime = NT_date(&fi.ftLastWriteTime);
     *atime = NT_date(&fi.ftLastAccessTime);
 #else
-    struct afs_stat status;
+    struct afs_stat_st status;
     if (afs_fstat(fd, &status) == -1) {
-       printf("fstat failed %d\n", errno);
+       fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
        exit(1);
     }
     *size = (int)status.st_size;
@@ -748,7 +788,8 @@ PrintVnodes(Volume * vp, VnodeClass class)
     char buf[SIZEOF_LARGEDISKVNODE];
     struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
     StreamHandle_t *file;
-    int vnodeIndex, nVnodes, offset = 0;
+    int vnodeIndex, nVnodes;
+    afs_foff_t offset = 0;
     Inode ino;
     IHandle_t *ih = vp->vnodeIndex[class].handle;
     FdHandle_t *fdP;
@@ -761,13 +802,13 @@ PrintVnodes(Volume * vp, VnodeClass class)
 
     fdP = IH_OPEN(ih);
     if (fdP == NULL) {
-       printf("open failed\n");
+       fprintf(stderr, "%s: open failed: ", progname);
        exit(1);
     }
 
     file = FDH_FDOPEN(fdP, "r");
     if (!file) {
-       printf("fdopen failed\n");
+       fprintf(stderr, "%s: fdopen failed\n", progname);
        exit(1);
     }
 
@@ -789,22 +830,33 @@ PrintVnodes(Volume * vp, VnodeClass class)
 
        ino = VNDISK_GET_INO(vnode);
        if (saveinodes) {
-           if (VALID_INO(ino) && (class == vSmall)) {
+           if (!VALID_INO(ino)) {
+               continue;
+           }
+           if (dsizeOnly && (class == vLarge)) {
+               afs_fsize_t fileLength;
+
+               VNDISK_GET_LEN(fileLength, vnode);
+               Vvnodesize += fileLength;
+               Vvnodesize_k += fileLength / 1024;
+           } else if (class == vSmall) {
                IHandle_t *ih1;
                FdHandle_t *fdP1;
                IH_INIT(ih1, V_device(vp), V_parentId(vp), ino);
                fdP1 = IH_OPEN(ih1);
                if (fdP1 == NULL) {
-                   printf("Can't open inode %s error %d (ignored)\n",
-                          PrintInode(NULL, ino), errno);
+                   fprintf(stderr,
+                           "%s: Can't open inode %s error %d (ignored)\n",
+                           progname, PrintInode(NULL, ino), errno);
                    continue;
                }
-               (void)afs_snprintf(nfile, sizeof nfile, "TmpInode.%s",
-                                  PrintInode(NULL, ino));
+               snprintf(nfile, sizeof nfile, "TmpInode.%s",
+                        PrintInode(NULL, ino));
                ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
                if (ofd < 0) {
-                   printf("Can't create file %s; error %d (ignored)\n",
-                          nfile, errno);
+                   fprintf(stderr,
+                           "%s: Can't create file %s; error %d (ignored)\n",
+                           progname, nfile, errno);
                    continue;
                }
                total = bad = 0;
@@ -816,9 +868,9 @@ PrintVnodes(Volume * vp, VnodeClass class)
                        IH_RELEASE(ih1);
                        close(ofd);
                        unlink(nfile);
-                       printf
-                           ("Error while reading from inode %s (%d - ignored)\n",
-                            PrintInode(NULL, ino), errno);
+                       fprintf(stderr,
+                               "%s: Error while reading from inode %s (%d - ignored)\n",
+                               progname, PrintInode(NULL, ino), errno);
                        bad = 1;
                        break;
                    }
@@ -830,9 +882,9 @@ PrintVnodes(Volume * vp, VnodeClass class)
                        IH_RELEASE(ih1);
                        close(ofd);
                        unlink(nfile);
-                       printf
-                           ("Error while writing to \"%s\" (%d - ignored)\n",
-                            nfile, errno);
+                       fprintf(stderr,
+                               "%s: Error while writing to \"%s\" (%d - ignored)\n",
+                               progname, nfile, errno);
                        bad = 1;
                        break;
                    }
@@ -862,21 +914,17 @@ PrintVnodes(Volume * vp, VnodeClass class)
 
 #if defined(AFS_NAMEI_ENV)
 void
-PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
+PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
           Inode ino, Volume * vp)
 #else
 void
-PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
+PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
           Inode ino)
 #endif
 {
 #if defined(AFS_NAMEI_ENV)
     IHandle_t *ihtmpp;
-#if !defined(AFS_NT40_ENV)
     namei_t filename;
-#else
-    char filename[MAX_PATH];
-#endif
 #endif
     afs_fsize_t fileLength;
 
@@ -888,8 +936,8 @@ PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
     if (orphaned && (fileLength == 0 || vnode->parent || !offset))
        return;
     printf
-       ("%10d Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
-        offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion,
+       ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
+        (long long)offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion,
         vnode->cloned, (afs_uintmax_t) fileLength, vnode->linkCount,
         vnode->parent);
     if (DumpInodeNumber)
@@ -899,12 +947,11 @@ PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
 #if defined(AFS_NAMEI_ENV)
     if (PrintFileNames) {
        IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino);
-#if !defined(AFS_NT40_ENV)
        namei_HandleToName(&filename, ihtmpp);
+#if !defined(AFS_NT40_ENV)
        printf(" UFS-Filename: %s", filename.n_path);
 #else
-       nt_HandleToName(filename, ihtmpp);
-       printf(" NTFS-Filename: %s", filename);
+       printf(" NTFS-Filename: %s", filename.n_path);
 #endif
     }
 #endif