1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

vol_id: use long options

This commit is contained in:
Kay Sievers 2007-05-03 11:00:02 +02:00
parent 4c13270a77
commit 4a86b682ab
3 changed files with 126 additions and 66 deletions

View File

@ -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\-t\fR
\fB\-\-type\fR
.RS 4
print the filesystem type
Print the filesystem type.
.RE
.PP
\fB\-l\fR
\fB\-\-label\fR
.RS 4
print the safe version of volume label suitable for use as filename. Use
\fB\-L\fR
to print literal label
Print the safe version of volume label suitable for use as filename.
.RE
.PP
\fB\-u\fR
\fB\-\-label\-raw\fR
.RS 4
print the uuid of a volume
Print the raw volume label.
.RE
.PP
\fB\-L\fR
\fB\-\-uuid\fR
.RS 4
print raw volume label
Print the uuid of a volume.
.RE
.PP
\fB\-\-skip\-raid\fR
.RS 4
Skip detection of raid metadata.
.RE
.PP
\fB\-\-probe\-all\fR
.RS 4
Probe for all types and print all matches.
.RE
.PP
\fB\-\-help\fR
.RS 4
Print usage.
.RE
.SH "ENVIRONMENT"
.PP

View 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;
} else
node = arg;
default:
retval = 1;
goto exit;
}
}
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;

View File

@ -26,9 +26,13 @@
<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>
@ -46,37 +50,55 @@
<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>