From dfaa6598236079478ac77b273aa49cacebca6029 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Fri, 27 May 2011 12:22:34 -0400 Subject: [PATCH] volinfo: accept vice partition id for -part option Accept a partition id for the -part option. For example, -part a is the same as -part /vicepa. Reviewed-on: http://gerrit.openafs.org/4739 Reviewed-by: Jeffrey Altman Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit 8fc3d6dfe196771a38f2bfe7275e90a73f742931) Change-Id: I9a52dc881e6b77526656ca94e4f175241a79551b Reviewed-on: http://gerrit.openafs.org/11257 Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- doc/man-pages/pod8/volinfo.pod | 4 +-- src/vol/vol-info.c | 65 +++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/doc/man-pages/pod8/volinfo.pod b/doc/man-pages/pod8/volinfo.pod index 33a8dc189..0e4bbe81b 100644 --- a/doc/man-pages/pod8/volinfo.pod +++ b/doc/man-pages/pod8/volinfo.pod @@ -54,10 +54,10 @@ associated inode number. When combined with the B<-vnode> flag, displays a change, modification, and access timestamp for each of the large vnode and small vnode tables. -=item B<-part> >+ +=item B<-part> >+ Specifies the partition that houses each volume for which to produce -output. Use the format F>, where I is one or two lowercase +output. Use the format F> or I, where I is one or two lowercase letters. This argument can be omitted if the current working directory is the mount location for an AFS server partition. If it is not the mount location for an AFS server partition, the command produces output for diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 5517283cc..822e44983 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -371,6 +371,46 @@ AttachVolume(struct DiskPartition64 * dp, char *volname, return vp; } +/** + * Convert the partition device number into a partition name. + * + * @param[in] partId partition number, 0 to 254 + * @param[out] partName buffer to hold partition name (e.g. /vicepa) + * @param[in] partNameSize size of partName buffer + * + * @return status + * @retval 0 success + * @retval -1 error, partId is out of range + * @retval -2 error, partition name exceeds partNameSize + */ +static int +GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize) +{ + const int OLD_NUM_DEVICES = 26; /* a..z */ + + if (partId < OLD_NUM_DEVICES) { + if (partNameSize < 8) { + return -2; + } + strlcpy(partName, "/vicep", partNameSize); + partName[6] = partId + 'a'; + partName[7] = '\0'; + return 0; + } + if (partId < VOLMAXPARTS) { + if (partNameSize < 9) { + return -2; + } + strlcpy(partName, "/vicep", partNameSize); + partId -= OLD_NUM_DEVICES; + partName[6] = 'a' + (partId / OLD_NUM_DEVICES); + partName[7] = 'a' + (partId % OLD_NUM_DEVICES); + partName[8] = '\0'; + return 0; + } + return -1; +} + /** * Process command line options and start scanning * @@ -385,7 +425,8 @@ handleit(struct cmd_syndesc *as, void *arock) struct cmd_item *ti; int err = 0; afs_uint32 volumeId = 0; - char *partName = 0; + char *partNameOrId = 0; + char partName[64] = ""; struct DiskPartition64 *partP = NULL; @@ -413,7 +454,7 @@ handleit(struct cmd_syndesc *as, void *arock) InodeTimes = 1; } if ((ti = as->parms[5].items)) { /* -part */ - partName = ti->data; + partNameOrId = ti->data; } if ((ti = as->parms[6].items)) { /* -volumeid */ volumeId = strtoul(ti->data, NULL, 10); @@ -452,6 +493,22 @@ handleit(struct cmd_syndesc *as, void *arock) DumpVnodes = 1; /* implied */ } + /* Allow user to specify partition by name or id. */ + if (partNameOrId) { + afs_uint32 partId = volutil_GetPartitionID(partNameOrId); + if (partId == -1) { + fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n", + progname, partNameOrId); + return 1; + } + if (GetPartitionName(partId, partName, sizeof(partName))) { + fprintf(stderr, + "%s: Could not format '%s' as a partition name.\n", + progname, partNameOrId); + return 1; + } + } + DInit(10); err = VAttachPartitions(); @@ -460,7 +517,7 @@ handleit(struct cmd_syndesc *as, void *arock) progname, err); } - if (partName) { + if (partName[0]) { partP = VGetPartition(partName, 0); if (!partP) { fprintf(stderr, @@ -817,7 +874,7 @@ main(int argc, char **argv) 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 (default current partition)"); + "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"); -- 2.39.5