2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <afs/afsint.h>
17 #include <rx/rx_queue.h>
21 #include "vnode.h" /* for vSmall, vLarge */
25 #include "AFS_component_version_number.c"
28 static const char *progname
= "volinfo";
30 /* Command line options */
48 * Process command line options and start scanning
50 * @param[in] as command syntax object
51 * @param[in] arock opaque object; not used
56 VolInfo(struct cmd_syndesc
*as
, void *arock
)
60 VolumeId volumeId
= 0;
61 char *partNameOrId
= NULL
;
62 struct VolInfoOpt
*opt
;
64 code
= volinfo_Init(progname
);
68 code
= volinfo_Options(&opt
);
73 if (as
->parms
[P_CHECKOUT
].items
) {
76 if (as
->parms
[P_VNODE
].items
) {
79 if (as
->parms
[P_DATE
].items
) {
82 if (as
->parms
[P_INODE
].items
) {
83 opt
->dumpInodeNumber
= 1;
85 if (as
->parms
[P_ITIME
].items
) {
86 opt
->dumpInodeTimes
= 1;
88 if ((ti
= as
->parms
[P_PART
].items
)) {
89 partNameOrId
= ti
->data
;
91 if ((ti
= as
->parms
[P_VOLUMEID
].items
)) {
92 volumeId
= strtoul(ti
->data
, NULL
, 10);
94 if (as
->parms
[P_HEADER
].items
) {
97 if (as
->parms
[P_SIZEONLY
].items
) {
100 if (as
->parms
[P_FIXHEADER
].items
) {
103 if (as
->parms
[P_SAVEINODES
].items
) {
106 if (as
->parms
[P_ORPHANED
].items
) {
107 opt
->showOrphaned
= 1;
109 if (as
->parms
[P_FILENAMES
].items
) {
110 opt
->dumpFileNames
= 1;
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
) {
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 */
128 if (opt
->saveInodes
) {
129 volinfo_AddVnodeHandler(vSmall
, volinfo_SaveInode
,
130 "Saving all volume files to current directory ...\n");
132 if (opt
->showSizes
) {
133 volinfo_AddVnodeHandler(vLarge
, volinfo_AddVnodeToSizeTotals
, NULL
);
134 volinfo_AddVnodeHandler(vSmall
, volinfo_AddVnodeToSizeTotals
, NULL
);
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");
141 code
= volinfo_ScanPartitions(opt
, partNameOrId
, volumeId
);
149 * volinfo program entry
152 main(int argc
, char **argv
)
155 struct cmd_syndesc
*ts
;
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
,
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
,
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");
188 /* For compatibility with older versions. */
189 cmd_AddParmAlias(ts
, P_SIZEONLY
, "-sizeOnly");
191 code
= cmd_Dispatch(argc
, argv
);