Import Upstream version 1.8.5
[hcoop/debian/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
18 #include <stdio.h>
19 #ifdef AFS_NT40_ENV
20 #include <windows.h>
21 #include <winbase.h>
22 #endif
23 #include "nfs.h"
24 #include <afs/afsint.h>
25 #include "ihandle.h"
26 #include <lock.h>
27 #include "vnode.h"
28 #include "volume.h"
29 #include "viceinode.h"
30
31 #ifndef AFS_NAMEI_ENV
32 main()
33 {
34 printf("nilist is only useful for namei AFS file server"
35 " implementations.\n");
36 exit(1);
37 }
38 #else
39
40 void
41 Usage(void)
42 {
43 printf("Usage: nilist partition [volume]\n");
44 printf
45 ("List all \"inodes\" for the volume group containing the volume\n");
46 printf("or for the entire partition.\n");
47 exit(1);
48 }
49
50 /* This judge function can be a dummy since I know how nt_ListAFSFiles works */
51 int
52 Judge(struct ViceInodeInfo *info, int vid)
53 {
54 return 1;
55 }
56
57 int
58 PrintInodeInfo(FILE * fp, struct ViceInodeInfo *info, char *dir, char *name)
59 {
60 static int lastVID = -1;
61 int rwVID;
62 char dname[1024];
63
64 rwVID =
65 info->u.param[1] ==
66 -1 ? info->u.special.parentId : info->u.vnode.volumeId;
67
68 if (rwVID != lastVID) {
69 if (lastVID != -1)
70 printf("\n");
71 lastVID = rwVID;
72 /* This munging of the name remove a "\R". */
73 (void)strcpy(dname, dir);
74 dname[strlen(dname) - 2] = '\0';
75 printf("Parent Volume %d, Directory %s\n", rwVID, dname);
76 printf("%19s %8s %5s %10s %10s %10s %10s %s\n", "Inode", "Size",
77 "Nlink", "P1", "P2", "P3", "P4", "Name");
78 }
79 #ifdef AFS_NT40_ENV
80 printf("%19I64d %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 #else
84 printf("%19lld %8d %5d %10d %10d %10d %10d %s\n", info->inodeNumber,
85 info->byteCount, info->linkCount, info->u.param[0],
86 info->u.param[1], info->u.param[2], info->u.param[3], name);
87 #endif
88
89 return 0;
90 }
91
92 main(int ac, char **av)
93 {
94 int singleVolumeNumber = 0;
95 char *part;
96 int ninodes;
97
98 if (ac < 2 || ac > 3)
99 Usage();
100
101 part = av[1];
102 if (ac == 3)
103 singleVolumeNumber = atoi(av[2]);
104
105 #ifdef AFS_NT40_ENV
106 ninodes =
107 nt_ListAFSFiles(part, PrintInodeInfo, stdout, Judge,
108 singleVolumeNumber);
109 #else
110 ninodes =
111 namei_ListAFSFiles(part, PrintInodeInfo, stdout, Judge,
112 singleVolumeNumber);
113 #endif
114 }
115
116
117 #endif /* AFS_NAMEI_ENV */