merge ntops and namei
[openafs.git] / src / vol / vol-info.c
index 77d6162..0edc296 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
    System:             VICE-TWO
    Module:             vol-info.c
    Institution:        The Information Technology Center, Carnegie-Mellon University
-   
+
    */
 
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <ctype.h>
 #include <errno.h>
@@ -35,6 +33,7 @@ RCSID
 #include <sys/time.h>
 #endif
 #include <afs/cmd.h>
+#include <afs/dir.h>
 
 #include <rx/xdr.h>
 #include <afs/afsint.h>
@@ -48,10 +47,9 @@ RCSID
 #include "volume.h"
 #include "partition.h"
 #include "viceinode.h"
-#include "volinodes.h"
 #include <afs/afssyscalls.h>
 #include <afs/afsutil.h>
-    
+
 #ifdef _AIX
 #include <time.h>
 #endif
@@ -86,13 +84,13 @@ int fixheader = 0, saveinodes = 0, orphaned = 0;
 int VolumeChanged;
 
 /* Forward Declarations */
-void PrintHeader(register Volume * vp);
+void PrintHeader(Volume * vp);
 void HandleAllPart(void);
 void HandlePart(struct DiskPartition64 *partP);
 void HandleVolume(struct DiskPartition64 *partP, char *name);
 struct DiskPartition64 *FindCurrentPartition(void);
 Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
-                    register struct VolumeHeader *header);
+                    struct VolumeHeader *header);
 #if defined(AFS_NAMEI_ENV)
 void PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
                Inode ino, Volume * vp);
@@ -171,9 +169,9 @@ ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
 
 Volume *
 AttachVolume(struct DiskPartition64 * dp, char *volname,
-            register struct VolumeHeader * header)
+            struct VolumeHeader * header)
 {
-    register Volume *vp;
+    Volume *vp;
     afs_int32 ec = 0;
 
     vp = (Volume *) calloc(1, sizeof(Volume));
@@ -220,7 +218,7 @@ AttachVolume(struct DiskPartition64 * dp, char *volname,
 static int
 handleit(struct cmd_syndesc *as, void *arock)
 {
-    register struct cmd_item *ti;
+    struct cmd_item *ti;
     int err = 0;
     afs_uint32 volumeId = 0;
     char *partName = 0;
@@ -323,7 +321,7 @@ handleit(struct cmd_syndesc *as, void *arock)
            }
        }
        (void)afs_snprintf(name1, sizeof name1, VFORMAT,
-                          afs_cast_uint32(volumeId));
+                          afs_printable_uint32_lu(volumeId));
        if (dsizeOnly && !saveinodes)
            printf
                ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
@@ -447,7 +445,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
     struct VolumeHeader header;
     struct VolumeDiskHeader diskHeader;
     struct afs_stat status, stat;
-    register int fd;
+    int fd;
     Volume *vp;
     IHandle_t *ih;
     char headerName[1024];
@@ -483,15 +481,16 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
 
        if (dheader) {
            FdHandle_t *fdP;
-           int size = 0;
-           int code;
+           afs_sfsize_t size = 0;
+           afs_sfsize_t code;
 
            if (afs_fstat(fd, &stat) == -1) {
                perror("stat");
                exit(1);
            }
            if (!dsizeOnly && !saveinodes) {
-               printf("Volume header (size = %d):\n", size = stat.st_size);
+               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);
            }
@@ -513,7 +512,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
            if (!dsizeOnly && !saveinodes) {
                printf("\tparent\t= %u\n", header.parent);
                printf("\tInfo inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.volumeInfo), code);
+                      PrintInode(NULL, header.volumeInfo), (int)code);
            }
 
            IH_INIT(ih, dp->device, header.parent, header.smallVnodeIndex);
@@ -532,7 +531,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
            size += code;
            if (!dsizeOnly && !saveinodes) {
                printf("\tSmall inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.smallVnodeIndex), code);
+                      PrintInode(NULL, header.smallVnodeIndex), (int)code);
            }
 
            IH_INIT(ih, dp->device, header.parent, header.largeVnodeIndex);
@@ -551,9 +550,9 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
            size += code;
            if (!dsizeOnly && !saveinodes) {
                printf("\tLarge inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.largeVnodeIndex), code);
+                      PrintInode(NULL, header.largeVnodeIndex), (int)code);
 #ifndef AFS_NT40_ENV
-               printf("Total aux volume size = %d\n\n", size);
+               printf("Total aux volume size = %d\n\n", (int)size);
 #endif
            }
 #ifdef AFS_NAMEI_ENV
@@ -573,8 +572,8 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
            size += code;
            if (!dsizeOnly && !saveinodes) {
                printf("\tLink inode\t= %s (size = %d)\n",
-                      PrintInode(NULL, header.linkTable), code);
-               printf("Total aux volume size = %d\n\n", size);
+                      PrintInode(NULL, header.linkTable), (int)code);
+               printf("Total aux volume size = %d\n\n", (int)size);
            }
 #endif
            Vauxsize = size;
@@ -616,7 +615,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name)
 int
 main(int argc, char **argv)
 {
-    register struct cmd_syndesc *ts;
+    struct cmd_syndesc *ts;
     afs_int32 code;
 
     ts = cmd_CreateSyntax(NULL, handleit, NULL, "Dump volume's internal state");
@@ -652,7 +651,7 @@ main(int argc, char **argv)
 #define typestring(type) (type == RWVOL? "read/write": type == ROVOL? "readonly": type == BACKVOL? "backup": "unknown")
 
 void
-PrintHeader(register Volume * vp)
+PrintHeader(Volume * vp)
 {
     Vdiskused = V_diskused(vp);
     if (dsizeOnly || saveinodes)
@@ -749,14 +748,16 @@ PrintVnodes(Volume * vp, VnodeClass class)
     char buf[SIZEOF_LARGEDISKVNODE];
     struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
     StreamHandle_t *file;
-    register int vnodeIndex, nVnodes, offset = 0;
+    int vnodeIndex, nVnodes, offset = 0;
     Inode ino;
     IHandle_t *ih = vp->vnodeIndex[class].handle;
     FdHandle_t *fdP;
     int size;
     char *ctime, *atime, *mtime;
     char nfile[50], buffer[256];
-    int total, ofd, len, code, bad = 0;
+    int ofd, bad = 0;
+    afs_foff_t total;
+    ssize_t len;
 
     fdP = IH_OPEN(ih);
     if (fdP == NULL) {
@@ -778,7 +779,7 @@ PrintVnodes(Volume * vp, VnodeClass class)
 
     nVnodes = (size / diskSize) - 1;
     if (nVnodes > 0) {
-       STREAM_SEEK(file, diskSize, 0);
+       STREAM_ASEEK(file, diskSize);
     } else
        nVnodes = 0;
 
@@ -808,7 +809,8 @@ PrintVnodes(Volume * vp, VnodeClass class)
                }
                total = bad = 0;
                while (1) {
-                   len = FDH_READ(fdP1, buffer, sizeof(buffer));
+                   ssize_t nBytes;
+                   len = FDH_PREAD(fdP1, buffer, sizeof(buffer), total);
                    if (len < 0) {
                        FDH_REALLYCLOSE(fdP1);
                        IH_RELEASE(ih1);
@@ -822,8 +824,8 @@ PrintVnodes(Volume * vp, VnodeClass class)
                    }
                    if (len == 0)
                        break;  /* No more input */
-                   code = write(ofd, buffer, len);
-                   if (code != len) {
+                   nBytes = write(ofd, buffer, len);
+                   if (nBytes != len) {
                        FDH_REALLYCLOSE(fdP1);
                        IH_RELEASE(ih1);
                        close(ofd);
@@ -841,8 +843,8 @@ PrintVnodes(Volume * vp, VnodeClass class)
                FDH_REALLYCLOSE(fdP1);
                IH_RELEASE(ih1);
                close(ofd);
-               printf("... Copied inode %s to file %s (%d bytes)\n",
-                      PrintInode(NULL, ino), nfile, total);
+               printf("... Copied inode %s to file %s (%lu bytes)\n",
+                      PrintInode(NULL, ino), nfile, (unsigned long)total);
            }
        } else {
 #if defined(AFS_NAMEI_ENV)
@@ -870,11 +872,7 @@ PrintVnode(int offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
 {
 #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;
 
@@ -897,12 +895,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