From 1a4262253e78aa7a4e8c58006abd3301f71bab89 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Fri, 27 May 2011 18:17:44 -0400 Subject: [PATCH 1/1] volinfo: accept -sizeonly for -sizeOnly For consistency, allow -sizeonly (all lowercase letters) to request the size summary. The old option name, -sizeOnly is available as an alias. Define the command line option parameter positions and use those to set and look up the options. Change-Id: Ie6a780e02bfa35cd5399364bab614b260c391abc Reviewed-on: http://gerrit.openafs.org/4741 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- doc/man-pages/pod8/volinfo.pod | 4 +- src/vol/vol-info.c | 101 ++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 39 deletions(-) diff --git a/doc/man-pages/pod8/volinfo.pod b/doc/man-pages/pod8/volinfo.pod index 1c6e84d..2d57564 100644 --- a/doc/man-pages/pod8/volinfo.pod +++ b/doc/man-pages/pod8/volinfo.pod @@ -9,7 +9,7 @@ volinfo - Produces detailed statistics about AFS volume headers B [B<-online>] [B<-vnode>] [B<-date>] [B<-inode>] [B<-itime>] S<<< [B<-part> >+] >>> - S<<< [B<-volumeid> >+] >>> [B<-header>] [B<-sizeOnly>] + S<<< [B<-volumeid> >+] >>> [B<-header>] [B<-sizeonly>] [B<-fixheader>] [B<-saveinodes>] [B<-orphaned>] [B<-filenames>] [B<-help>] =for html @@ -75,7 +75,7 @@ houses the volume. Displays statistics about the volume header of each volume, in addition to the default output. -=item B<-sizeOnly> +=item B<-sizeonly> Displays a single line of output for each volume, reporting the size of various structures associated with it. The default output is suppressed diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 33f3812..d73a13e 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -49,6 +49,23 @@ static const char *progname = "volinfo"; +/* Command line options */ +typedef enum { + P_ONLINE, + P_VNODE, + P_DATE, + P_INODE, + P_ITIME, + P_PART, + P_VOLUMEID, + P_HEADER, + P_SIZEONLY, + P_FIXHEADER, + P_SAVEINODES, + P_ORPHANED, + P_FILENAMES +} volinfo_parm_t; + /* Modes */ static int DumpInfo = 1; /**< Dump volume information, defualt mode*/ static int DumpHeader = 0; /**< Dump volume header files info */ @@ -414,45 +431,45 @@ handleit(struct cmd_syndesc *as, void *arock) } #endif - if (as->parms[0].items) { /* -online */ + if (as->parms[P_ONLINE].items) { fprintf(stderr, "%s: -online not supported\n", progname); return 1; } - if (as->parms[1].items) { /* -vnode */ + if (as->parms[P_VNODE].items) { DumpVnodes = 1; } - if (as->parms[2].items) { /* -date */ + if (as->parms[P_DATE].items) { DumpDate = 1; } - if (as->parms[3].items) { /* -inode */ + if (as->parms[P_INODE].items) { DumpInodeNumber = 1; } - if (as->parms[4].items) { /* -itime */ + if (as->parms[P_ITIME].items) { InodeTimes = 1; } - if ((ti = as->parms[5].items)) { /* -part */ + if ((ti = as->parms[P_PART].items)) { partNameOrId = ti->data; } - if ((ti = as->parms[6].items)) { /* -volumeid */ + if ((ti = as->parms[P_VOLUMEID].items)) { volumeId = strtoul(ti->data, NULL, 10); } - if (as->parms[7].items) { /* -header */ + if (as->parms[P_HEADER].items) { DumpHeader = 1; } - if (as->parms[8].items) { /* -sizeOnly */ + if (as->parms[P_SIZEONLY].items) { ShowSizes = 1; } - if (as->parms[9].items) { /* -FixHeader */ + if (as->parms[P_FIXHEADER].items) { FixHeader = 1; } - if (as->parms[10].items) { /* -saveinodes */ + if (as->parms[P_SAVEINODES].items) { SaveInodes = 1; } - if (as->parms[11].items) { /* -orphaned */ + if (as->parms[P_ORPHANED].items) { ShowOrphaned = 1; } #if defined(AFS_NAMEI_ENV) - if (as->parms[12].items) { /* -filenames */ + if (as->parms[P_FILENAMES].items) { PrintFileNames = 1; } #endif @@ -829,6 +846,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name) free(vp); } + /** * volinfo program entry */ @@ -838,32 +856,41 @@ main(int argc, char **argv) struct cmd_syndesc *ts; afs_int32 code; - ts = cmd_CreateSyntax(NULL, handleit, NULL, "Dump volume's internal state"); - cmd_AddParm(ts, "-online", CMD_FLAG, CMD_OPTIONAL, - "Get info from running fileserver"); - cmd_AddParm(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode info"); - cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL, - "Also dump vnode's mod date"); - cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL, - "Also dump vnode's inode number"); - cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL, - "Dump special inode's mod times"); - cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, - "AFS partition name or id (default current partition)"); - cmd_AddParm(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id"); - cmd_AddParm(ts, "-header", CMD_FLAG, CMD_OPTIONAL, - "Dump volume's header info"); - cmd_AddParm(ts, "-sizeOnly", CMD_FLAG, CMD_OPTIONAL, - "Dump volume's size"); - cmd_AddParm(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL, - "Try to fix header"); - cmd_AddParm(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL, - "Try to save all inodes"); - cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL, - "List all dir/files without a parent"); + ts = cmd_CreateSyntax(NULL, handleit, NULL, + "Dump volume's internal state"); + cmd_AddParmAtOffset(ts, "-online", CMD_FLAG, CMD_OPTIONAL, + "Get info from running fileserver", P_ONLINE); + cmd_AddParmAtOffset(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL, + "Dump vnode info", P_VNODE); + cmd_AddParmAtOffset(ts, "-date", CMD_FLAG, CMD_OPTIONAL, + "Also dump vnode's mod date", P_DATE); + cmd_AddParmAtOffset(ts, "-inode", CMD_FLAG, CMD_OPTIONAL, + "Also dump vnode's inode number", P_INODE); + cmd_AddParmAtOffset(ts, "-itime", CMD_FLAG, CMD_OPTIONAL, + "Dump special inode's mod times", P_ITIME); + cmd_AddParmAtOffset(ts, "-part", CMD_LIST, CMD_OPTIONAL, + "AFS partition name or id (default current partition)", + P_PART); + cmd_AddParmAtOffset(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id", + P_VOLUMEID); + cmd_AddParmAtOffset(ts, "-header", CMD_FLAG, CMD_OPTIONAL, + "Dump volume's header info", P_HEADER); + cmd_AddParmAtOffset(ts, "-sizeonly", CMD_FLAG, CMD_OPTIONAL, + "Dump volume's size", P_SIZEONLY); + cmd_AddParmAtOffset(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL, + "Try to fix header", P_FIXHEADER); + cmd_AddParmAtOffset(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL, + "Try to save all inodes", P_SAVEINODES); + cmd_AddParmAtOffset(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL, + "List all dir/files without a parent", P_ORPHANED); #if defined(AFS_NAMEI_ENV) - cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's namei filename"); + cmd_AddParmAtOffset(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, + "Also dump vnode's namei filename", P_FILENAMES); #endif + + /* For compatibility with older versions. */ + cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly"); + code = cmd_Dispatch(argc, argv); return code; } -- 1.9.4