include-afsconfig-before-param-h-20010712
[openafs.git] / src / vol / test / nilist.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* nilist.c - List the "inode" information for one or all volumes on
11  * a partition.
12  */
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17 RCSID("$Header$");
18
19 #include <stdio.h>
20 #ifdef AFS_NT40_ENV
21 #include <windows.h>
22 #include <winbase.h>
23 #endif
24 #include "nfs.h"
25 #include <afs/afsint.h>
26 #include "ihandle.h"
27 #include <lock.h>
28 #include "vnode.h"
29 #include "volume.h"
30 #include "viceinode.h"
31
32 #ifndef AFS_NAMEI_ENV
33 main()
34 {
35      printf("nilist is only useful for namei AFS file server"
36             " implementations.\n");
37      exit(1);
38 }
39 #else
40
41 void Usage(void)
42 {
43     printf("Usage: nilist partition [volume]\n");
44     printf("List all \"inodes\" for the volume group containing the volume\n");
45     printf("or for the entire partition.\n");
46     exit(1);
47 }
48
49 /* This judge function can be a dummy since I know how nt_ListAFSFiles works */
50 int Judge(struct ViceInodeInfo *info, int vid)
51 {
52     return 1;
53 }
54
55 int PrintInodeInfo(FILE *fp, struct ViceInodeInfo *info, char *dir, char *name)
56 {
57     static int lastVID = -1;
58     int rwVID;
59     char dname[1024];
60     
61     rwVID = info->u.param[1] == -1 ? info->u.special.parentId : 
62         info->u.vnode.volumeId;
63
64     if (rwVID != lastVID) {
65         if (lastVID != -1)
66             printf("\n");
67         lastVID = rwVID;
68         /* This munging of the name remove a "\R". */
69         (void) strcpy(dname, dir);
70         dname[strlen(dname)-2] = '\0';
71         printf("Parent Volume %d, Directory %s\n", rwVID, dname);
72         printf("%19s %8s %5s %10s %10s %10s %10s %s\n", "Inode", "Size",
73                "Nlink", "P1", "P2", "P3", "P4", "Name");
74     }
75 #ifdef AFS_NT40_ENV
76     printf("%19I64d %8d %5d %10d %10d %10d %10d %s\n", info->inodeNumber,
77            info->byteCount, info->linkCount, info->u.param[0],
78            info->u.param[1], info->u.param[2], info->u.param[3], name);
79 #else
80     printf("%19lld %8d %5d %10d %10d %10d %10d %s\n", info->inodeNumber,
81            info->byteCount, info->linkCount, info->u.param[0],
82            info->u.param[1], info->u.param[2], info->u.param[3], name);
83 #endif
84
85     return 0;
86 }
87
88 main(int ac, char **av)
89 {
90     int singleVolumeNumber = 0;
91     char *part;
92     int ninodes;
93
94     if (ac < 2 || ac > 3) Usage();
95
96     part = av[1];
97     if (ac == 3)
98         singleVolumeNumber = atoi(av[2]);
99
100 #ifdef AFS_NT40_ENV
101     ninodes = nt_ListAFSFiles(part, PrintInodeInfo, stdout,
102                               Judge, singleVolumeNumber);
103 #else
104     ninodes = namei_ListAFSFiles(part, PrintInodeInfo, stdout,
105                                  Judge, singleVolumeNumber);
106 #endif
107 }
108
109
110 #endif /* AFS_NAMEI_ENV */