diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-06-26 01:54:47 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-06-26 01:54:47 +0200 |
commit | 208f6aba21199ff4f93002eeb948d564f76843e6 (patch) | |
tree | 64e6c47539c47575ee6de824aa4e2fb08cfd7ae9 /extras | |
parent | 670e470543e02937979e1c879d97f474d5b6fbd1 (diff) |
rename udev_volume_id to vol_id and add --export option
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/ata_id/ata_id.c | 1 | ||||
-rw-r--r-- | extras/volume_id/Makefile | 8 | ||||
-rw-r--r-- | extras/volume_id/README | 68 | ||||
-rw-r--r-- | extras/volume_id/s390-dasd.rules | 7 | ||||
-rw-r--r-- | extras/volume_id/vol_id.c (renamed from extras/volume_id/udev_volume_id.c) | 154 |
5 files changed, 131 insertions, 107 deletions
diff --git a/extras/ata_id/ata_id.c b/extras/ata_id/ata_id.c index e26cb6bd2d..59e2b3987b 100644 --- a/extras/ata_id/ata_id.c +++ b/extras/ata_id/ata_id.c @@ -81,6 +81,7 @@ static void set_str(char *to, const unsigned char *from, int count) case '/': case ' ': to[j++] = '_'; + break; default: to[j++] = from[i]; } diff --git a/extras/volume_id/Makefile b/extras/volume_id/Makefile index 56fdf278b9..eca9cfdbd4 100644 --- a/extras/volume_id/Makefile +++ b/extras/volume_id/Makefile @@ -1,13 +1,13 @@ -# Makefile for udev_volume_id +# Makefile for volume_id # -# Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> +# Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # -PROG = udev_volume_id +PROG = vol_id all: $(PROG) @@ -33,7 +33,7 @@ override CFLAGS+=-D_FILE_OFFSET_BITS=64 VOLUME_ID_BASE=volume_id include $(VOLUME_ID_BASE)/Makefile.inc -OBJS = udev_volume_id.o $(VOLUME_ID_OBJS) ../../udev.a +OBJS = vol_id.o $(VOLUME_ID_OBJS) ../../udev.a HEADERS = $(VOLUME_ID_HEADERS) $(OBJS): $(HEADERS) diff --git a/extras/volume_id/README b/extras/volume_id/README index d570615e10..a7635ff612 100644 --- a/extras/volume_id/README +++ b/extras/volume_id/README @@ -1,43 +1,73 @@ - -udev_volume_id - partition, filesystem, disklabel reader +vol_id - partition, filesystem, disklabel reader This program is normally called from a udev rule, to provide udev with the name, uuid or the filesystem type of a partition to name a device node. -udev_volume_id opens the blockdevice node specified at the commandline. -The following commandline switches are supported to specify what udev_volume_id -should print to stdout: +vol_id opens the blockdevice node specified at the commandline. +The following commandline switches are supported to specify what vol_id +should print: - no option prints all values - -h prints help text - -l prints the label of the partition - -u prints the uuid of the partition + --export prints all values + -h prints help text + -l prints the label of the partition + -u prints the uuid of the partition -udev_volume_id will only return successful if the string asked for, is not +vol_id will only return successful if the string asked for, is not empty. All trailing whitespace will be removed, spaces replaced by underscore and slashes ignored. +fstype probe label uuid fsversion +---------------------------------------------------- +ext * * * * +reiserfs jr/3.5/3.6/4 * * * * +fat (12, 16, 32) * * * * +ntfs * * * * +jfs * * * - +xfs * * * - +hfs (plus, wrapped) * * * - +udf * * - - +iso9660 * * n/a - +ufs * - - - +linux swap * * * * +LVM 1 * - - - +LVM 2 * - - * +linux raid * - * * +cramfs * * - - +sysv * * - * +luks * - * - +hpfs * - - - +romfs * +minix * +dasd * +highpoint * +isw_raid * +lsi_raid * +nvidia_raid * +promise_raid * +silicon_raid * +via_raid * +mac partitons * +msdos partitions * + + The following rule will create a symlink named with the label string: - KERNEL="[hs]d*", PROGRAM="/sbin/udev_volume_id -l %N", SYMLINK="%c" + KERNEL=="[hs]d*", PROGRAM=="/sbin/vol_id -l %N", SYMLINK+="%c" -If no label is found udev_volume_id exits with nonzero and the rule will be +If no label is found vol_id exits with nonzero and the rule will be ignored. To give it a try, you may call it on the commandline: - - [root@pim udev.kay]# extras/volume_id/udev_volume_id /dev/hda3 + [root@pim udev.kay]# extras/volume_id/vol_id /dev/hda3 T:ext3 L:Music Store N:Music_Store U:d2da42b5-bbd9-44eb-a72c-cc4542fcb71e - [root@pim udev.kay]# extras/volume_id/udev_volume_id -l /dev/hda3 + [root@pim udev.kay]# extras/volume_id/vol_id -l /dev/hda3 Music_Store - [root@pim udev.kay]# extras/volume_id/udev_volume_id -t /dev/hda3 + [root@pim udev.kay]# extras/volume_id/vol_id -t /dev/hda3 swap -Please send any comment/questions/concerns to me or: - linux-hotplug-devel@lists.sourceforge.net - +Any comment/questions/concerns to me: Kay Sievers <kay.sievers@vrfy.org> diff --git a/extras/volume_id/s390-dasd.rules b/extras/volume_id/s390-dasd.rules deleted file mode 100644 index a870d87e04..0000000000 --- a/extras/volume_id/s390-dasd.rules +++ /dev/null @@ -1,7 +0,0 @@ -# s390 block devices named by disk label -KERNEL="dasd*[a-z]", PROGRAM="/sbin/udev_volume_id -d -l" RESULT="[0-9A-Z]*", SYMLINK="dasd/%c/disc dasd/%b/disc" -KERNEL="dasd*[0-9]", PROGRAM="/sbin/udev_volume_id -d -l" RESULT="[0-9A-Z]*", SYMLINK="dasd/%c/part%n dasd/%b/part%n" -KERNEL="dasd*[a-z]", SYMLINK="dasd/%b/disc" -KERNEL="dasd*[0-9]", SYMLINK="dasd/%b/part%n" -KERNEL="dcssblk*", NAME="%k", SYMLINK="dcssblk/%b" - diff --git a/extras/volume_id/udev_volume_id.c b/extras/volume_id/vol_id.c index 7c6fc4050d..3048fd8062 100644 --- a/extras/volume_id/udev_volume_id.c +++ b/extras/volume_id/vol_id.c @@ -64,60 +64,83 @@ void log_message(int priority, const char *format, ...) } #endif -extern int optind; +static void set_str(char *to, const unsigned char *from, int count) +{ + int i, j; + int len; + + len = strnlen(from, count); + while (isspace(from[len-1])) + len--; + + i = 0; + while (isspace(from[i]) && (i < len)) + i++; + + j = 0; + while (i < len) { + switch(from[i]) { + case '/': + break; + case ' ': + to[j++] = '_'; + break; + default: + to[j++] = from[i]; + } + i++; + } + to[j] = '\0'; +} int main(int argc, char *argv[]) { - const char help[] = "usage: udev_volume_id [-t|-l|-u] <device>\n" + const char help[] = "usage: udev_volume_id [--export|-t|-l|-u] <device>\n" + " --export\n" " -t filesystem type\n" " -l filesystem label\n" " -u filesystem uuid\n" "\n"; - static const char short_options[] = "htlu"; + enum print_type { + PRINT_EXPORT, + PRINT_TYPE, + PRINT_LABEL, + PRINT_UUID, + } print = PRINT_EXPORT; struct volume_id *vid = NULL; - const char *device; - char print = 'a'; static char name[VOLUME_ID_LABEL_SIZE]; - int len, i, j; + int i; unsigned long long size; - int rc = 1; + const char *node = NULL; + int rc = 0; logging_init("udev_volume_id"); - while (1) { - int option; - - option = getopt(argc, argv, short_options); - if (option == -1) - break; - - switch (option) { - case 't': - print = 't'; - continue; - case 'l': - print = 'l'; - continue; - case 'u': - print = 'u'; - continue; - case 'h': - case '?': - default: - printf(help); - exit(1); - } + for (i = 1 ; i < argc; i++) { + char *arg = argv[i]; + + if (strcmp(arg, "--export") == 0) { + print = PRINT_EXPORT; + } else if (strcmp(arg, "-t") == 0) { + print = PRINT_TYPE; + } else if (strcmp(arg, "-l") == 0) { + print = PRINT_LABEL; + } else if (strcmp(arg, "-u") == 0) { + print = PRINT_UUID; + } else + node = arg; } - - device = argv[optind]; - if (device == NULL) { - printf(help); - exit(1); + if (!node) { + err("no node specified"); + fprintf(stderr, help); + rc = 1; + goto exit; } - vid = volume_id_open_node(device); + vid = volume_id_open_node(node); if (vid == NULL) { - printf("error open volume\n"); + fprintf(stderr, "error open volume\n"); + rc = 2; goto exit; } @@ -130,69 +153,46 @@ int main(int argc, char *argv[]) if (volume_id_probe_dasd(vid) == 0) goto print; - printf("unknown volume type\n"); + fprintf(stderr, "unknown volume type\n"); + rc = 3; goto exit; - print: - len = strnlen(vid->label, VOLUME_ID_LABEL_SIZE); - - /* remove trailing spaces */ - while (len > 0 && isspace(vid->label[len-1])) - len--; - name[len] = '\0'; - - /* substitute chars */ - i = 0; - j = 0; - while (j < len) { - switch(vid->label[j]) { - case '/' : - break; - case ' ' : - name[i++] = '_'; - break; - default : - name[i++] = vid->label[j]; - } - j++; - } - name[i] = '\0'; + set_str(name, vid->label, sizeof(vid->label)); switch (print) { - case 't': + case PRINT_EXPORT: + printf("ID_FS_USAGE=%s\n", vid->usage); + printf("ID_FS_TYPE=%s\n", vid->type); + printf("ID_FS_VERSION=%s\n", vid->type_version); + printf("ID_FS_UUID=%s\n", vid->uuid); + printf("ID_FS_LABEL=%s\n", vid->label); + printf("ID_FS_LABEL_SAFE=%s\n", name); + break; + case PRINT_TYPE: printf("%s\n", vid->type); break; - case 'l': + case PRINT_LABEL: if (name[0] == '\0' || (vid->usage_id != VOLUME_ID_FILESYSTEM && vid->usage_id != VOLUME_ID_DISKLABEL)) { - rc = 2; + rc = 3; goto exit; } printf("%s\n", name); break; - case 'u': + case PRINT_UUID: if (vid->uuid[0] == '\0' || vid->usage_id != VOLUME_ID_FILESYSTEM) { - rc = 2; + rc = 4; goto exit; } printf("%s\n", vid->uuid); break; - case 'a': - printf("F:%s\n", vid->usage); - printf("T:%s\n", vid->type); - printf("V:%s\n", vid->type_version); - printf("L:%s\n", vid->label); - printf("N:%s\n", name); - printf("U:%s\n", vid->uuid); } - rc = 0; exit: if (vid != NULL) volume_id_close(vid); logging_close(); - - exit(rc); + return rc; } |