From 8fc3d6dfe196771a38f2bfe7275e90a73f742931 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. Change-Id: I59d9cb71a49bbfc631c7975a859ebc3e5eccdf1a Reviewed-on: http://gerrit.openafs.org/4739 Reviewed-by: Jeffrey Altman Tested-by: BuildBot Reviewed-by: Derrick Brashear --- 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 e9946565d..1c6e84d7f 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; 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 85b650fd5..33f3812bc 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -348,6 +348,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 * @@ -362,7 +402,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; @@ -390,7 +431,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); @@ -429,6 +470,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(); @@ -437,7 +494,7 @@ handleit(struct cmd_syndesc *as, void *arock) progname, err); } - if (partName) { + if (partName[0]) { partP = VGetPartition(partName, 0); if (!partP) { fprintf(stderr, @@ -792,7 +849,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