Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vol / volinfo-main.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 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14 #include <ctype.h>
15 #include <afs/cmd.h>
16 #include <afs/afsint.h>
17 #include <rx/rx_queue.h>
18 #include "nfs.h"
19 #include "ihandle.h"
20 #include "lock.h"
21 #include "vnode.h" /* for vSmall, vLarge */
22 #include "vol-info.h"
23
24 #ifndef AFS_NT40_ENV
25 #include "AFS_component_version_number.c"
26 #endif
27
28 static const char *progname = "volinfo";
29
30 /* Command line options */
31 typedef enum {
32 P_CHECKOUT,
33 P_VNODE,
34 P_DATE,
35 P_INODE,
36 P_ITIME,
37 P_PART,
38 P_VOLUMEID,
39 P_HEADER,
40 P_SIZEONLY,
41 P_FIXHEADER,
42 P_SAVEINODES,
43 P_ORPHANED,
44 P_FILENAMES,
45 } volinfo_parm_t;
46
47 /**
48 * Process command line options and start scanning
49 *
50 * @param[in] as command syntax object
51 * @param[in] arock opaque object; not used
52 *
53 * @return error code
54 */
55 static int
56 VolInfo(struct cmd_syndesc *as, void *arock)
57 {
58 int code;
59 struct cmd_item *ti;
60 VolumeId volumeId = 0;
61 char *partNameOrId = NULL;
62 struct VolInfoOpt *opt;
63
64 code = volinfo_Init(progname);
65 if (code) {
66 return code;
67 }
68 code = volinfo_Options(&opt);
69 if (code) {
70 return code;
71 }
72
73 if (as->parms[P_CHECKOUT].items) {
74 opt->checkout = 1;
75 }
76 if (as->parms[P_VNODE].items) {
77 opt->dumpVnodes = 1;
78 }
79 if (as->parms[P_DATE].items) {
80 opt->dumpDate = 1;
81 }
82 if (as->parms[P_INODE].items) {
83 opt->dumpInodeNumber = 1;
84 }
85 if (as->parms[P_ITIME].items) {
86 opt->dumpInodeTimes = 1;
87 }
88 if ((ti = as->parms[P_PART].items)) {
89 partNameOrId = ti->data;
90 }
91 if ((ti = as->parms[P_VOLUMEID].items)) {
92 volumeId = strtoul(ti->data, NULL, 10);
93 }
94 if (as->parms[P_HEADER].items) {
95 opt->dumpHeader = 1;
96 }
97 if (as->parms[P_SIZEONLY].items) {
98 opt->showSizes = 1;
99 }
100 if (as->parms[P_FIXHEADER].items) {
101 opt->fixHeader = 1;
102 }
103 if (as->parms[P_SAVEINODES].items) {
104 opt->saveInodes = 1;
105 }
106 if (as->parms[P_ORPHANED].items) {
107 opt->showOrphaned = 1;
108 }
109 if (as->parms[P_FILENAMES].items) {
110 opt->dumpFileNames = 1;
111 }
112
113 /* -saveinodes and -sizeOnly override the default mode.
114 * For compatibility with old versions of volinfo, -orphaned
115 * and -filename options imply -vnodes */
116 if (opt->saveInodes || opt->showSizes) {
117 opt->dumpInfo = 0;
118 opt->dumpHeader = 0;
119 opt->dumpVnodes = 0;
120 opt->dumpInodeTimes = 0;
121 opt->showOrphaned = 0;
122 } else if (opt->showOrphaned) {
123 opt->dumpVnodes = 1; /* implied */
124 } else if (opt->dumpFileNames) {
125 opt->dumpVnodes = 1; /* implied */
126 }
127
128 if (opt->saveInodes) {
129 volinfo_AddVnodeHandler(vSmall, volinfo_SaveInode,
130 "Saving all volume files to current directory ...\n");
131 }
132 if (opt->showSizes) {
133 volinfo_AddVnodeHandler(vLarge, volinfo_AddVnodeToSizeTotals, NULL);
134 volinfo_AddVnodeHandler(vSmall, volinfo_AddVnodeToSizeTotals, NULL);
135 }
136 if (opt->dumpVnodes) {
137 volinfo_AddVnodeHandler(vLarge, volinfo_PrintVnode, "\nLarge vnodes (directories)\n");
138 volinfo_AddVnodeHandler(vSmall, volinfo_PrintVnode,
139 "\nSmall vnodes(files, symbolic links)\n");
140 }
141 code = volinfo_ScanPartitions(opt, partNameOrId, volumeId);
142 if (opt) {
143 free(opt);
144 }
145 return code;
146 }
147
148 /**
149 * volinfo program entry
150 */
151 int
152 main(int argc, char **argv)
153 {
154 afs_int32 code;
155 struct cmd_syndesc *ts;
156
157 ts = cmd_CreateSyntax(NULL, VolInfo, NULL, 0,
158 "Dump volume's internal state");
159 cmd_AddParmAtOffset(ts, P_CHECKOUT, "-checkout", CMD_FLAG, CMD_OPTIONAL,
160 "Checkout volumes from running fileserver");
161 cmd_AddParmAtOffset(ts, P_VNODE, "-vnode", CMD_FLAG, CMD_OPTIONAL,
162 "Dump vnode info");
163 cmd_AddParmAtOffset(ts, P_DATE, "-date", CMD_FLAG, CMD_OPTIONAL,
164 "Also dump vnode's mod date");
165 cmd_AddParmAtOffset(ts, P_INODE, "-inode", CMD_FLAG, CMD_OPTIONAL,
166 "Also dump vnode's inode number");
167 cmd_AddParmAtOffset(ts, P_ITIME, "-itime", CMD_FLAG, CMD_OPTIONAL,
168 "Dump special inode's mod times");
169 cmd_AddParmAtOffset(ts, P_PART, "-part", CMD_LIST, CMD_OPTIONAL,
170 "AFS partition name or id (default current partition)");
171 cmd_AddParmAtOffset(ts, P_VOLUMEID, "-volumeid", CMD_LIST, CMD_OPTIONAL,
172 "Volume id");
173 cmd_AddParmAtOffset(ts, P_HEADER, "-header", CMD_FLAG, CMD_OPTIONAL,
174 "Dump volume's header info");
175 cmd_AddParmAtOffset(ts, P_SIZEONLY, "-sizeonly", CMD_FLAG, CMD_OPTIONAL,
176 "Dump volume's size");
177 cmd_AddParmAtOffset(ts, P_FIXHEADER, "-fixheader", CMD_FLAG,
178 CMD_OPTIONAL, "Try to fix header");
179 cmd_AddParmAtOffset(ts, P_SAVEINODES, "-saveinodes", CMD_FLAG,
180 CMD_OPTIONAL, "Try to save all inodes");
181 cmd_AddParmAtOffset(ts, P_ORPHANED, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
182 "List all dir/files without a parent");
183 #if defined(AFS_NAMEI_ENV)
184 cmd_AddParmAtOffset(ts, P_FILENAMES, "-filenames", CMD_FLAG,
185 CMD_OPTIONAL, "Also dump vnode's namei filename");
186 #endif
187
188 /* For compatibility with older versions. */
189 cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly");
190
191 code = cmd_Dispatch(argc, argv);
192 return code;
193 }