2 * vol_id - udev callout to read filesystem label and uuid
4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <sys/ioctl.h>
32 #include "../../udev_utils.h"
33 #include "../../logging.h"
34 #include "volume_id/volume_id.h"
35 #include "volume_id/dasd.h"
37 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
40 void log_message(int priority, const char *format, ...)
43 static int udev_log = -1;
48 value = getenv("UDEV_LOG");
50 udev_log = log_priority(value);
55 if (priority > udev_log)
58 va_start(args, format);
59 vsyslog(priority, format, args);
64 static void set_str(char *to, const unsigned char *from, int count)
69 len = strnlen(from, count);
70 while (isspace(from[len-1]))
74 while (isspace(from[i]) && (i < len))
93 int main(int argc, char *argv[])
95 const char help[] = "usage: vol_id [--export|-t|-l|-u] <device>\n"
97 " -t filesystem type\n"
98 " -l filesystem label\n"
99 " -u filesystem uuid\n"
106 } print = PRINT_EXPORT;
107 struct volume_id *vid = NULL;
108 static char name[VOLUME_ID_LABEL_SIZE];
110 unsigned long long size;
111 const char *node = NULL;
114 logging_init("vol_id");
116 for (i = 1 ; i < argc; i++) {
119 if (strcmp(arg, "--export") == 0) {
120 print = PRINT_EXPORT;
121 } else if (strcmp(arg, "-t") == 0) {
123 } else if (strcmp(arg, "-l") == 0) {
125 } else if (strcmp(arg, "-u") == 0) {
131 err("no node specified");
132 fprintf(stderr, help);
137 vid = volume_id_open_node(node);
139 fprintf(stderr, "error open volume\n");
144 if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
147 if (volume_id_probe_all(vid, 0, size) == 0)
150 if (volume_id_probe_dasd(vid) == 0)
153 fprintf(stderr, "unknown volume type\n");
158 set_str(name, vid->label, sizeof(vid->label));
162 printf("ID_FS_USAGE=%s\n", vid->usage);
163 printf("ID_FS_TYPE=%s\n", vid->type);
164 printf("ID_FS_VERSION=%s\n", vid->type_version);
165 printf("ID_FS_UUID=%s\n", vid->uuid);
166 printf("ID_FS_LABEL=%s\n", vid->label);
167 printf("ID_FS_LABEL_SAFE=%s\n", name);
170 printf("%s\n", vid->type);
173 if (name[0] == '\0' ||
174 (vid->usage_id != VOLUME_ID_FILESYSTEM && vid->usage_id != VOLUME_ID_DISKLABEL)) {
178 printf("%s\n", name);
181 if (vid->uuid[0] == '\0' || vid->usage_id != VOLUME_ID_FILESYSTEM) {
185 printf("%s\n", vid->uuid);
191 volume_id_close(vid);