]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
volinfo: accept vice partition id for -part option
authorMichael Meffie <mmeffie@sinenomine.net>
Fri, 27 May 2011 16:22:34 +0000 (12:22 -0400)
committerStephan Wiesand <stephan.wiesand@desy.de>
Wed, 13 Aug 2014 18:16:35 +0000 (14:16 -0400)
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 <jaltman@openafs.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit 8fc3d6dfe196771a38f2bfe7275e90a73f742931)

Change-Id: I9a52dc881e6b77526656ca94e4f175241a79551b
Reviewed-on: http://gerrit.openafs.org/11257
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
doc/man-pages/pod8/volinfo.pod
src/vol/vol-info.c

index 33a8dc189d2e0e00546b1140e87dc8fc55996738..0e4bbe81b50bd4c56526551a53f0a8df952b988d 100644 (file)
@@ -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> <I<partition name>>+
+=item B<-part> <I<partition name or id>>+
 
 Specifies the partition that houses each volume for which to produce
-output. Use the format F</vicepI<xx>>, where I<xx> is one or two lowercase
+output. Use the format F</vicepI<xx>> or I<xx>, where I<xx> 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
index 5517283cc80811066a51b0b6cbc9627c20b73f51..822e449839daa0dd6a3e2d6946d56d35e7d35f28 100644 (file)
@@ -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");