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)
29 #define BLKID_EXIT_NOTFOUND 2 /* token or device not found */
30 #define BLKID_EXIT_OTHER 4 /* bad usage or other error */
31 #define BLKID_EXIT_AMBIVAL 8 /* ambivalent low-level probing detected */
35 #include "ismounted.h"
38 #define OPTUTILS_EXIT_CODE BLKID_EXIT_OTHER /* exclusive_option() */
40 #define CLOSE_EXIT_CODE BLKID_EXIT_OTHER /* close_stdout() */
41 #include "closestream.h"
46 #define XALLOC_EXIT_CODE BLKID_EXIT_OTHER /* x.*alloc(), xstrndup() */
51 struct blkid_control
{
61 lowprobe_superblocks
:1,
67 static void __attribute__((__noreturn__
)) usage(void)
71 fputs(USAGE_HEADER
, out
);
72 fprintf(out
, _( " %s --label <label> | --uuid <uuid>\n\n"), program_invocation_short_name
);
73 fprintf(out
, _( " %s [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] \n"
74 " [--match-token <token>] [<dev> ...]\n\n"), program_invocation_short_name
);
75 fprintf(out
, _( " %s -p [--match-tag <tag>] [--offset <offset>] [--size <size>] \n"
76 " [--output <format>] <dev> ...\n\n"), program_invocation_short_name
);
77 fprintf(out
, _( " %s -i [--match-tag <tag>] [--output <format>] <dev> ...\n"), program_invocation_short_name
);
78 fputs(USAGE_OPTIONS
, out
);
79 fputs(_( " -c, --cache-file <file> read from <file> instead of reading from the default\n"
80 " cache file (-c /dev/null means no cache)\n"), out
);
81 fputs(_( " -d, --no-encoding don't encode non-printing characters\n"), out
);
82 fputs(_( " -g, --garbage-collect garbage collect the blkid cache\n"), out
);
83 fputs(_( " -o, --output <format> output format; can be one of:\n"
84 " value, device, export or full; (default: full)\n"), out
);
85 fputs(_( " -k, --list-filesystems list all known filesystems/RAIDs and exit\n"), out
);
86 fputs(_( " -s, --match-tag <tag> show specified tag(s) (default show all tags)\n"), out
);
87 fputs(_( " -t, --match-token <token> find device with a specific token (NAME=value pair)\n"), out
);
88 fputs(_( " -l, --list-one look up only first device with token specified by -t\n"), out
);
89 fputs(_( " -L, --label <label> convert LABEL to device name\n"), out
);
90 fputs(_( " -U, --uuid <uuid> convert UUID to device name\n"), out
);
92 fputs(_( "Low-level probing options:\n"), out
);
93 fputs(_( " -p, --probe low-level superblocks probing (bypass cache)\n"), out
);
94 fputs(_( " -i, --info gather information about I/O limits\n"), out
);
95 fputs(_( " -H, --hint <value> set hint for probing function\n"), out
);
96 fputs(_( " -S, --size <size> overwrite device size\n"), out
);
97 fputs(_( " -O, --offset <offset> probe at the given offset\n"), out
);
98 fputs(_( " -u, --usages <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"), out
);
99 fputs(_( " -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3)\n"), out
);
100 fputs(_( " -D, --no-part-details don't print info from partition table\n"), out
);
102 fputs(USAGE_SEPARATOR
, out
);
103 fprintf(out
, USAGE_HELP_OPTIONS(28));
105 fputs(USAGE_ARGUMENTS
, out
);
106 fprintf(out
, USAGE_ARG_SIZE(_("<size> and <offset>")));
107 fputs(USAGE_ARG_SEPARATOR
, out
);
108 fputs(_(" <dev> specify device(s) to probe (default: all devices)\n"), out
);
110 fprintf(out
, USAGE_MAN_TAIL("blkid(8)"));
115 * This function does "safe" printing. It will convert non-printable
116 * ASCII characters using '^' and M- notation.
118 * If 'esc' is defined then escape all chars from esc by \.
120 static void safe_print(const struct blkid_control
*ctl
, const char *cp
, int len
,
130 if (!ctl
->raw_chars
) {
135 if ((ch
< 32) || (ch
== 0x7f)) {
137 ch
^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
139 } else if (esc
&& strchr(esc
, ch
))
146 static int pretty_print_word(const char *str
, int max_len
,
147 int left_len
, int overflow_nl
)
149 int len
= strlen(str
) + left_len
;
153 if (overflow_nl
&& len
> max_len
) {
156 } else if (len
> max_len
)
160 } while (len
++ < max_len
);
164 static void pretty_print_line(const char *device
, const char *fs_type
,
165 const char *label
, const char *mtpt
,
168 static int device_len
= 10, fs_type_len
= 7;
169 static int label_len
= 8, mtpt_len
= 14;
170 static int term_width
= -1;
173 if (term_width
< 0) {
174 term_width
= get_terminal_width(80);
176 if (term_width
> 80) {
189 len
= pretty_print_word(device
, device_len
, 0, 1);
190 len
= pretty_print_word(fs_type
, fs_type_len
, len
, 0);
191 len
= pretty_print_word(label
, label_len
, len
, 0);
192 pretty_print_word(mtpt
, mtpt_len
, len
, 0);
198 static void pretty_print_dev(blkid_dev dev
)
200 blkid_tag_iterate iter
;
201 const char *type
, *value
, *devname
;
202 const char *uuid
= "", *fs_type
= "", *label
= "";
203 int len
, mount_flags
;
208 pretty_print_line("device", "fs_type", "label",
209 "mount point", "UUID");
210 for (len
=get_terminal_width(0)-1; len
> 0; len
--)
216 devname
= blkid_dev_devname(dev
);
217 if (access(devname
, F_OK
))
220 /* Get the uuid, label, type */
221 iter
= blkid_tag_iterate_begin(dev
);
222 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
223 if (!strcmp(type
, "UUID"))
225 if (!strcmp(type
, "TYPE"))
227 if (!strcmp(type
, "LABEL"))
230 blkid_tag_iterate_end(iter
);
232 /* Get the mount point */
234 retval
= check_mount_point(devname
, &mount_flags
, mtpt
, sizeof(mtpt
));
236 const char *msg
= NULL
;
238 if (mount_flags
& MF_MOUNTED
) {
240 msg
= _("(mounted, mtpt unknown)");
241 } else if (mount_flags
& MF_BUSY
)
244 msg
= _("(not mounted)");
247 xstrncpy(mtpt
, msg
, sizeof(mtpt
));
250 pretty_print_line(devname
, fs_type
, label
, mtpt
, uuid
);
253 static void print_udev_format(const char *name
, const char *value
)
255 char enc
[265], safe
[256];
256 size_t namelen
= strlen(name
);
260 if (!strcmp(name
, "TYPE")
261 || !strcmp(name
, "VERSION")
262 || !strcmp(name
, "SYSTEM_ID")
263 || !strcmp(name
, "PUBLISHER_ID")
264 || !strcmp(name
, "APPLICATION_ID")
265 || !strcmp(name
, "BOOT_SYSTEM_ID")
266 || !strcmp(name
, "VOLUME_ID")
267 || !strcmp(name
, "LOGICAL_VOLUME_ID")
268 || !strcmp(name
, "VOLUME_SET_ID")
269 || !strcmp(name
, "DATA_PREPARER_ID")) {
270 blkid_encode_string(value
, enc
, sizeof(enc
));
271 printf("ID_FS_%s=%s\n", name
, enc
);
273 } else if (!strcmp(name
, "UUID") ||
274 !strncmp(name
, "LABEL", 5) ||
275 !strcmp(name
, "UUID_SUB")) {
277 blkid_safe_string(value
, safe
, sizeof(safe
));
278 printf("ID_FS_%s=%s\n", name
, safe
);
280 blkid_encode_string(value
, enc
, sizeof(enc
));
281 printf("ID_FS_%s_ENC=%s\n", name
, enc
);
283 } else if (!strcmp(name
, "PTUUID")) {
284 printf("ID_PART_TABLE_UUID=%s\n", value
);
286 } else if (!strcmp(name
, "PTTYPE")) {
287 printf("ID_PART_TABLE_TYPE=%s\n", value
);
289 } else if (!strcmp(name
, "PART_ENTRY_NAME") ||
290 !strcmp(name
, "PART_ENTRY_TYPE")) {
292 blkid_encode_string(value
, enc
, sizeof(enc
));
293 printf("ID_%s=%s\n", name
, enc
);
295 } else if (!strncmp(name
, "PART_ENTRY_", 11))
296 printf("ID_%s=%s\n", name
, value
);
298 else if (namelen
>= 15 && (
299 !strcmp(name
+ (namelen
- 12), "_SECTOR_SIZE") ||
300 !strcmp(name
+ (namelen
- 8), "_IO_SIZE") ||
301 !strcmp(name
, "ALIGNMENT_OFFSET")))
302 printf("ID_IOLIMIT_%s=%s\n", name
, value
);
304 printf("ID_FS_%s=%s\n", name
, value
);
307 static int has_item(const struct blkid_control
*ctl
, const char *item
)
311 for (p
= ctl
->show
; *p
!= NULL
; p
++)
312 if (!strcmp(item
, *p
))
317 static void print_value(const struct blkid_control
*ctl
, int num
,
318 const char *devname
, const char *value
,
319 const char *name
, size_t valsz
)
321 if (ctl
->output
& OUTPUT_VALUE_ONLY
) {
322 fputs(value
, stdout
);
325 } else if (ctl
->output
& OUTPUT_UDEV_LIST
) {
326 print_udev_format(name
, value
);
328 } else if (ctl
->output
& OUTPUT_EXPORT_LIST
) {
329 if (num
== 1 && devname
)
330 printf("DEVNAME=%s\n", devname
);
333 safe_print(ctl
, value
, valsz
, " \\\"'$`<>");
337 if (num
== 1 && devname
)
338 printf("%s:", devname
);
341 fputs("=\"", stdout
);
342 safe_print(ctl
, value
, valsz
, "\"\\");
347 static void print_tags(const struct blkid_control
*ctl
, blkid_dev dev
)
349 blkid_tag_iterate iter
;
350 const char *type
, *value
, *devname
;
352 static int first
= 1;
357 if (ctl
->output
& OUTPUT_PRETTY_LIST
) {
358 pretty_print_dev(dev
);
362 devname
= blkid_dev_devname(dev
);
364 if (ctl
->output
& OUTPUT_DEVICE_ONLY
) {
365 printf("%s\n", devname
);
369 iter
= blkid_tag_iterate_begin(dev
);
370 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
371 if (ctl
->show
[0] && !has_item(ctl
, type
))
374 if (num
== 1 && !first
&&
375 (ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
376 /* add extra line between output from more devices */
379 print_value(ctl
, num
++, devname
, value
, type
, strlen(value
));
381 blkid_tag_iterate_end(iter
);
384 if (!(ctl
->output
& (OUTPUT_VALUE_ONLY
| OUTPUT_UDEV_LIST
|
385 OUTPUT_EXPORT_LIST
)))
392 static int append_str(char **res
, size_t *sz
, const char *a
, const char *b
)
395 size_t asz
= a
? strlen(a
) : 0;
396 size_t bsz
= b
? strlen(b
) : 0;
397 size_t len
= *sz
+ asz
+ bsz
;
402 *res
= str
= xrealloc(str
, len
+ 1);
406 str
= mempcpy(str
, a
, asz
);
408 str
= mempcpy(str
, b
, bsz
);
416 * Compose and print ID_FS_AMBIVALENT for udev
418 static int print_udev_ambivalent(blkid_probe pr
)
422 int count
= 0, rc
= -1;
424 while (!blkid_do_probe(pr
)) {
425 const char *usage_txt
= NULL
, *type
= NULL
, *version
= NULL
;
428 blkid_probe_lookup_value(pr
, "USAGE", &usage_txt
, NULL
);
429 blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
);
430 blkid_probe_lookup_value(pr
, "VERSION", &version
, NULL
);
432 if (!usage_txt
|| !type
)
435 blkid_encode_string(usage_txt
, enc
, sizeof(enc
));
436 if (append_str(&val
, &valsz
, enc
, ":"))
439 blkid_encode_string(type
, enc
, sizeof(enc
));
440 if (append_str(&val
, &valsz
, enc
, version
? ":" : " "))
444 blkid_encode_string(version
, enc
, sizeof(enc
));
445 if (append_str(&val
, &valsz
, enc
, " "))
452 *(val
+ valsz
- 1) = '\0'; /* rem tailing whitespace */
453 printf("ID_FS_AMBIVALENT=%s\n", val
);
461 static int lowprobe_superblocks(blkid_probe pr
, struct blkid_control
*ctl
)
464 int rc
, fd
= blkid_probe_get_fd(pr
);
466 if (fd
< 0 || fstat(fd
, &st
))
469 blkid_probe_enable_partitions(pr
, 1);
471 if (!S_ISCHR(st
.st_mode
) && blkid_probe_get_size(pr
) <= 1024 * 1440 &&
472 blkid_probe_is_wholedisk(pr
)) {
474 * check if the small disk is partitioned, if yes then
475 * don't probe for filesystems.
477 blkid_probe_enable_superblocks(pr
, 0);
479 rc
= blkid_do_fullprobe(pr
);
481 return rc
; /* -1 = error, 1 = nothing, 0 = success */
483 if (blkid_probe_lookup_value(pr
, "PTTYPE", NULL
, NULL
) == 0)
484 return 0; /* partition table detected */
487 if (!ctl
->no_part_details
)
488 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
489 blkid_probe_enable_superblocks(pr
, 1);
491 return blkid_do_safeprobe(pr
);
494 static int lowprobe_topology(blkid_probe pr
)
496 /* enable topology probing only */
497 blkid_probe_enable_topology(pr
, 1);
499 blkid_probe_enable_superblocks(pr
, 0);
500 blkid_probe_enable_partitions(pr
, 0);
502 return blkid_do_fullprobe(pr
);
505 static int lowprobe_device(blkid_probe pr
, const char *devname
,
506 struct blkid_control
*ctl
)
510 int nvals
= 0, n
, num
= 1;
514 static int first
= 1;
516 fd
= open(devname
, O_RDONLY
|O_CLOEXEC
|O_NONBLOCK
);
518 warn(_("error: %s"), devname
);
519 return BLKID_EXIT_NOTFOUND
;
522 if (blkid_probe_set_device(pr
, fd
, ctl
->offset
, ctl
->size
)) {
524 warn(_("error: %s"), devname
);
528 if (ctl
->lowprobe_topology
)
529 rc
= lowprobe_topology(pr
);
530 if (rc
>= 0 && ctl
->lowprobe_superblocks
)
531 rc
= lowprobe_superblocks(pr
, ctl
);
536 nvals
= blkid_probe_numof_values(pr
);
538 if (nvals
&& !first
&& ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
))
539 /* add extra line between output from devices */
542 if (nvals
&& (ctl
->output
& OUTPUT_DEVICE_ONLY
)) {
543 printf("%s\n", devname
);
547 for (n
= 0; n
< nvals
; n
++) {
548 if (blkid_probe_get_value(pr
, n
, &name
, &data
, &len
))
550 if (ctl
->show
[0] && !has_item(ctl
, name
))
552 len
= strnlen(data
, len
);
553 print_value(ctl
, num
++, devname
, data
, name
, len
);
559 if (nvals
>= 1 && !(ctl
->output
& (OUTPUT_VALUE_ONLY
|
560 OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
564 if (ctl
->output
& OUTPUT_UDEV_LIST
)
565 print_udev_ambivalent(pr
);
567 warnx(_("%s: ambivalent result (probably more "
568 "filesystems on the device, use wipefs(8) "
569 "to see more details)"),
575 return BLKID_EXIT_AMBIVAL
; /* ambivalent probing result */
577 return BLKID_EXIT_NOTFOUND
; /* nothing detected */
579 return 0; /* success */
582 /* converts comma separated list to BLKID_USAGE_* mask */
583 static int list_to_usage(const char *list
, int *flag
)
586 const char *word
= NULL
, *p
= list
;
588 if (p
&& strncmp(p
, "no", 2) == 0) {
589 *flag
= BLKID_FLTR_NOTIN
;
599 if (!strncmp(word
, "filesystem", 10))
600 mask
|= BLKID_USAGE_FILESYSTEM
;
601 else if (!strncmp(word
, "raid", 4))
602 mask
|= BLKID_USAGE_RAID
;
603 else if (!strncmp(word
, "crypto", 6))
604 mask
|= BLKID_USAGE_CRYPTO
;
605 else if (!strncmp(word
, "other", 5))
606 mask
|= BLKID_USAGE_OTHER
;
613 warnx(_("unknown keyword in -u <list> argument: '%s'"),
615 exit(BLKID_EXIT_OTHER
);
618 /* converts comma separated list to types[] */
619 static char **list_to_types(const char *list
, int *flag
)
622 const char *p
= list
;
625 if (p
&& strncmp(p
, "no", 2) == 0) {
626 *flag
= BLKID_FLTR_NOTIN
;
630 warnx(_("error: -u <list> argument is empty"));
633 for (i
= 1; p
&& (p
= strchr(p
, ',')); i
++, p
++);
635 res
= xcalloc(i
+ 1, sizeof(char *));
636 p
= *flag
& BLKID_FLTR_NOTIN
? list
+ 2 : list
;
640 const char *word
= p
;
642 res
[i
++] = p
? xstrndup(word
, p
- word
) : xstrdup(word
);
651 exit(BLKID_EXIT_OTHER
);
654 static void free_types_list(char *list
[])
660 for (n
= list
; *n
; n
++)
665 int main(int argc
, char **argv
)
667 struct blkid_control ctl
= { .output
= OUTPUT_FULL
, 0 };
668 blkid_cache cache
= NULL
;
669 char **devices
= NULL
;
670 char *search_type
= NULL
, *search_value
= NULL
;
671 char *read
= NULL
, *hint
= NULL
;
673 char **fltr_type
= NULL
;
674 int fltr_flag
= BLKID_FLTR_ONLYIN
;
675 unsigned int numdev
= 0, numtag
= 0;
676 int err
= BLKID_EXIT_OTHER
;
680 static const struct option longopts
[] = {
681 { "cache-file", required_argument
, NULL
, 'c' },
682 { "no-encoding", no_argument
, NULL
, 'd' },
683 { "no-part-details", no_argument
, NULL
, 'D' },
684 { "garbage-collect", no_argument
, NULL
, 'g' },
685 { "output", required_argument
, NULL
, 'o' },
686 { "list-filesystems", no_argument
, NULL
, 'k' },
687 { "match-tag", required_argument
, NULL
, 's' },
688 { "match-token", required_argument
, NULL
, 't' },
689 { "list-one", no_argument
, NULL
, 'l' },
690 { "label", required_argument
, NULL
, 'L' },
691 { "uuid", required_argument
, NULL
, 'U' },
692 { "probe", no_argument
, NULL
, 'p' },
693 { "hint", required_argument
, NULL
, 'H' },
694 { "info", no_argument
, NULL
, 'i' },
695 { "size", required_argument
, NULL
, 'S' },
696 { "offset", required_argument
, NULL
, 'O' },
697 { "usages", required_argument
, NULL
, 'u' },
698 { "match-types", required_argument
, NULL
, 'n' },
699 { "version", no_argument
, NULL
, 'V' },
700 { "help", no_argument
, NULL
, 'h' },
704 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
708 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
710 setlocale(LC_ALL
, "");
711 bindtextdomain(PACKAGE
, LOCALEDIR
);
713 close_stdout_atexit();
715 strutils_set_exitcode(BLKID_EXIT_OTHER
);
717 while ((c
= getopt_long (argc
, argv
,
718 "c:DdgH:hilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts
, NULL
)) != -1) {
720 err_exclusive_options(c
, longopts
, excl
, excl_st
);
730 ctl
.no_part_details
= 1;
737 search_value
= xstrdup(optarg
);
738 search_type
= xstrdup("LABEL");
741 fltr_type
= list_to_types(optarg
, &fltr_flag
);
744 fltr_usage
= list_to_usage(optarg
, &fltr_flag
);
748 search_value
= xstrdup(optarg
);
749 search_type
= xstrdup("UUID");
752 ctl
.lowprobe_topology
= 1;
763 const char *name
= NULL
;
765 while (blkid_superblocks_get_name(idx
++, &name
, NULL
) == 0)
766 printf("%s\n", name
);
770 if (!strcmp(optarg
, "value"))
771 ctl
.output
= OUTPUT_VALUE_ONLY
;
772 else if (!strcmp(optarg
, "device"))
773 ctl
.output
= OUTPUT_DEVICE_ONLY
;
774 else if (!strcmp(optarg
, "list"))
775 ctl
.output
= OUTPUT_PRETTY_LIST
; /* deprecated */
776 else if (!strcmp(optarg
, "udev"))
777 ctl
.output
= OUTPUT_UDEV_LIST
;
778 else if (!strcmp(optarg
, "export"))
779 ctl
.output
= OUTPUT_EXPORT_LIST
;
780 else if (!strcmp(optarg
, "full"))
783 errx(BLKID_EXIT_OTHER
, _("unsupported output format %s"), optarg
);
786 ctl
.offset
= strtosize_or_err(optarg
, _("invalid offset argument"));
789 ctl
.lowprobe_superblocks
= 1;
792 if (numtag
+ 1 >= sizeof(ctl
.show
) / sizeof(*ctl
.show
)) {
793 warnx(_("Too many tags specified"));
796 ctl
.show
[numtag
++] = optarg
;
799 ctl
.size
= strtosize_or_err(optarg
, _("invalid size argument"));
803 warnx(_("Can only search for "
804 "one NAME=value pair"));
807 if (blkid_parse_tag_string(optarg
,
810 warnx(_("-t needs NAME=value pair"));
816 fprintf(stdout
, _("%s from %s (libblkid %s, %s)\n"),
817 program_invocation_short_name
, PACKAGE_STRING
,
818 LIBBLKID_VERSION
, LIBBLKID_DATE
);
822 /* ignore - backward compatibility */
828 errtryhelp(EXIT_FAILURE
);
832 if (ctl
.lowprobe_topology
|| ctl
.lowprobe_superblocks
)
835 /* The rest of the args are device names */
837 devices
= xcalloc(argc
- optind
, sizeof(char *));
838 while (optind
< argc
) {
839 char *dev
= argv
[optind
++];
842 if (stat(dev
, &sb
) != 0)
844 else if (S_ISBLK(sb
.st_mode
))
846 else if (S_ISREG(sb
.st_mode
))
848 else if (S_ISCHR(sb
.st_mode
)) {
851 if (!sysfs_chrdev_devno_to_devname(
852 sb
.st_rdev
, buf
, sizeof(buf
)))
854 if (strncmp(buf
, "ubi", 3) != 0)
859 devices
[numdev
++] = dev
;
863 /* only unsupported devices specified */
864 err
= BLKID_EXIT_NOTFOUND
;
869 /* convert LABEL/UUID lookup to evaluate request */
870 if (ctl
.lookup
&& ctl
.output
== OUTPUT_DEVICE_ONLY
&& search_type
&&
871 (!strcmp(search_type
, "LABEL") || !strcmp(search_type
, "UUID"))) {
876 if (!ctl
.lowprobe
&& !ctl
.eval
&& blkid_get_cache(&cache
, read
) < 0)
880 blkid_gc_cache(cache
);
884 err
= BLKID_EXIT_NOTFOUND
;
886 if (ctl
.eval
== 0 && (ctl
.output
& OUTPUT_PRETTY_LIST
)) {
888 errx(BLKID_EXIT_OTHER
,
889 _("The low-level probing mode does not "
890 "support 'list' output format"));
891 pretty_print_dev(NULL
);
901 errx(BLKID_EXIT_OTHER
,
902 _("The low-level probing mode "
903 "requires a device"));
905 /* automatically enable 'export' format for I/O Limits */
906 if (!ctl
.output
&& ctl
.lowprobe_topology
)
907 ctl
.output
= OUTPUT_EXPORT_LIST
;
909 pr
= blkid_new_probe();
912 if (hint
&& blkid_probe_set_hint(pr
, hint
, 0) != 0) {
913 warn(_("Failed to use probing hint: %s"), hint
);
917 if (ctl
.lowprobe_superblocks
) {
918 blkid_probe_set_superblocks_flags(pr
,
919 BLKID_SUBLKS_LABEL
| BLKID_SUBLKS_UUID
|
920 BLKID_SUBLKS_TYPE
| BLKID_SUBLKS_SECTYPE
|
921 BLKID_SUBLKS_USAGE
| BLKID_SUBLKS_VERSION
|
922 BLKID_SUBLKS_FSINFO
);
925 blkid_probe_filter_superblocks_usage(pr
, fltr_flag
, fltr_usage
))
928 else if (fltr_type
&&
929 blkid_probe_filter_superblocks_type(pr
, fltr_flag
, fltr_type
))
933 for (i
= 0; i
< numdev
; i
++) {
934 err
= lowprobe_device(pr
, devices
[i
], &ctl
);
938 blkid_free_probe(pr
);
939 } else if (ctl
.eval
) {
943 char *res
= blkid_evaluate_tag(search_type
, search_value
, NULL
);
948 } else if (ctl
.lookup
) {
950 * Classic (cache based) API
955 errx(BLKID_EXIT_OTHER
,
956 _("The lookup option requires a "
957 "search type specified using -t"));
958 /* Load any additional devices not in the cache */
959 for (i
= 0; i
< numdev
; i
++)
960 blkid_get_dev(cache
, devices
[i
], BLKID_DEV_NORMAL
);
962 if ((dev
= blkid_find_dev_with_tag(cache
, search_type
,
964 print_tags(&ctl
, dev
);
967 /* If we didn't specify a single device, show all available devices */
968 } else if (!numdev
) {
969 blkid_dev_iterate iter
;
972 blkid_probe_all(cache
);
974 iter
= blkid_dev_iterate_begin(cache
);
975 blkid_dev_set_search(iter
, search_type
, search_value
);
976 while (blkid_dev_next(iter
, &dev
) == 0) {
977 dev
= blkid_verify(cache
, dev
);
980 print_tags(&ctl
, dev
);
983 blkid_dev_iterate_end(iter
);
984 /* Add all specified devices to cache (optionally display tags) */
985 } else for (i
= 0; i
< numdev
; i
++) {
986 blkid_dev dev
= blkid_get_dev(cache
, devices
[i
],
991 !blkid_dev_has_tag(dev
, search_type
,
994 print_tags(&ctl
, dev
);
1002 free_types_list(fltr_type
);
1003 if (!ctl
.lowprobe
&& !ctl
.eval
)
1004 blkid_put_cache(cache
);