chiark / gitweb /
vol_id: use long options
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 3 May 2007 09:00:02 +0000 (11:00 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 3 May 2007 09:00:02 +0000 (11:00 +0200)
extras/volume_id/vol_id.8
extras/volume_id/vol_id.c
extras/volume_id/vol_id.xml

index bb248a4..7594253 100644 (file)
 vol_id \- probe filesystem type and read label and uuid
 .SH "SYNOPSIS"
 .HP 7
-\fBvol_id\fR [\fB\-\-export\fR] [\fB\-t\fR] [\fB\-l\fR] [\fB\-u\fR] [\fIdevice\fR]
+\fBvol_id\fR [\fB\-\-export\fR] [\fB\-\-type\fR] [\fB\-\-label\fR] [\fB\-\-label\-raw\fR] [\fB\-\-uuid\fR] [\fB\-\-skip\-raid\fR] [\fB\-\-probe\-all\fR] [\fB\-\-help\fR] [\fIdevice\fR]
 .SH "DESCRIPTION"
 .PP
 \fBvol_id\fR
-is usually called from a udev rule, to provide udev with the filesystem type, the label and the uuid of a volume.
-\fBvol_id\fR
-supports all common filesystem formats and detects various raid setups to prevent the recognition of raid members as a volume with a filesystem.
+is usually called from a udev rule, to provide udev with the filesystem type, the label and the uuid of a volume. It supports most of the common filesystem formats and detects various raid setups to prevent the recognition of raid members as a volume with a filesystem.
 .SH "OPTIONS"
 .PP
 \fB\-\-export\fR
 .RS 4
-print all values in key/value format to import them into the environment.
+Print all values in key/value format to import them into the environment.
+.RE
+.PP
+\fB\-\-type\fR
+.RS 4
+Print the filesystem type.
+.RE
+.PP
+\fB\-\-label\fR
+.RS 4
+Print the safe version of volume label suitable for use as filename.
+.RE
+.PP
+\fB\-\-label\-raw\fR
+.RS 4
+Print the raw volume label.
 .RE
 .PP
-\fB\-t\fR
+\fB\-\-uuid\fR
 .RS 4
-print the filesystem type
+Print the uuid of a volume.
 .RE
 .PP
-\fB\-l\fR
+\fB\-\-skip\-raid\fR
 .RS 4
-print the safe version of volume label suitable for use as filename. Use
-\fB\-L\fR
-to print literal label
+Skip detection of raid metadata.
 .RE
 .PP
-\fB\-u\fR
+\fB\-\-probe\-all\fR
 .RS 4
-print the uuid of a volume
+Probe for all types and print all matches.
 .RE
 .PP
-\fB\-L\fR
+\fB\-\-help\fR
 .RS 4
-print raw volume label
+Print usage.
 .RE
 .SH "ENVIRONMENT"
 .PP
index 0427d70..f696760 100644 (file)
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <pwd.h>
 #include <grp.h>
+#include <getopt.h>
 #include <sys/ioctl.h>
 
 #include "../../udev.h"
@@ -111,30 +112,32 @@ static void set_str(char *to, const char *from, size_t count)
 
 int main(int argc, char *argv[])
 {
-       const char help[] = "Usage: vol_id [options] <device>\n"
-                           " --export        export key/value pairs\n"
-                           "  -t             filesystem type\n"
-                           "  -l             filesystem label\n"
-                           "  -u             filesystem uuid\n"
-                           "  -L             raw label\n"
-                           " --skip-raid     don't probe for raid\n"
-                           " --probe-all     find possibly conflicting signatures\n"
-                           " --help\n"
-                           "\n";
+       static const struct option options[] = {
+               { "label", 0, NULL, 'l' },
+               { "label-raw", 0, NULL, 'L' },
+               { "uuid", 0, NULL, 'u' },
+               { "type", 0, NULL, 't' },
+               { "export", 0, NULL, 'x' },
+               { "skip-raid", 0, NULL, 's' },
+               { "probe-all", 0, NULL, 'a' },
+               { "help", 0, NULL, 'h' },
+               {}
+       };
+
        enum print_type {
                PRINT_EXPORT,
                PRINT_TYPE,
                PRINT_LABEL,
                PRINT_UUID,
-               PRINT_RAW_LABEL,
+               PRINT_LABEL_RAW,
        } print = PRINT_EXPORT;
+
        struct volume_id *vid = NULL;
        static char name[VOLUME_ID_LABEL_SIZE];
-       int i;
        uint64_t size;
        int skip_raid = 0;
        int probe_all = 0;
-       const char *node = NULL;
+       const char *node;
        struct passwd *pw;
        int retval;
        int rc = 0;
@@ -144,32 +147,56 @@ int main(int argc, char *argv[])
        /* hook in our debug into libvolume_id */
        volume_id_log_fn = vid_log;
 
-       for (i = 1 ; i < argc; i++) {
-               char *arg = argv[i];
+       while (1) {
+               int option;
 
-               if (strcmp(arg, "--export") == 0) {
-                       print = PRINT_EXPORT;
-               } else if (strcmp(arg, "-t") == 0) {
-                       print = PRINT_TYPE;
-               } else if (strcmp(arg, "-l") == 0) {
+               option = getopt_long(argc, argv, "lLutxsah", options, NULL);
+               if (option == -1)
+                       break;
+
+               switch (option) {
+               case 'l':
                        print = PRINT_LABEL;
-               } else if (strcmp(arg, "-u") == 0) {
+                       break;
+               case 'L':
+                       print = PRINT_LABEL_RAW;
+                       break;
+               case 'u':
                        print = PRINT_UUID;
-               } else if (strcmp(arg, "-L") == 0) {
-                       print = PRINT_RAW_LABEL;
-               } else if (strcmp(arg, "--skip-raid") == 0) {
+                       break;
+               case 't':
+                       print = PRINT_TYPE;
+                       break;
+               case 'x':
+                       print = PRINT_EXPORT;
+                       break;
+               case 's':
                        skip_raid = 1;
-               } else if (strcmp(arg, "--probe-all") == 0) {
+                       break;
+               case 'a':
                        probe_all = 1;
-               } else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
-                       printf(help);
+                       break;
+               case 'h':
+                       printf("Usage: vol_id [options] <device>\n"
+                           " --export        export key/value pairs\n"
+                           " --type          filesystem type\n"
+                           " --label         filesystem label\n"
+                           " --label-raw     raw label\n"
+                           " --uuid          filesystem uuid\n"
+                           " --skip-raid     don't probe for raid\n"
+                           " --probe-all     find possibly conflicting signatures\n"
+                           " --help\n\n");
+                       goto exit;
+               default:
+                       retval = 1;
                        goto exit;
-               } else
-                       node = arg;
+               }
        }
+
+       node = argv[optind];
        if (!node) {
-               err("no node specified");
-               fprintf(stderr, help);
+               err("no device");
+               fprintf(stderr, "no device\n");
                rc = 1;
                goto exit;
        }
@@ -311,7 +338,7 @@ int main(int argc, char *argv[])
                }
                printf("%s\n", vid->uuid);
                break;
-       case PRINT_RAW_LABEL:
+       case PRINT_LABEL_RAW:
                if (vid->label[0] == '\0' || vid->usage_id == VOLUME_ID_RAID) {
                        rc = 3;
                        goto exit;
index 2b26b3b..6d0a6c6 100644 (file)
         <cmdsynopsis>
           <command>vol_id</command>
           <arg><option>--export</option></arg>
-          <arg><option>-t</option></arg>
-          <arg><option>-l</option></arg>
-          <arg><option>-u</option></arg>
+          <arg><option>--type</option></arg>
+          <arg><option>--label</option></arg>
+          <arg><option>--label-raw</option></arg>
+          <arg><option>--uuid</option></arg>
+          <arg><option>--skip-raid</option></arg>
+          <arg><option>--probe-all</option></arg>
+          <arg><option>--help</option></arg>
           <arg><replaceable>device</replaceable></arg>
         </cmdsynopsis>
       </refsynopsisdiv>
@@ -36,8 +40,8 @@
       <refsect1><title>DESCRIPTION</title>
         <para><command>vol_id</command> is usually called from a udev rule, to
         provide udev with the filesystem type, the label and the uuid of a
-        volume. <command>vol_id</command> supports all common filesystem formats
-        and detects various raid setups to prevent the recognition of raid members
+        volume. It supports most of the common filesystem formats and detects
+        various raid setups to prevent the recognition of raid members
         as a volume with a filesystem.</para>
       </refsect1>
 
           <varlistentry>
             <term><option>--export</option></term>
             <listitem>
-              <para>print all values in key/value format to import them into the
+              <para>Print all values in key/value format to import them into the
               environment.</para>
             </listitem>
           </varlistentry>
           <varlistentry>
-            <term><option>-t</option></term>
+            <term><option>--type</option></term>
             <listitem>
-              <para>print the filesystem type</para>
+              <para>Print the filesystem type.</para>
             </listitem>
           </varlistentry>
           <varlistentry>
-            <term><option>-l</option></term>
+            <term><option>--label</option></term>
             <listitem>
-             <para>
-               print the safe version of volume label suitable for
-               use as filename. Use <option>-L</option> to print literal label
-             </para>
+              <para>
+                Print the safe version of volume label suitable for
+                use as filename.
+              </para>
             </listitem>
           </varlistentry>
           <varlistentry>
-            <term><option>-u</option></term>
+            <term><option>--label-raw</option></term>
             <listitem>
-              <para>print the uuid of a volume</para>
+              <para>
+                Print the raw volume label.
+              </para>
             </listitem>
           </varlistentry>
           <varlistentry>
-            <term><option>-L</option></term>
+            <term><option>--uuid</option></term>
             <listitem>
-             <para>
-               print raw volume label
-             </para>
+              <para>Print the uuid of a volume.</para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>--skip-raid</option></term>
+            <listitem>
+              <para>Skip detection of raid metadata.</para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>--probe-all</option></term>
+            <listitem>
+              <para>Probe for all types and print all matches.</para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>--help</option></term>
+            <listitem>
+              <para>Print usage.</para>
             </listitem>
           </varlistentry>
         </variablelist>