2 * blkid.c - User command-line interface for libblkid
4 * Copyright (C) 2001 Andreas Dilger
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
16 #include <sys/types.h>
22 #define OUTPUT_FULL (1 << 0)
23 #define OUTPUT_VALUE_ONLY (1 << 1)
24 #define OUTPUT_DEVICE_ONLY (1 << 2)
25 #define OUTPUT_PRETTY_LIST (1 << 3) /* deprecated */
26 #define OUTPUT_UDEV_LIST (1 << 4) /* deprecated */
27 #define OUTPUT_EXPORT_LIST (1 << 5)
28 #define OUTPUT_JSON (1 << 6)
30 #define BLKID_EXIT_NOTFOUND 2 /* token or device not found */
31 #define BLKID_EXIT_OTHER 4 /* bad usage or other error */
32 #define BLKID_EXIT_AMBIVAL 8 /* ambivalent low-level probing detected */
36 #include "ismounted.h"
39 #define OPTUTILS_EXIT_CODE BLKID_EXIT_OTHER /* exclusive_option() */
41 #define CLOSE_EXIT_CODE BLKID_EXIT_OTHER /* close_stdout() */
42 #include "closestream.h"
47 #define XALLOC_EXIT_CODE BLKID_EXIT_OTHER /* x.*alloc(), xstrndup() */
53 struct blkid_control
{
58 struct ul_jsonwrt
*json_fmt
;
64 lowprobe_superblocks
:1,
70 static void __attribute__((__noreturn__
)) usage(void)
74 fputs(USAGE_HEADER
, out
);
75 fprintf(out
, _( " %s --label <label> | --uuid <uuid>\n\n"), program_invocation_short_name
);
76 fprintf(out
, _( " %s [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] \n"
77 " [--match-token <token>] [<dev> ...]\n\n"), program_invocation_short_name
);
78 fprintf(out
, _( " %s -p [--match-tag <tag>] [--offset <offset>] [--size <size>] \n"
79 " [--output <format>] <dev> ...\n\n"), program_invocation_short_name
);
80 fprintf(out
, _( " %s -i [--match-tag <tag>] [--output <format>] <dev> ...\n"), program_invocation_short_name
);
81 fputs(USAGE_OPTIONS
, out
);
82 fputs(_( " -c, --cache-file <file> read from <file> instead of reading from the default\n"
83 " cache file (-c /dev/null means no cache)\n"), out
);
84 fputs(_( " -d, --no-encoding don't encode non-printing characters\n"), out
);
85 fputs(_( " -g, --garbage-collect garbage collect the blkid cache\n"), out
);
86 fputs(_( " -o, --output <format> output format; can be one of:\n"
87 " value, device, export, json or full; (default: full)\n"), out
);
88 fputs(_( " -k, --list-filesystems list all known filesystems/RAIDs and exit\n"), out
);
89 fputs(_( " -s, --match-tag <tag> show specified tag(s) (default show all tags)\n"), out
);
90 fputs(_( " -t, --match-token <token> find device with a specific token (NAME=value pair)\n"), out
);
91 fputs(_( " -l, --list-one look up only first device with token specified by -t\n"), out
);
92 fputs(_( " -L, --label <label> convert LABEL to device name\n"), out
);
93 fputs(_( " -U, --uuid <uuid> convert UUID to device name\n"), out
);
95 fputs(_( "Low-level probing options:\n"), out
);
96 fputs(_( " -p, --probe low-level superblocks probing (bypass cache)\n"), out
);
97 fputs(_( " -i, --info gather information about I/O limits\n"), out
);
98 fputs(_( " -H, --hint <value> set hint for probing function\n"), out
);
99 fputs(_( " -S, --size <size> overwrite device size\n"), out
);
100 fputs(_( " -O, --offset <offset> probe at the given offset\n"), out
);
101 fputs(_( " -u, --usages <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"), out
);
102 fputs(_( " -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3)\n"), out
);
103 fputs(_( " -D, --no-part-details don't print info from partition table\n"), out
);
105 fputs(USAGE_SEPARATOR
, out
);
106 fprintf(out
, USAGE_HELP_OPTIONS(28));
108 fputs(USAGE_ARGUMENTS
, out
);
109 fprintf(out
, USAGE_ARG_SIZE(_("<size> and <offset>")));
110 fputs(USAGE_ARG_SEPARATOR
, out
);
111 fputs(_(" <dev> specify device(s) to probe (default: all devices)\n"), out
);
113 fprintf(out
, USAGE_MAN_TAIL("blkid(8)"));
118 * This function does "safe" printing. It will convert non-printable
119 * ASCII characters using '^' and M- notation.
121 * If 'esc' is defined then escape all chars from esc by \.
123 static void safe_print(const struct blkid_control
*ctl
, const char *cp
, int len
,
133 if (!ctl
->raw_chars
) {
138 if ((ch
< 32) || (ch
== 0x7f)) {
140 ch
^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
142 } else if (esc
&& strchr(esc
, ch
))
149 static int pretty_print_word(const char *str
, int max_len
,
150 int left_len
, int overflow_nl
)
152 int len
= strlen(str
) + left_len
;
156 if (overflow_nl
&& len
> max_len
) {
159 } else if (len
> max_len
)
163 } while (len
++ < max_len
);
167 static void pretty_print_line(const char *device
, const char *fs_type
,
168 const char *label
, const char *mtpt
,
171 static int device_len
= 10, fs_type_len
= 7;
172 static int label_len
= 8, mtpt_len
= 14;
173 static int term_width
= -1;
176 if (term_width
< 0) {
177 term_width
= get_terminal_width(80);
179 if (term_width
> 80) {
192 len
= pretty_print_word(device
, device_len
, 0, 1);
193 len
= pretty_print_word(fs_type
, fs_type_len
, len
, 0);
194 len
= pretty_print_word(label
, label_len
, len
, 0);
195 pretty_print_word(mtpt
, mtpt_len
, len
, 0);
201 static void pretty_print_dev(blkid_dev dev
)
203 blkid_tag_iterate iter
;
204 const char *type
, *value
, *devname
;
205 const char *uuid
= "", *fs_type
= "", *label
= "";
206 int len
, mount_flags
;
211 pretty_print_line("device", "fs_type", "label",
212 "mount point", "UUID");
213 for (len
=get_terminal_width(0)-1; len
> 0; len
--)
219 devname
= blkid_dev_devname(dev
);
220 if (access(devname
, F_OK
))
223 /* Get the uuid, label, type */
224 iter
= blkid_tag_iterate_begin(dev
);
225 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
226 if (!strcmp(type
, "UUID"))
228 if (!strcmp(type
, "TYPE"))
230 if (!strcmp(type
, "LABEL"))
233 blkid_tag_iterate_end(iter
);
235 /* Get the mount point */
237 retval
= check_mount_point(devname
, &mount_flags
, mtpt
, sizeof(mtpt
));
239 const char *msg
= NULL
;
241 if (mount_flags
& MF_MOUNTED
) {
243 msg
= _("(mounted, mtpt unknown)");
244 } else if (mount_flags
& MF_BUSY
)
247 msg
= _("(not mounted)");
250 xstrncpy(mtpt
, msg
, sizeof(mtpt
));
253 pretty_print_line(devname
, fs_type
, label
, mtpt
, uuid
);
256 static void print_udev_format(const char *name
, const char *value
)
258 char enc
[265], safe
[256];
259 size_t namelen
= strlen(name
);
263 if (!strcmp(name
, "TYPE")
264 || !strcmp(name
, "VERSION")
265 || !strcmp(name
, "SYSTEM_ID")
266 || !strcmp(name
, "PUBLISHER_ID")
267 || !strcmp(name
, "APPLICATION_ID")
268 || !strcmp(name
, "BOOT_SYSTEM_ID")
269 || !strcmp(name
, "VOLUME_ID")
270 || !strcmp(name
, "LOGICAL_VOLUME_ID")
271 || !strcmp(name
, "VOLUME_SET_ID")
272 || !strcmp(name
, "DATA_PREPARER_ID")) {
273 blkid_encode_string(value
, enc
, sizeof(enc
));
274 printf("ID_FS_%s=%s\n", name
, enc
);
276 } else if (!strcmp(name
, "UUID") ||
277 !strncmp(name
, "LABEL", 5) ||
278 !strcmp(name
, "UUID_SUB")) {
280 blkid_safe_string(value
, safe
, sizeof(safe
));
281 printf("ID_FS_%s=%s\n", name
, safe
);
283 blkid_encode_string(value
, enc
, sizeof(enc
));
284 printf("ID_FS_%s_ENC=%s\n", name
, enc
);
286 } else if (!strcmp(name
, "PTUUID")) {
287 printf("ID_PART_TABLE_UUID=%s\n", value
);
289 } else if (!strcmp(name
, "PTTYPE")) {
290 printf("ID_PART_TABLE_TYPE=%s\n", value
);
292 } else if (!strcmp(name
, "PART_ENTRY_NAME") ||
293 !strcmp(name
, "PART_ENTRY_TYPE")) {
295 blkid_encode_string(value
, enc
, sizeof(enc
));
296 printf("ID_%s=%s\n", name
, enc
);
298 } else if (!strncmp(name
, "PART_ENTRY_", 11))
299 printf("ID_%s=%s\n", name
, value
);
301 else if (namelen
>= 15 && (
302 !strcmp(name
+ (namelen
- 12), "_SECTOR_SIZE") ||
303 !strcmp(name
+ (namelen
- 8), "_IO_SIZE") ||
304 !strcmp(name
, "ALIGNMENT_OFFSET")))
305 printf("ID_IOLIMIT_%s=%s\n", name
, value
);
307 printf("ID_FS_%s=%s\n", name
, value
);
310 static int has_item(const struct blkid_control
*ctl
, const char *item
)
314 for (p
= ctl
->show
; *p
!= NULL
; p
++)
315 if (!strcmp(item
, *p
))
320 static void print_value(const struct blkid_control
*ctl
, int num
,
321 const char *devname
, const char *value
,
322 const char *name
, size_t valsz
)
324 if (ctl
->output
& OUTPUT_VALUE_ONLY
) {
325 fputs(value
, stdout
);
328 } else if (ctl
->output
& OUTPUT_UDEV_LIST
) {
329 print_udev_format(name
, value
);
331 } else if (ctl
->output
& OUTPUT_EXPORT_LIST
) {
332 if (num
== 1 && devname
)
333 printf("DEVNAME=%s\n", devname
);
336 safe_print(ctl
, value
, valsz
, " \\\"'$`<>");
339 } else if (ctl
->output
& OUTPUT_JSON
) {
340 ul_jsonwrt_value_s_sized(ctl
->json_fmt
, name
, value
, valsz
);
343 if (num
== 1 && devname
)
344 printf("%s:", devname
);
347 fputs("=\"", stdout
);
348 safe_print(ctl
, value
, valsz
, "\"\\");
353 static void print_tags(const struct blkid_control
*ctl
, blkid_dev dev
)
355 blkid_tag_iterate iter
;
356 const char *type
, *value
, *devname
;
358 static int first
= 1;
363 if (ctl
->output
& OUTPUT_PRETTY_LIST
) {
364 pretty_print_dev(dev
);
368 devname
= blkid_dev_devname(dev
);
370 if (ctl
->output
& OUTPUT_DEVICE_ONLY
) {
371 printf("%s\n", devname
);
375 if (ctl
->output
== OUTPUT_JSON
) {
376 ul_jsonwrt_init(ctl
->json_fmt
, stdout
, 0);
377 ul_jsonwrt_open(ctl
->json_fmt
, NULL
, UL_JSON_OBJECT
);
380 iter
= blkid_tag_iterate_begin(dev
);
381 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
382 if (ctl
->show
[0] && !has_item(ctl
, type
))
385 if (num
== 1 && !first
&&
386 (ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
387 /* add extra line between output from more devices */
390 print_value(ctl
, num
++, devname
, value
, type
, strlen(value
));
392 blkid_tag_iterate_end(iter
);
394 if (ctl
->output
== OUTPUT_JSON
)
395 ul_jsonwrt_close(ctl
->json_fmt
, UL_JSON_OBJECT
);
398 if (!(ctl
->output
& (OUTPUT_VALUE_ONLY
| OUTPUT_UDEV_LIST
|
407 static int append_str(char **res
, size_t *sz
, const char *a
, const char *b
)
410 size_t asz
= a
? strlen(a
) : 0;
411 size_t bsz
= b
? strlen(b
) : 0;
412 size_t len
= *sz
+ asz
+ bsz
;
417 *res
= str
= xrealloc(str
, len
+ 1);
421 str
= mempcpy(str
, a
, asz
);
423 str
= mempcpy(str
, b
, bsz
);
431 * Compose and print ID_FS_AMBIVALENT for udev
433 static int print_udev_ambivalent(blkid_probe pr
)
437 int count
= 0, rc
= -1;
439 while (!blkid_do_probe(pr
)) {
440 const char *usage_txt
= NULL
, *type
= NULL
, *version
= NULL
;
443 blkid_probe_lookup_value(pr
, "USAGE", &usage_txt
, NULL
);
444 blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
);
445 blkid_probe_lookup_value(pr
, "VERSION", &version
, NULL
);
447 if (!usage_txt
|| !type
)
450 blkid_encode_string(usage_txt
, enc
, sizeof(enc
));
451 if (append_str(&val
, &valsz
, enc
, ":"))
454 blkid_encode_string(type
, enc
, sizeof(enc
));
455 if (append_str(&val
, &valsz
, enc
, version
? ":" : " "))
459 blkid_encode_string(version
, enc
, sizeof(enc
));
460 if (append_str(&val
, &valsz
, enc
, " "))
467 *(val
+ valsz
- 1) = '\0'; /* rem tailing whitespace */
468 printf("ID_FS_AMBIVALENT=%s\n", val
);
476 static int lowprobe_superblocks(blkid_probe pr
, struct blkid_control
*ctl
)
479 int rc
, fd
= blkid_probe_get_fd(pr
);
481 if (fd
< 0 || fstat(fd
, &st
))
484 blkid_probe_enable_partitions(pr
, 1);
486 if (!S_ISCHR(st
.st_mode
) && blkid_probe_get_size(pr
) <= 1024 * 1440 &&
487 blkid_probe_is_wholedisk(pr
)) {
489 * check if the small disk is partitioned, if yes then
490 * don't probe for filesystems.
492 blkid_probe_enable_superblocks(pr
, 0);
494 rc
= blkid_do_fullprobe(pr
);
496 return rc
; /* -1 = error, 1 = nothing, 0 = success */
498 if (blkid_probe_lookup_value(pr
, "PTTYPE", NULL
, NULL
) == 0)
499 return 0; /* partition table detected */
502 if (!ctl
->no_part_details
)
503 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
504 blkid_probe_enable_superblocks(pr
, 1);
506 return blkid_do_safeprobe(pr
);
509 static int lowprobe_topology(blkid_probe pr
)
511 /* enable topology probing only */
512 blkid_probe_enable_topology(pr
, 1);
514 blkid_probe_enable_superblocks(pr
, 0);
515 blkid_probe_enable_partitions(pr
, 0);
517 return blkid_do_fullprobe(pr
);
520 static int lowprobe_device(blkid_probe pr
, const char *devname
,
521 struct blkid_control
*ctl
)
525 int nvals
= 0, n
, num
= 1;
529 static int first
= 1;
531 fd
= open(devname
, O_RDONLY
|O_CLOEXEC
|O_NONBLOCK
);
533 warn(_("error: %s"), devname
);
534 return BLKID_EXIT_NOTFOUND
;
537 if (blkid_probe_set_device(pr
, fd
, ctl
->offset
, ctl
->size
)) {
539 warn(_("error: %s"), devname
);
543 if (ctl
->lowprobe_topology
)
544 rc
= lowprobe_topology(pr
);
545 if (rc
>= 0 && ctl
->lowprobe_superblocks
)
546 rc
= lowprobe_superblocks(pr
, ctl
);
551 nvals
= blkid_probe_numof_values(pr
);
553 if (nvals
&& !first
&& ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
))
554 /* add extra line between output from devices */
557 if (ctl
->output
== OUTPUT_JSON
) {
558 ul_jsonwrt_init(ctl
->json_fmt
, stdout
, 0);
559 ul_jsonwrt_open(ctl
->json_fmt
, NULL
, UL_JSON_OBJECT
);
562 if (nvals
&& (ctl
->output
& OUTPUT_DEVICE_ONLY
)) {
563 printf("%s\n", devname
);
567 for (n
= 0; n
< nvals
; n
++) {
568 if (blkid_probe_get_value(pr
, n
, &name
, &data
, &len
))
570 if (ctl
->show
[0] && !has_item(ctl
, name
))
572 len
= strnlen(data
, len
);
573 print_value(ctl
, num
++, devname
, data
, name
, len
);
579 if (nvals
>= 1 && !(ctl
->output
& (OUTPUT_VALUE_ONLY
|
580 OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
|
584 if (ctl
->output
== OUTPUT_JSON
)
585 ul_jsonwrt_close(ctl
->json_fmt
, UL_JSON_OBJECT
);
588 if (ctl
->output
& OUTPUT_UDEV_LIST
)
589 print_udev_ambivalent(pr
);
591 warnx(_("%s: ambivalent result (probably more "
592 "filesystems on the device, use wipefs(8) "
593 "to see more details)"),
599 return BLKID_EXIT_AMBIVAL
; /* ambivalent probing result */
601 return BLKID_EXIT_NOTFOUND
; /* nothing detected */
603 return 0; /* success */
606 /* converts comma separated list to BLKID_USAGE_* mask */
607 static int list_to_usage(const char *list
, int *flag
)
610 const char *word
= NULL
, *p
= list
;
612 if (p
&& strncmp(p
, "no", 2) == 0) {
613 *flag
= BLKID_FLTR_NOTIN
;
623 if (!strncmp(word
, "filesystem", 10))
624 mask
|= BLKID_USAGE_FILESYSTEM
;
625 else if (!strncmp(word
, "raid", 4))
626 mask
|= BLKID_USAGE_RAID
;
627 else if (!strncmp(word
, "crypto", 6))
628 mask
|= BLKID_USAGE_CRYPTO
;
629 else if (!strncmp(word
, "other", 5))
630 mask
|= BLKID_USAGE_OTHER
;
637 warnx(_("unknown keyword in -u <list> argument: '%s'"),
639 exit(BLKID_EXIT_OTHER
);
642 /* converts comma separated list to types[] */
643 static char **list_to_types(const char *list
, int *flag
)
646 const char *p
= list
;
649 if (p
&& strncmp(p
, "no", 2) == 0) {
650 *flag
= BLKID_FLTR_NOTIN
;
654 warnx(_("error: -u <list> argument is empty"));
657 for (i
= 1; p
&& (p
= strchr(p
, ',')); i
++, p
++);
659 res
= xcalloc(i
+ 1, sizeof(char *));
660 p
= *flag
& BLKID_FLTR_NOTIN
? list
+ 2 : list
;
664 const char *word
= p
;
666 res
[i
++] = p
? xstrndup(word
, p
- word
) : xstrdup(word
);
675 exit(BLKID_EXIT_OTHER
);
678 static void free_types_list(char *list
[])
684 for (n
= list
; *n
; n
++)
689 int main(int argc
, char **argv
)
691 struct ul_jsonwrt json_fmt
;
692 struct blkid_control ctl
= {
693 .output
= OUTPUT_FULL
,
694 .json_fmt
= &json_fmt
,
696 blkid_cache cache
= NULL
;
697 char **devices
= NULL
;
698 char *search_type
= NULL
, *search_value
= NULL
;
699 char *read
= NULL
, *hint
= NULL
;
701 char **fltr_type
= NULL
;
702 int fltr_flag
= BLKID_FLTR_ONLYIN
;
703 unsigned int numdev
= 0, numtag
= 0;
704 int err
= BLKID_EXIT_OTHER
;
708 static const struct option longopts
[] = {
709 { "cache-file", required_argument
, NULL
, 'c' },
710 { "no-encoding", no_argument
, NULL
, 'd' },
711 { "no-part-details", no_argument
, NULL
, 'D' },
712 { "garbage-collect", no_argument
, NULL
, 'g' },
713 { "output", required_argument
, NULL
, 'o' },
714 { "list-filesystems", no_argument
, NULL
, 'k' },
715 { "match-tag", required_argument
, NULL
, 's' },
716 { "match-token", required_argument
, NULL
, 't' },
717 { "list-one", no_argument
, NULL
, 'l' },
718 { "label", required_argument
, NULL
, 'L' },
719 { "uuid", required_argument
, NULL
, 'U' },
720 { "probe", no_argument
, NULL
, 'p' },
721 { "hint", required_argument
, NULL
, 'H' },
722 { "info", no_argument
, NULL
, 'i' },
723 { "size", required_argument
, NULL
, 'S' },
724 { "offset", required_argument
, NULL
, 'O' },
725 { "usages", required_argument
, NULL
, 'u' },
726 { "match-types", required_argument
, NULL
, 'n' },
727 { "version", no_argument
, NULL
, 'V' },
728 { "help", no_argument
, NULL
, 'h' },
732 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
736 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
738 setlocale(LC_ALL
, "");
739 bindtextdomain(PACKAGE
, LOCALEDIR
);
741 close_stdout_atexit();
743 strutils_set_exitcode(BLKID_EXIT_OTHER
);
745 while ((c
= getopt_long (argc
, argv
,
746 "c:DdgH:hilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts
, NULL
)) != -1) {
748 err_exclusive_options(c
, longopts
, excl
, excl_st
);
758 ctl
.no_part_details
= 1;
765 search_value
= xstrdup(optarg
);
766 search_type
= xstrdup("LABEL");
769 fltr_type
= list_to_types(optarg
, &fltr_flag
);
772 fltr_usage
= list_to_usage(optarg
, &fltr_flag
);
776 search_value
= xstrdup(optarg
);
777 search_type
= xstrdup("UUID");
780 ctl
.lowprobe_topology
= 1;
791 const char *name
= NULL
;
793 while (blkid_superblocks_get_name(idx
++, &name
, NULL
) == 0)
794 printf("%s\n", name
);
798 if (!strcmp(optarg
, "value"))
799 ctl
.output
= OUTPUT_VALUE_ONLY
;
800 else if (!strcmp(optarg
, "device"))
801 ctl
.output
= OUTPUT_DEVICE_ONLY
;
802 else if (!strcmp(optarg
, "list"))
803 ctl
.output
= OUTPUT_PRETTY_LIST
; /* deprecated */
804 else if (!strcmp(optarg
, "udev"))
805 ctl
.output
= OUTPUT_UDEV_LIST
;
806 else if (!strcmp(optarg
, "export"))
807 ctl
.output
= OUTPUT_EXPORT_LIST
;
808 else if (!strcmp(optarg
, "json"))
809 ctl
.output
= OUTPUT_JSON
;
810 else if (!strcmp(optarg
, "full"))
813 errx(BLKID_EXIT_OTHER
, _("unsupported output format %s"), optarg
);
816 ctl
.offset
= strtosize_or_err(optarg
, _("invalid offset argument"));
819 ctl
.lowprobe_superblocks
= 1;
822 if (numtag
+ 1 >= sizeof(ctl
.show
) / sizeof(*ctl
.show
)) {
823 warnx(_("Too many tags specified"));
826 ctl
.show
[numtag
++] = optarg
;
829 ctl
.size
= strtosize_or_err(optarg
, _("invalid size argument"));
833 warnx(_("Can only search for "
834 "one NAME=value pair"));
837 if (blkid_parse_tag_string(optarg
,
840 warnx(_("-t needs NAME=value pair"));
846 fprintf(stdout
, _("%s from %s (libblkid %s, %s)\n"),
847 program_invocation_short_name
, PACKAGE_STRING
,
848 LIBBLKID_VERSION
, LIBBLKID_DATE
);
852 /* ignore - backward compatibility */
858 errtryhelp(EXIT_FAILURE
);
862 if (ctl
.lowprobe_topology
|| ctl
.lowprobe_superblocks
)
865 /* The rest of the args are device names */
867 devices
= xcalloc(argc
- optind
, sizeof(char *));
868 while (optind
< argc
) {
869 char *dev
= argv
[optind
++];
872 if (stat(dev
, &sb
) != 0)
874 else if (S_ISBLK(sb
.st_mode
))
876 else if (S_ISREG(sb
.st_mode
))
878 else if (S_ISCHR(sb
.st_mode
)) {
881 if (!sysfs_chrdev_devno_to_devname(
882 sb
.st_rdev
, buf
, sizeof(buf
)))
884 if (strncmp(buf
, "ubi", 3) != 0)
889 devices
[numdev
++] = dev
;
893 /* only unsupported devices specified */
894 err
= BLKID_EXIT_NOTFOUND
;
899 /* convert LABEL/UUID lookup to evaluate request */
900 if (ctl
.lookup
&& ctl
.output
== OUTPUT_DEVICE_ONLY
&& search_type
&&
901 (!strcmp(search_type
, "LABEL") || !strcmp(search_type
, "UUID"))) {
906 if (!ctl
.lowprobe
&& !ctl
.eval
&& blkid_get_cache(&cache
, read
) < 0)
910 blkid_gc_cache(cache
);
914 err
= BLKID_EXIT_NOTFOUND
;
916 if (ctl
.eval
== 0 && (ctl
.output
& OUTPUT_PRETTY_LIST
)) {
918 errx(BLKID_EXIT_OTHER
,
919 _("The low-level probing mode does not "
920 "support 'list' output format"));
921 pretty_print_dev(NULL
);
931 errx(BLKID_EXIT_OTHER
,
932 _("The low-level probing mode "
933 "requires a device"));
935 /* automatically enable 'export' format for I/O Limits */
936 if (!ctl
.output
&& ctl
.lowprobe_topology
)
937 ctl
.output
= OUTPUT_EXPORT_LIST
;
939 pr
= blkid_new_probe();
942 if (hint
&& blkid_probe_set_hint(pr
, hint
, 0) != 0) {
943 warn(_("Failed to use probing hint: %s"), hint
);
947 if (ctl
.lowprobe_superblocks
) {
948 blkid_probe_set_superblocks_flags(pr
,
949 BLKID_SUBLKS_LABEL
| BLKID_SUBLKS_UUID
|
950 BLKID_SUBLKS_TYPE
| BLKID_SUBLKS_SECTYPE
|
951 BLKID_SUBLKS_USAGE
| BLKID_SUBLKS_VERSION
|
952 BLKID_SUBLKS_FSINFO
);
955 blkid_probe_filter_superblocks_usage(pr
, fltr_flag
, fltr_usage
))
958 else if (fltr_type
&&
959 blkid_probe_filter_superblocks_type(pr
, fltr_flag
, fltr_type
))
963 for (i
= 0; i
< numdev
; i
++) {
964 err
= lowprobe_device(pr
, devices
[i
], &ctl
);
968 blkid_free_probe(pr
);
969 } else if (ctl
.eval
) {
973 char *res
= blkid_evaluate_tag(search_type
, search_value
, NULL
);
978 } else if (ctl
.lookup
) {
980 * Classic (cache based) API
985 errx(BLKID_EXIT_OTHER
,
986 _("The lookup option requires a "
987 "search type specified using -t"));
988 /* Load any additional devices not in the cache */
989 for (i
= 0; i
< numdev
; i
++)
990 blkid_get_dev(cache
, devices
[i
], BLKID_DEV_NORMAL
);
992 if ((dev
= blkid_find_dev_with_tag(cache
, search_type
,
994 print_tags(&ctl
, dev
);
997 /* If we didn't specify a single device, show all available devices */
998 } else if (!numdev
) {
999 blkid_dev_iterate iter
;
1002 blkid_probe_all(cache
);
1004 iter
= blkid_dev_iterate_begin(cache
);
1005 blkid_dev_set_search(iter
, search_type
, search_value
);
1006 while (blkid_dev_next(iter
, &dev
) == 0) {
1007 dev
= blkid_verify(cache
, dev
);
1010 print_tags(&ctl
, dev
);
1013 blkid_dev_iterate_end(iter
);
1014 /* Add all specified devices to cache (optionally display tags) */
1015 } else for (i
= 0; i
< numdev
; i
++) {
1016 blkid_dev dev
= blkid_get_dev(cache
, devices
[i
],
1021 !blkid_dev_has_tag(dev
, search_type
,
1024 print_tags(&ctl
, dev
);
1032 free_types_list(fltr_type
);
1033 if (!ctl
.lowprobe
&& !ctl
.eval
)
1034 blkid_put_cache(cache
);