2 * udev_volume_id - udev callout to read filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * sample udev rule for creation of a symlink with the filsystem uuid:
7 * KERNEL="sd*", PROGRAM="/sbin/udev_volume_id -M%M -m%m -u", SYMLINK="%c"
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "volume_id.h"
30 int main(int argc, char *argv[])
32 struct volume_id *vid;
33 const char help[] = "usage: udev_volume_id -m<minor> -M<major> [-t|-l|-u]\n";
37 static const char short_options[] = "M:m:htlu";
44 option = getopt(argc, argv, short_options);
50 major = (int) strtoul(optarg, &tail, 10);
51 if (tail[0] != '\0') {
52 printf("invalid major\n");
57 minor = (int) strtoul(optarg, &tail, 10);
58 if (tail[0] != '\0') {
59 printf("invalid minor\n");
80 if (major == -1 || minor == -1) {
85 vid = volume_id_open_dev_t(makedev(major, minor));
87 printf("error open volume\n");
91 rc = volume_id_probe(vid, ALL);
93 printf("error probing volume\n");
99 printf("%s\n", vid->fs_name);
102 if (vid->label_string[0] == '\0')
104 printf("%s\n", vid->label_string);
107 if (vid->uuid_string[0] == '\0')
109 printf("%s\n", vid->uuid_string);
112 printf("T:%s\n", vid->fs_name);
113 printf("L:%s\n", vid->label_string);
114 printf("U:%s\n", vid->uuid_string);
117 volume_id_close(vid);