Signed-off-by: Kay Sievers <kay.sievers@suse.de>
case '/':
case ' ':
to[j++] = '_';
case '/':
case ' ':
to[j++] = '_';
default:
to[j++] = from[i];
}
default:
to[j++] = from[i];
}
-# 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.
#
#
# 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.
#
VOLUME_ID_BASE=volume_id
include $(VOLUME_ID_BASE)/Makefile.inc
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)
HEADERS = $(VOLUME_ID_HEADERS)
$(OBJS): $(HEADERS)
-
-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.
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.
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:
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:
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
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
- [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
-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>
Kay Sievers <kay.sievers@vrfy.org>
+++ /dev/null
-# 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"
-
+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[])
{
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";
" -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;
struct volume_id *vid = NULL;
- const char *device;
- char print = 'a';
static char name[VOLUME_ID_LABEL_SIZE];
static char name[VOLUME_ID_LABEL_SIZE];
+ const char *node = NULL;
+ int rc = 0;
logging_init("udev_volume_id");
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);
- printf("error open volume\n");
+ fprintf(stderr, "error open volume\n");
+ rc = 2;
if (volume_id_probe_dasd(vid) == 0)
goto print;
if (volume_id_probe_dasd(vid) == 0)
goto print;
- printf("unknown volume type\n");
+ fprintf(stderr, "unknown volume type\n");
+ rc = 3;
- 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));
+ 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;
printf("%s\n", vid->type);
break;
if (name[0] == '\0' ||
(vid->usage_id != VOLUME_ID_FILESYSTEM && vid->usage_id != VOLUME_ID_DISKLABEL)) {
if (name[0] == '\0' ||
(vid->usage_id != VOLUME_ID_FILESYSTEM && vid->usage_id != VOLUME_ID_DISKLABEL)) {
goto exit;
}
printf("%s\n", name);
break;
goto exit;
}
printf("%s\n", name);
break;
if (vid->uuid[0] == '\0' || vid->usage_id != VOLUME_ID_FILESYSTEM) {
if (vid->uuid[0] == '\0' || vid->usage_id != VOLUME_ID_FILESYSTEM) {
goto exit;
}
printf("%s\n", vid->uuid);
break;
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);
exit:
if (vid != NULL)
volume_id_close(vid);
logging_close();
exit:
if (vid != NULL)
volume_id_close(vid);
logging_close();