From 4a86b682ab3f0473a24ef66d56db100eb592a9bb Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 3 May 2007 11:00:02 +0200 Subject: [PATCH] vol_id: use long options --- extras/volume_id/vol_id.8 | 41 +++++++++++------ extras/volume_id/vol_id.c | 91 ++++++++++++++++++++++++------------- extras/volume_id/vol_id.xml | 60 ++++++++++++++++-------- 3 files changed, 126 insertions(+), 66 deletions(-) diff --git a/extras/volume_id/vol_id.8 b/extras/volume_id/vol_id.8 index bb248a45..75942536 100644 --- a/extras/volume_id/vol_id.8 +++ b/extras/volume_id/vol_id.8 @@ -14,40 +14,51 @@ 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 diff --git a/extras/volume_id/vol_id.c b/extras/volume_id/vol_id.c index 0427d70d..f6967603 100644 --- a/extras/volume_id/vol_id.c +++ b/extras/volume_id/vol_id.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #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] \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] \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; diff --git a/extras/volume_id/vol_id.xml b/extras/volume_id/vol_id.xml index 2b26b3bd..6d0a6c69 100644 --- a/extras/volume_id/vol_id.xml +++ b/extras/volume_id/vol_id.xml @@ -26,9 +26,13 @@ vol_id - - - + + + + + + + device @@ -36,8 +40,8 @@ DESCRIPTION vol_id is usually called from a udev rule, to provide udev with the filesystem type, the label and the uuid of a - volume. vol_id 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. @@ -46,37 +50,55 @@ - print all values in key/value format to import them into the + Print all values in key/value format to import them into the environment. - + - print the filesystem type + Print the filesystem type. - + - - print the safe version of volume label suitable for - use as filename. Use to print literal label - + + Print the safe version of volume label suitable for + use as filename. + - + - print the uuid of a volume + + Print the raw volume label. + - + - - print raw volume label - + Print the uuid of a volume. + + + + + + Skip detection of raid metadata. + + + + + + Probe for all types and print all matches. + + + + + + Print usage. -- 2.39.5