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() */
49 struct blkid_control
{
59 lowprobe_superblocks
:1,
65 static void print_version(FILE *out
)
67 fprintf(out
, _("%s from %s (libblkid %s, %s)\n"),
68 program_invocation_short_name
, PACKAGE_STRING
,
69 LIBBLKID_VERSION
, LIBBLKID_DATE
);
72 static void __attribute__((__noreturn__
)) usage(void)
76 fputs(USAGE_HEADER
, out
);
77 fprintf(out
, _( " %s --label <label> | --uuid <uuid>\n\n"), program_invocation_short_name
);
78 fprintf(out
, _( " %s [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] \n"
79 " [--match-token <token>] [<dev> ...]\n\n"), program_invocation_short_name
);
80 fprintf(out
, _( " %s -p [--match-tag <tag>] [--offset <offset>] [--size <size>] \n"
81 " [--output <format>] <dev> ...\n\n"), program_invocation_short_name
);
82 fprintf(out
, _( " %s -i [--match-tag <tag>] [--output <format>] <dev> ...\n"), program_invocation_short_name
);
83 fputs(USAGE_OPTIONS
, out
);
84 fputs(_( " -c, --cache-file <file> read from <file> instead of reading from the default\n"
85 " cache file (-c /dev/null means no cache)\n"), out
);
86 fputs(_( " -d, --no-encoding don't encode non-printing characters\n"), out
);
87 fputs(_( " -g, --garbage-collect garbage collect the blkid cache\n"), out
);
88 fputs(_( " -o, --output <format> output format; can be one of:\n"
89 " value, device, export or full; (default: full)\n"), out
);
90 fputs(_( " -k, --list-filesystems list all known filesystems/RAIDs and exit\n"), out
);
91 fputs(_( " -s, --match-tag <tag> show specified tag(s) (default show all tags)\n"), out
);
92 fputs(_( " -t, --match-token <token> find device with a specific token (NAME=value pair)\n"), out
);
93 fputs(_( " -l, --list-one look up only first device with token specified by -t\n"), out
);
94 fputs(_( " -L, --label <label> convert LABEL to device name\n"), out
);
95 fputs(_( " -U, --uuid <uuid> convert UUID to device name\n"), out
);
96 fputs(_( " <dev> specify device(s) to probe (default: all devices)\n"), out
);
98 fputs(_( "Low-level probing options:\n"), out
);
99 fputs(_( " -p, --probe low-level superblocks probing (bypass cache)\n"), out
);
100 fputs(_( " -i, --info gather information about I/O limits\n"), out
);
101 fputs(_( " -S, --size <size> overwrite device size\n"), out
);
102 fputs(_( " -O, --offset <offset> probe at the given offset\n"), out
);
103 fputs(_( " -u, --usages <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"), out
);
104 fputs(_( " -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3)\n"), out
);
105 fputs(_( " -D, --no-part-details don't print info from partition table\n"), out
);
107 fputs(USAGE_SEPARATOR
, out
);
108 printf(USAGE_HELP_OPTIONS(28));
109 printf(USAGE_MAN_TAIL("blkid(8)"));
114 * This function does "safe" printing. It will convert non-printable
115 * ASCII characters using '^' and M- notation.
117 * If 'esc' is defined then escape all chars from esc by \.
119 static void safe_print(const struct blkid_control
*ctl
, const char *cp
, int len
,
129 if (!ctl
->raw_chars
) {
134 if ((ch
< 32) || (ch
== 0x7f)) {
136 ch
^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
138 } else if (esc
&& strchr(esc
, ch
))
145 static int pretty_print_word(const char *str
, int max_len
,
146 int left_len
, int overflow_nl
)
148 int len
= strlen(str
) + left_len
;
152 if (overflow_nl
&& len
> max_len
) {
155 } else if (len
> max_len
)
159 } while (len
++ < max_len
);
163 static void pretty_print_line(const char *device
, const char *fs_type
,
164 const char *label
, const char *mtpt
,
167 static int device_len
= 10, fs_type_len
= 7;
168 static int label_len
= 8, mtpt_len
= 14;
169 static int term_width
= -1;
172 if (term_width
< 0) {
173 term_width
= get_terminal_width(80);
175 if (term_width
> 80) {
188 len
= pretty_print_word(device
, device_len
, 0, 1);
189 len
= pretty_print_word(fs_type
, fs_type_len
, len
, 0);
190 len
= pretty_print_word(label
, label_len
, len
, 0);
191 pretty_print_word(mtpt
, mtpt_len
, len
, 0);
197 static void pretty_print_dev(blkid_dev dev
)
199 blkid_tag_iterate iter
;
200 const char *type
, *value
, *devname
;
201 const char *uuid
= "", *fs_type
= "", *label
= "";
202 int len
, mount_flags
;
207 pretty_print_line("device", "fs_type", "label",
208 "mount point", "UUID");
209 for (len
=get_terminal_width(0)-1; len
> 0; len
--)
215 devname
= blkid_dev_devname(dev
);
216 if (access(devname
, F_OK
))
219 /* Get the uuid, label, type */
220 iter
= blkid_tag_iterate_begin(dev
);
221 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
222 if (!strcmp(type
, "UUID"))
224 if (!strcmp(type
, "TYPE"))
226 if (!strcmp(type
, "LABEL"))
229 blkid_tag_iterate_end(iter
);
231 /* Get the mount point */
233 retval
= check_mount_point(devname
, &mount_flags
, mtpt
, sizeof(mtpt
));
235 if (mount_flags
& MF_MOUNTED
) {
237 strcpy(mtpt
, _("(mounted, mtpt unknown)"));
238 } else if (mount_flags
& MF_BUSY
)
239 strcpy(mtpt
, _("(in use)"));
241 strcpy(mtpt
, _("(not mounted)"));
244 pretty_print_line(devname
, fs_type
, label
, mtpt
, uuid
);
247 static void print_udev_format(const char *name
, const char *value
)
249 char enc
[265], safe
[256];
250 size_t namelen
= strlen(name
);
254 if (!strcmp(name
, "TYPE") || !strcmp(name
, "VERSION")) {
255 blkid_encode_string(value
, enc
, sizeof(enc
));
256 printf("ID_FS_%s=%s\n", name
, enc
);
258 } else if (!strcmp(name
, "UUID") ||
259 !strncmp(name
, "LABEL", 5) ||
260 !strcmp(name
, "UUID_SUB")) {
262 blkid_safe_string(value
, safe
, sizeof(safe
));
263 printf("ID_FS_%s=%s\n", name
, safe
);
265 blkid_encode_string(value
, enc
, sizeof(enc
));
266 printf("ID_FS_%s_ENC=%s\n", name
, enc
);
268 } else if (!strcmp(name
, "PTUUID")) {
269 printf("ID_PART_TABLE_UUID=%s\n", value
);
271 } else if (!strcmp(name
, "PTTYPE")) {
272 printf("ID_PART_TABLE_TYPE=%s\n", value
);
274 } else if (!strcmp(name
, "PART_ENTRY_NAME") ||
275 !strcmp(name
, "PART_ENTRY_TYPE")) {
277 blkid_encode_string(value
, enc
, sizeof(enc
));
278 printf("ID_%s=%s\n", name
, enc
);
280 } else if (!strncmp(name
, "PART_ENTRY_", 11))
281 printf("ID_%s=%s\n", name
, value
);
283 else if (namelen
>= 15 && (
284 !strcmp(name
+ (namelen
- 12), "_SECTOR_SIZE") ||
285 !strcmp(name
+ (namelen
- 8), "_IO_SIZE") ||
286 !strcmp(name
, "ALIGNMENT_OFFSET")))
287 printf("ID_IOLIMIT_%s=%s\n", name
, value
);
289 printf("ID_FS_%s=%s\n", name
, value
);
292 static int has_item(const struct blkid_control
*ctl
, const char *item
)
296 for (p
= ctl
->show
; *p
!= NULL
; p
++)
297 if (!strcmp(item
, *p
))
302 static void print_value(const struct blkid_control
*ctl
, int num
,
303 const char *devname
, const char *value
,
304 const char *name
, size_t valsz
)
306 if (ctl
->output
& OUTPUT_VALUE_ONLY
) {
307 fputs(value
, stdout
);
310 } else if (ctl
->output
& OUTPUT_UDEV_LIST
) {
311 print_udev_format(name
, value
);
313 } else if (ctl
->output
& OUTPUT_EXPORT_LIST
) {
314 if (num
== 1 && devname
)
315 printf("DEVNAME=%s\n", devname
);
318 safe_print(ctl
, value
, valsz
, " \\\"'$`<>");
322 if (num
== 1 && devname
)
323 printf("%s:", devname
);
326 fputs("=\"", stdout
);
327 safe_print(ctl
, value
, valsz
, "\"\\");
332 static void print_tags(const struct blkid_control
*ctl
, blkid_dev dev
)
334 blkid_tag_iterate iter
;
335 const char *type
, *value
, *devname
;
337 static int first
= 1;
342 if (ctl
->output
& OUTPUT_PRETTY_LIST
) {
343 pretty_print_dev(dev
);
347 devname
= blkid_dev_devname(dev
);
349 if (ctl
->output
& OUTPUT_DEVICE_ONLY
) {
350 printf("%s\n", devname
);
354 iter
= blkid_tag_iterate_begin(dev
);
355 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
356 if (ctl
->show
[0] && !has_item(ctl
, type
))
359 if (num
== 1 && !first
&&
360 (ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
361 /* add extra line between output from more devices */
364 print_value(ctl
, num
++, devname
, value
, type
, strlen(value
));
366 blkid_tag_iterate_end(iter
);
369 if (!(ctl
->output
& (OUTPUT_VALUE_ONLY
| OUTPUT_UDEV_LIST
|
370 OUTPUT_EXPORT_LIST
)))
377 static int append_str(char **res
, size_t *sz
, const char *a
, const char *b
)
380 size_t asz
= a
? strlen(a
) : 0;
381 size_t bsz
= b
? strlen(b
) : 0;
382 size_t len
= *sz
+ asz
+ bsz
;
387 *res
= str
= xrealloc(str
, len
+ 1);
404 * Compose and print ID_FS_AMBIVALENT for udev
406 static int print_udev_ambivalent(blkid_probe pr
)
410 int count
= 0, rc
= -1;
412 while (!blkid_do_probe(pr
)) {
413 const char *usage_txt
= NULL
, *type
= NULL
, *version
= NULL
;
416 blkid_probe_lookup_value(pr
, "USAGE", &usage_txt
, NULL
);
417 blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
);
418 blkid_probe_lookup_value(pr
, "VERSION", &version
, NULL
);
420 if (!usage_txt
|| !type
)
423 blkid_encode_string(usage_txt
, enc
, sizeof(enc
));
424 if (append_str(&val
, &valsz
, enc
, ":"))
427 blkid_encode_string(type
, enc
, sizeof(enc
));
428 if (append_str(&val
, &valsz
, enc
, version
? ":" : " "))
432 blkid_encode_string(version
, enc
, sizeof(enc
));
433 if (append_str(&val
, &valsz
, enc
, " "))
440 *(val
+ valsz
- 1) = '\0'; /* rem tailing whitespace */
441 printf("ID_FS_AMBIVALENT=%s\n", val
);
449 static int lowprobe_superblocks(blkid_probe pr
, struct blkid_control
*ctl
)
452 int rc
, fd
= blkid_probe_get_fd(pr
);
454 if (fd
< 0 || fstat(fd
, &st
))
457 blkid_probe_enable_partitions(pr
, 1);
459 if (!S_ISCHR(st
.st_mode
) && blkid_probe_get_size(pr
) <= 1024 * 1440 &&
460 blkid_probe_is_wholedisk(pr
)) {
462 * check if the small disk is partitioned, if yes then
463 * don't probe for filesystems.
465 blkid_probe_enable_superblocks(pr
, 0);
467 rc
= blkid_do_fullprobe(pr
);
469 return rc
; /* -1 = error, 1 = nothing, 0 = success */
471 if (blkid_probe_lookup_value(pr
, "PTTYPE", NULL
, NULL
) == 0)
472 return 0; /* partition table detected */
475 if (!ctl
->no_part_details
)
476 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
477 blkid_probe_enable_superblocks(pr
, 1);
479 return blkid_do_safeprobe(pr
);
482 static int lowprobe_topology(blkid_probe pr
)
484 /* enable topology probing only */
485 blkid_probe_enable_topology(pr
, 1);
487 blkid_probe_enable_superblocks(pr
, 0);
488 blkid_probe_enable_partitions(pr
, 0);
490 return blkid_do_fullprobe(pr
);
493 static int lowprobe_device(blkid_probe pr
, const char *devname
,
494 struct blkid_control
*ctl
)
498 int nvals
= 0, n
, num
= 1;
502 static int first
= 1;
504 fd
= open(devname
, O_RDONLY
|O_CLOEXEC
);
506 warn(_("error: %s"), devname
);
507 return BLKID_EXIT_NOTFOUND
;
509 if (blkid_probe_set_device(pr
, fd
, ctl
->offset
, ctl
->size
))
512 if (ctl
->lowprobe_topology
)
513 rc
= lowprobe_topology(pr
);
514 if (rc
>= 0 && ctl
->lowprobe_superblocks
)
515 rc
= lowprobe_superblocks(pr
, ctl
);
520 nvals
= blkid_probe_numof_values(pr
);
522 if (nvals
&& !first
&& ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
))
523 /* add extra line between output from devices */
526 if (nvals
&& (ctl
->output
& OUTPUT_DEVICE_ONLY
)) {
527 printf("%s\n", devname
);
531 for (n
= 0; n
< nvals
; n
++) {
532 if (blkid_probe_get_value(pr
, n
, &name
, &data
, &len
))
534 if (ctl
->show
[0] && !has_item(ctl
, name
))
536 len
= strnlen(data
, len
);
537 print_value(ctl
, num
++, devname
, data
, name
, len
);
543 if (nvals
>= 1 && !(ctl
->output
& (OUTPUT_VALUE_ONLY
|
544 OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
548 if (ctl
->output
& OUTPUT_UDEV_LIST
)
549 print_udev_ambivalent(pr
);
551 warnx(_("%s: ambivalent result (probably more "
552 "filesystems on the device, use wipefs(8) "
553 "to see more details)"),
559 return BLKID_EXIT_AMBIVAL
; /* ambivalent probing result */
561 return BLKID_EXIT_NOTFOUND
; /* nothing detected */
563 return 0; /* success */
566 /* converts comma separated list to BLKID_USAGE_* mask */
567 static int list_to_usage(const char *list
, int *flag
)
570 const char *word
= NULL
, *p
= list
;
572 if (p
&& strncmp(p
, "no", 2) == 0) {
573 *flag
= BLKID_FLTR_NOTIN
;
583 if (!strncmp(word
, "filesystem", 10))
584 mask
|= BLKID_USAGE_FILESYSTEM
;
585 else if (!strncmp(word
, "raid", 4))
586 mask
|= BLKID_USAGE_RAID
;
587 else if (!strncmp(word
, "crypto", 6))
588 mask
|= BLKID_USAGE_CRYPTO
;
589 else if (!strncmp(word
, "other", 5))
590 mask
|= BLKID_USAGE_OTHER
;
597 warnx(_("unknown keyword in -u <list> argument: '%s'"),
599 exit(BLKID_EXIT_OTHER
);
602 /* converts comma separated list to types[] */
603 static char **list_to_types(const char *list
, int *flag
)
606 const char *p
= list
;
609 if (p
&& strncmp(p
, "no", 2) == 0) {
610 *flag
= BLKID_FLTR_NOTIN
;
614 warnx(_("error: -u <list> argument is empty"));
617 for (i
= 1; p
&& (p
= strchr(p
, ',')); i
++, p
++);
619 res
= xcalloc(i
+ 1, sizeof(char *));
620 p
= *flag
& BLKID_FLTR_NOTIN
? list
+ 2 : list
;
624 const char *word
= p
;
626 res
[i
++] = p
? xstrndup(word
, p
- word
) : xstrdup(word
);
635 exit(BLKID_EXIT_OTHER
);
638 static void free_types_list(char *list
[])
644 for (n
= list
; *n
; n
++)
649 int main(int argc
, char **argv
)
651 struct blkid_control ctl
= { .output
= OUTPUT_FULL
, 0 };
652 blkid_cache cache
= NULL
;
653 char **devices
= NULL
;
654 char *search_type
= NULL
, *search_value
= NULL
;
657 char **fltr_type
= NULL
;
658 int fltr_flag
= BLKID_FLTR_ONLYIN
;
659 unsigned int numdev
= 0, numtag
= 0;
660 int err
= BLKID_EXIT_OTHER
;
664 static const struct option longopts
[] = {
665 { "cache-file", required_argument
, NULL
, 'c' },
666 { "no-encoding", no_argument
, NULL
, 'd' },
667 { "no-part-details", no_argument
, NULL
, 'D' },
668 { "garbage-collect", no_argument
, NULL
, 'g' },
669 { "output", required_argument
, NULL
, 'o' },
670 { "list-filesystems", no_argument
, NULL
, 'k' },
671 { "match-tag", required_argument
, NULL
, 's' },
672 { "match-token", required_argument
, NULL
, 't' },
673 { "list-one", no_argument
, NULL
, 'l' },
674 { "label", required_argument
, NULL
, 'L' },
675 { "uuid", required_argument
, NULL
, 'U' },
676 { "probe", no_argument
, NULL
, 'p' },
677 { "info", no_argument
, NULL
, 'i' },
678 { "size", required_argument
, NULL
, 'S' },
679 { "offset", required_argument
, NULL
, 'O' },
680 { "usages", required_argument
, NULL
, 'u' },
681 { "match-types", required_argument
, NULL
, 'n' },
682 { "version", no_argument
, NULL
, 'V' },
683 { "help", no_argument
, NULL
, 'h' },
687 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
691 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
693 setlocale(LC_ALL
, "");
694 bindtextdomain(PACKAGE
, LOCALEDIR
);
696 atexit(close_stdout
);
698 strutils_set_exitcode(BLKID_EXIT_OTHER
);
700 while ((c
= getopt_long (argc
, argv
,
701 "c:DdghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts
, NULL
)) != -1) {
703 err_exclusive_options(c
, NULL
, excl
, excl_st
);
713 ctl
.no_part_details
= 1;
717 search_value
= xstrdup(optarg
);
718 search_type
= xstrdup("LABEL");
721 fltr_type
= list_to_types(optarg
, &fltr_flag
);
724 fltr_usage
= list_to_usage(optarg
, &fltr_flag
);
728 search_value
= xstrdup(optarg
);
729 search_type
= xstrdup("UUID");
732 ctl
.lowprobe_topology
= 1;
743 const char *name
= NULL
;
745 while (blkid_superblocks_get_name(idx
++, &name
, NULL
) == 0)
746 printf("%s\n", name
);
750 if (!strcmp(optarg
, "value"))
751 ctl
.output
= OUTPUT_VALUE_ONLY
;
752 else if (!strcmp(optarg
, "device"))
753 ctl
.output
= OUTPUT_DEVICE_ONLY
;
754 else if (!strcmp(optarg
, "list"))
755 ctl
.output
= OUTPUT_PRETTY_LIST
; /* deprecated */
756 else if (!strcmp(optarg
, "udev"))
757 ctl
.output
= OUTPUT_UDEV_LIST
;
758 else if (!strcmp(optarg
, "export"))
759 ctl
.output
= OUTPUT_EXPORT_LIST
;
760 else if (!strcmp(optarg
, "full"))
763 errx(BLKID_EXIT_OTHER
, _("unsupported output format %s"), optarg
);
766 ctl
.offset
= strtosize_or_err(optarg
, _("invalid offset argument"));
769 ctl
.lowprobe_superblocks
= 1;
772 if (numtag
+ 1 >= sizeof(ctl
.show
) / sizeof(*ctl
.show
)) {
773 warnx(_("Too many tags specified"));
776 ctl
.show
[numtag
++] = optarg
;
779 ctl
.size
= strtosize_or_err(optarg
, _("invalid size argument"));
783 warnx(_("Can only search for "
784 "one NAME=value pair"));
787 if (blkid_parse_tag_string(optarg
,
790 warnx(_("-t needs NAME=value pair"));
796 print_version(stdout
);
800 /* ignore - backward compatibility */
806 errtryhelp(EXIT_FAILURE
);
810 if (ctl
.lowprobe_topology
|| ctl
.lowprobe_superblocks
)
813 /* The rest of the args are device names */
815 devices
= xcalloc(argc
- optind
, sizeof(char *));
816 while (optind
< argc
)
817 devices
[numdev
++] = argv
[optind
++];
820 /* convert LABEL/UUID lookup to evaluate request */
821 if (ctl
.lookup
&& ctl
.output
== OUTPUT_DEVICE_ONLY
&& search_type
&&
822 (!strcmp(search_type
, "LABEL") || !strcmp(search_type
, "UUID"))) {
827 if (!ctl
.lowprobe
&& !ctl
.eval
&& blkid_get_cache(&cache
, read
) < 0)
831 blkid_gc_cache(cache
);
835 err
= BLKID_EXIT_NOTFOUND
;
837 if (ctl
.eval
== 0 && (ctl
.output
& OUTPUT_PRETTY_LIST
)) {
839 errx(BLKID_EXIT_OTHER
,
840 _("The low-level probing mode does not "
841 "support 'list' output format"));
842 pretty_print_dev(NULL
);
852 errx(BLKID_EXIT_OTHER
,
853 _("The low-level probing mode "
854 "requires a device"));
856 /* automatically enable 'export' format for I/O Limits */
857 if (!ctl
.output
&& ctl
.lowprobe_topology
)
858 ctl
.output
= OUTPUT_EXPORT_LIST
;
860 pr
= blkid_new_probe();
864 if (ctl
.lowprobe_superblocks
) {
865 blkid_probe_set_superblocks_flags(pr
,
866 BLKID_SUBLKS_LABEL
| BLKID_SUBLKS_UUID
|
867 BLKID_SUBLKS_TYPE
| BLKID_SUBLKS_SECTYPE
|
868 BLKID_SUBLKS_USAGE
| BLKID_SUBLKS_VERSION
);
872 blkid_probe_filter_superblocks_usage(pr
, fltr_flag
, fltr_usage
))
875 else if (fltr_type
&&
876 blkid_probe_filter_superblocks_type(pr
, fltr_flag
, fltr_type
))
880 for (i
= 0; i
< numdev
; i
++) {
881 err
= lowprobe_device(pr
, devices
[i
], &ctl
);
885 blkid_free_probe(pr
);
886 } else if (ctl
.eval
) {
890 char *res
= blkid_evaluate_tag(search_type
, search_value
, NULL
);
895 } else if (ctl
.lookup
) {
897 * Classic (cache based) API
902 errx(BLKID_EXIT_OTHER
,
903 _("The lookup option requires a "
904 "search type specified using -t"));
905 /* Load any additional devices not in the cache */
906 for (i
= 0; i
< numdev
; i
++)
907 blkid_get_dev(cache
, devices
[i
], BLKID_DEV_NORMAL
);
909 if ((dev
= blkid_find_dev_with_tag(cache
, search_type
,
911 print_tags(&ctl
, dev
);
914 /* If we didn't specify a single device, show all available devices */
915 } else if (!numdev
) {
916 blkid_dev_iterate iter
;
919 blkid_probe_all(cache
);
921 iter
= blkid_dev_iterate_begin(cache
);
922 blkid_dev_set_search(iter
, search_type
, search_value
);
923 while (blkid_dev_next(iter
, &dev
) == 0) {
924 dev
= blkid_verify(cache
, dev
);
927 print_tags(&ctl
, dev
);
930 blkid_dev_iterate_end(iter
);
931 /* Add all specified devices to cache (optionally display tags) */
932 } else for (i
= 0; i
< numdev
; i
++) {
933 blkid_dev dev
= blkid_get_dev(cache
, devices
[i
],
938 !blkid_dev_has_tag(dev
, search_type
,
941 print_tags(&ctl
, dev
);
949 free_types_list(fltr_type
);
950 if (!ctl
.lowprobe
&& !ctl
.eval
)
951 blkid_put_cache(cache
);