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 __attribute__((__noreturn__
)) usage(void)
69 fputs(USAGE_HEADER
, out
);
70 fprintf(out
, _( " %s --label <label> | --uuid <uuid>\n\n"), program_invocation_short_name
);
71 fprintf(out
, _( " %s [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] \n"
72 " [--match-token <token>] [<dev> ...]\n\n"), program_invocation_short_name
);
73 fprintf(out
, _( " %s -p [--match-tag <tag>] [--offset <offset>] [--size <size>] \n"
74 " [--output <format>] <dev> ...\n\n"), program_invocation_short_name
);
75 fprintf(out
, _( " %s -i [--match-tag <tag>] [--output <format>] <dev> ...\n"), program_invocation_short_name
);
76 fputs(USAGE_OPTIONS
, out
);
77 fputs(_( " -c, --cache-file <file> read from <file> instead of reading from the default\n"
78 " cache file (-c /dev/null means no cache)\n"), out
);
79 fputs(_( " -d, --no-encoding don't encode non-printing characters\n"), out
);
80 fputs(_( " -g, --garbage-collect garbage collect the blkid cache\n"), out
);
81 fputs(_( " -o, --output <format> output format; can be one of:\n"
82 " value, device, export or full; (default: full)\n"), out
);
83 fputs(_( " -k, --list-filesystems list all known filesystems/RAIDs and exit\n"), out
);
84 fputs(_( " -s, --match-tag <tag> show specified tag(s) (default show all tags)\n"), out
);
85 fputs(_( " -t, --match-token <token> find device with a specific token (NAME=value pair)\n"), out
);
86 fputs(_( " -l, --list-one look up only first device with token specified by -t\n"), out
);
87 fputs(_( " -L, --label <label> convert LABEL to device name\n"), out
);
88 fputs(_( " -U, --uuid <uuid> convert UUID to device name\n"), out
);
89 fputs(_( " <dev> specify device(s) to probe (default: all devices)\n"), out
);
91 fputs(_( "Low-level probing options:\n"), out
);
92 fputs(_( " -p, --probe low-level superblocks probing (bypass cache)\n"), out
);
93 fputs(_( " -i, --info gather information about I/O limits\n"), out
);
94 fputs(_( " -S, --size <size> overwrite device size\n"), out
);
95 fputs(_( " -O, --offset <offset> probe at the given offset\n"), out
);
96 fputs(_( " -u, --usages <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"), out
);
97 fputs(_( " -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3)\n"), out
);
98 fputs(_( " -D, --no-part-details don't print info from partition table\n"), out
);
100 fputs(USAGE_SEPARATOR
, out
);
101 printf(USAGE_HELP_OPTIONS(28));
102 printf(USAGE_MAN_TAIL("blkid(8)"));
107 * This function does "safe" printing. It will convert non-printable
108 * ASCII characters using '^' and M- notation.
110 * If 'esc' is defined then escape all chars from esc by \.
112 static void safe_print(const struct blkid_control
*ctl
, const char *cp
, int len
,
122 if (!ctl
->raw_chars
) {
127 if ((ch
< 32) || (ch
== 0x7f)) {
129 ch
^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
131 } else if (esc
&& strchr(esc
, ch
))
138 static int pretty_print_word(const char *str
, int max_len
,
139 int left_len
, int overflow_nl
)
141 int len
= strlen(str
) + left_len
;
145 if (overflow_nl
&& len
> max_len
) {
148 } else if (len
> max_len
)
152 } while (len
++ < max_len
);
156 static void pretty_print_line(const char *device
, const char *fs_type
,
157 const char *label
, const char *mtpt
,
160 static int device_len
= 10, fs_type_len
= 7;
161 static int label_len
= 8, mtpt_len
= 14;
162 static int term_width
= -1;
165 if (term_width
< 0) {
166 term_width
= get_terminal_width(80);
168 if (term_width
> 80) {
181 len
= pretty_print_word(device
, device_len
, 0, 1);
182 len
= pretty_print_word(fs_type
, fs_type_len
, len
, 0);
183 len
= pretty_print_word(label
, label_len
, len
, 0);
184 pretty_print_word(mtpt
, mtpt_len
, len
, 0);
190 static void pretty_print_dev(blkid_dev dev
)
192 blkid_tag_iterate iter
;
193 const char *type
, *value
, *devname
;
194 const char *uuid
= "", *fs_type
= "", *label
= "";
195 int len
, mount_flags
;
200 pretty_print_line("device", "fs_type", "label",
201 "mount point", "UUID");
202 for (len
=get_terminal_width(0)-1; len
> 0; len
--)
208 devname
= blkid_dev_devname(dev
);
209 if (access(devname
, F_OK
))
212 /* Get the uuid, label, type */
213 iter
= blkid_tag_iterate_begin(dev
);
214 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
215 if (!strcmp(type
, "UUID"))
217 if (!strcmp(type
, "TYPE"))
219 if (!strcmp(type
, "LABEL"))
222 blkid_tag_iterate_end(iter
);
224 /* Get the mount point */
226 retval
= check_mount_point(devname
, &mount_flags
, mtpt
, sizeof(mtpt
));
228 if (mount_flags
& MF_MOUNTED
) {
230 strcpy(mtpt
, _("(mounted, mtpt unknown)"));
231 } else if (mount_flags
& MF_BUSY
)
232 strcpy(mtpt
, _("(in use)"));
234 strcpy(mtpt
, _("(not mounted)"));
237 pretty_print_line(devname
, fs_type
, label
, mtpt
, uuid
);
240 static void print_udev_format(const char *name
, const char *value
)
242 char enc
[265], safe
[256];
243 size_t namelen
= strlen(name
);
247 if (!strcmp(name
, "TYPE") || !strcmp(name
, "VERSION")) {
248 blkid_encode_string(value
, enc
, sizeof(enc
));
249 printf("ID_FS_%s=%s\n", name
, enc
);
251 } else if (!strcmp(name
, "UUID") ||
252 !strncmp(name
, "LABEL", 5) ||
253 !strcmp(name
, "UUID_SUB")) {
255 blkid_safe_string(value
, safe
, sizeof(safe
));
256 printf("ID_FS_%s=%s\n", name
, safe
);
258 blkid_encode_string(value
, enc
, sizeof(enc
));
259 printf("ID_FS_%s_ENC=%s\n", name
, enc
);
261 } else if (!strcmp(name
, "PTUUID")) {
262 printf("ID_PART_TABLE_UUID=%s\n", value
);
264 } else if (!strcmp(name
, "PTTYPE")) {
265 printf("ID_PART_TABLE_TYPE=%s\n", value
);
267 } else if (!strcmp(name
, "PART_ENTRY_NAME") ||
268 !strcmp(name
, "PART_ENTRY_TYPE")) {
270 blkid_encode_string(value
, enc
, sizeof(enc
));
271 printf("ID_%s=%s\n", name
, enc
);
273 } else if (!strncmp(name
, "PART_ENTRY_", 11))
274 printf("ID_%s=%s\n", name
, value
);
276 else if (namelen
>= 15 && (
277 !strcmp(name
+ (namelen
- 12), "_SECTOR_SIZE") ||
278 !strcmp(name
+ (namelen
- 8), "_IO_SIZE") ||
279 !strcmp(name
, "ALIGNMENT_OFFSET")))
280 printf("ID_IOLIMIT_%s=%s\n", name
, value
);
282 printf("ID_FS_%s=%s\n", name
, value
);
285 static int has_item(const struct blkid_control
*ctl
, const char *item
)
289 for (p
= ctl
->show
; *p
!= NULL
; p
++)
290 if (!strcmp(item
, *p
))
295 static void print_value(const struct blkid_control
*ctl
, int num
,
296 const char *devname
, const char *value
,
297 const char *name
, size_t valsz
)
299 if (ctl
->output
& OUTPUT_VALUE_ONLY
) {
300 fputs(value
, stdout
);
303 } else if (ctl
->output
& OUTPUT_UDEV_LIST
) {
304 print_udev_format(name
, value
);
306 } else if (ctl
->output
& OUTPUT_EXPORT_LIST
) {
307 if (num
== 1 && devname
)
308 printf("DEVNAME=%s\n", devname
);
311 safe_print(ctl
, value
, valsz
, " \\\"'$`<>");
315 if (num
== 1 && devname
)
316 printf("%s:", devname
);
319 fputs("=\"", stdout
);
320 safe_print(ctl
, value
, valsz
, "\"\\");
325 static void print_tags(const struct blkid_control
*ctl
, blkid_dev dev
)
327 blkid_tag_iterate iter
;
328 const char *type
, *value
, *devname
;
330 static int first
= 1;
335 if (ctl
->output
& OUTPUT_PRETTY_LIST
) {
336 pretty_print_dev(dev
);
340 devname
= blkid_dev_devname(dev
);
342 if (ctl
->output
& OUTPUT_DEVICE_ONLY
) {
343 printf("%s\n", devname
);
347 iter
= blkid_tag_iterate_begin(dev
);
348 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
349 if (ctl
->show
[0] && !has_item(ctl
, type
))
352 if (num
== 1 && !first
&&
353 (ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
354 /* add extra line between output from more devices */
357 print_value(ctl
, num
++, devname
, value
, type
, strlen(value
));
359 blkid_tag_iterate_end(iter
);
362 if (!(ctl
->output
& (OUTPUT_VALUE_ONLY
| OUTPUT_UDEV_LIST
|
363 OUTPUT_EXPORT_LIST
)))
370 static int append_str(char **res
, size_t *sz
, const char *a
, const char *b
)
373 size_t asz
= a
? strlen(a
) : 0;
374 size_t bsz
= b
? strlen(b
) : 0;
375 size_t len
= *sz
+ asz
+ bsz
;
380 *res
= str
= xrealloc(str
, len
+ 1);
397 * Compose and print ID_FS_AMBIVALENT for udev
399 static int print_udev_ambivalent(blkid_probe pr
)
403 int count
= 0, rc
= -1;
405 while (!blkid_do_probe(pr
)) {
406 const char *usage_txt
= NULL
, *type
= NULL
, *version
= NULL
;
409 blkid_probe_lookup_value(pr
, "USAGE", &usage_txt
, NULL
);
410 blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
);
411 blkid_probe_lookup_value(pr
, "VERSION", &version
, NULL
);
413 if (!usage_txt
|| !type
)
416 blkid_encode_string(usage_txt
, enc
, sizeof(enc
));
417 if (append_str(&val
, &valsz
, enc
, ":"))
420 blkid_encode_string(type
, enc
, sizeof(enc
));
421 if (append_str(&val
, &valsz
, enc
, version
? ":" : " "))
425 blkid_encode_string(version
, enc
, sizeof(enc
));
426 if (append_str(&val
, &valsz
, enc
, " "))
433 *(val
+ valsz
- 1) = '\0'; /* rem tailing whitespace */
434 printf("ID_FS_AMBIVALENT=%s\n", val
);
442 static int lowprobe_superblocks(blkid_probe pr
, struct blkid_control
*ctl
)
445 int rc
, fd
= blkid_probe_get_fd(pr
);
447 if (fd
< 0 || fstat(fd
, &st
))
450 blkid_probe_enable_partitions(pr
, 1);
452 if (!S_ISCHR(st
.st_mode
) && blkid_probe_get_size(pr
) <= 1024 * 1440 &&
453 blkid_probe_is_wholedisk(pr
)) {
455 * check if the small disk is partitioned, if yes then
456 * don't probe for filesystems.
458 blkid_probe_enable_superblocks(pr
, 0);
460 rc
= blkid_do_fullprobe(pr
);
462 return rc
; /* -1 = error, 1 = nothing, 0 = success */
464 if (blkid_probe_lookup_value(pr
, "PTTYPE", NULL
, NULL
) == 0)
465 return 0; /* partition table detected */
468 if (!ctl
->no_part_details
)
469 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
470 blkid_probe_enable_superblocks(pr
, 1);
472 return blkid_do_safeprobe(pr
);
475 static int lowprobe_topology(blkid_probe pr
)
477 /* enable topology probing only */
478 blkid_probe_enable_topology(pr
, 1);
480 blkid_probe_enable_superblocks(pr
, 0);
481 blkid_probe_enable_partitions(pr
, 0);
483 return blkid_do_fullprobe(pr
);
486 static int lowprobe_device(blkid_probe pr
, const char *devname
,
487 struct blkid_control
*ctl
)
491 int nvals
= 0, n
, num
= 1;
495 static int first
= 1;
497 fd
= open(devname
, O_RDONLY
|O_CLOEXEC
);
499 warn(_("error: %s"), devname
);
500 return BLKID_EXIT_NOTFOUND
;
502 if (blkid_probe_set_device(pr
, fd
, ctl
->offset
, ctl
->size
))
505 if (ctl
->lowprobe_topology
)
506 rc
= lowprobe_topology(pr
);
507 if (rc
>= 0 && ctl
->lowprobe_superblocks
)
508 rc
= lowprobe_superblocks(pr
, ctl
);
513 nvals
= blkid_probe_numof_values(pr
);
515 if (nvals
&& !first
&& ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
))
516 /* add extra line between output from devices */
519 if (nvals
&& (ctl
->output
& OUTPUT_DEVICE_ONLY
)) {
520 printf("%s\n", devname
);
524 for (n
= 0; n
< nvals
; n
++) {
525 if (blkid_probe_get_value(pr
, n
, &name
, &data
, &len
))
527 if (ctl
->show
[0] && !has_item(ctl
, name
))
529 len
= strnlen(data
, len
);
530 print_value(ctl
, num
++, devname
, data
, name
, len
);
536 if (nvals
>= 1 && !(ctl
->output
& (OUTPUT_VALUE_ONLY
|
537 OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
541 if (ctl
->output
& OUTPUT_UDEV_LIST
)
542 print_udev_ambivalent(pr
);
544 warnx(_("%s: ambivalent result (probably more "
545 "filesystems on the device, use wipefs(8) "
546 "to see more details)"),
552 return BLKID_EXIT_AMBIVAL
; /* ambivalent probing result */
554 return BLKID_EXIT_NOTFOUND
; /* nothing detected */
556 return 0; /* success */
559 /* converts comma separated list to BLKID_USAGE_* mask */
560 static int list_to_usage(const char *list
, int *flag
)
563 const char *word
= NULL
, *p
= list
;
565 if (p
&& strncmp(p
, "no", 2) == 0) {
566 *flag
= BLKID_FLTR_NOTIN
;
576 if (!strncmp(word
, "filesystem", 10))
577 mask
|= BLKID_USAGE_FILESYSTEM
;
578 else if (!strncmp(word
, "raid", 4))
579 mask
|= BLKID_USAGE_RAID
;
580 else if (!strncmp(word
, "crypto", 6))
581 mask
|= BLKID_USAGE_CRYPTO
;
582 else if (!strncmp(word
, "other", 5))
583 mask
|= BLKID_USAGE_OTHER
;
590 warnx(_("unknown keyword in -u <list> argument: '%s'"),
592 exit(BLKID_EXIT_OTHER
);
595 /* converts comma separated list to types[] */
596 static char **list_to_types(const char *list
, int *flag
)
599 const char *p
= list
;
602 if (p
&& strncmp(p
, "no", 2) == 0) {
603 *flag
= BLKID_FLTR_NOTIN
;
607 warnx(_("error: -u <list> argument is empty"));
610 for (i
= 1; p
&& (p
= strchr(p
, ',')); i
++, p
++);
612 res
= xcalloc(i
+ 1, sizeof(char *));
613 p
= *flag
& BLKID_FLTR_NOTIN
? list
+ 2 : list
;
617 const char *word
= p
;
619 res
[i
++] = p
? xstrndup(word
, p
- word
) : xstrdup(word
);
628 exit(BLKID_EXIT_OTHER
);
631 static void free_types_list(char *list
[])
637 for (n
= list
; *n
; n
++)
642 int main(int argc
, char **argv
)
644 struct blkid_control ctl
= { .output
= OUTPUT_FULL
, 0 };
645 blkid_cache cache
= NULL
;
646 char **devices
= NULL
;
647 char *search_type
= NULL
, *search_value
= NULL
;
650 char **fltr_type
= NULL
;
651 int fltr_flag
= BLKID_FLTR_ONLYIN
;
652 unsigned int numdev
= 0, numtag
= 0;
653 int err
= BLKID_EXIT_OTHER
;
657 static const struct option longopts
[] = {
658 { "cache-file", required_argument
, NULL
, 'c' },
659 { "no-encoding", no_argument
, NULL
, 'd' },
660 { "no-part-details", no_argument
, NULL
, 'D' },
661 { "garbage-collect", no_argument
, NULL
, 'g' },
662 { "output", required_argument
, NULL
, 'o' },
663 { "list-filesystems", no_argument
, NULL
, 'k' },
664 { "match-tag", required_argument
, NULL
, 's' },
665 { "match-token", required_argument
, NULL
, 't' },
666 { "list-one", no_argument
, NULL
, 'l' },
667 { "label", required_argument
, NULL
, 'L' },
668 { "uuid", required_argument
, NULL
, 'U' },
669 { "probe", no_argument
, NULL
, 'p' },
670 { "info", no_argument
, NULL
, 'i' },
671 { "size", required_argument
, NULL
, 'S' },
672 { "offset", required_argument
, NULL
, 'O' },
673 { "usages", required_argument
, NULL
, 'u' },
674 { "match-types", required_argument
, NULL
, 'n' },
675 { "version", no_argument
, NULL
, 'V' },
676 { "help", no_argument
, NULL
, 'h' },
680 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
684 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
686 setlocale(LC_ALL
, "");
687 bindtextdomain(PACKAGE
, LOCALEDIR
);
689 close_stdout_atexit();
691 strutils_set_exitcode(BLKID_EXIT_OTHER
);
693 while ((c
= getopt_long (argc
, argv
,
694 "c:DdghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts
, NULL
)) != -1) {
696 err_exclusive_options(c
, NULL
, excl
, excl_st
);
706 ctl
.no_part_details
= 1;
710 search_value
= xstrdup(optarg
);
711 search_type
= xstrdup("LABEL");
714 fltr_type
= list_to_types(optarg
, &fltr_flag
);
717 fltr_usage
= list_to_usage(optarg
, &fltr_flag
);
721 search_value
= xstrdup(optarg
);
722 search_type
= xstrdup("UUID");
725 ctl
.lowprobe_topology
= 1;
736 const char *name
= NULL
;
738 while (blkid_superblocks_get_name(idx
++, &name
, NULL
) == 0)
739 printf("%s\n", name
);
743 if (!strcmp(optarg
, "value"))
744 ctl
.output
= OUTPUT_VALUE_ONLY
;
745 else if (!strcmp(optarg
, "device"))
746 ctl
.output
= OUTPUT_DEVICE_ONLY
;
747 else if (!strcmp(optarg
, "list"))
748 ctl
.output
= OUTPUT_PRETTY_LIST
; /* deprecated */
749 else if (!strcmp(optarg
, "udev"))
750 ctl
.output
= OUTPUT_UDEV_LIST
;
751 else if (!strcmp(optarg
, "export"))
752 ctl
.output
= OUTPUT_EXPORT_LIST
;
753 else if (!strcmp(optarg
, "full"))
756 errx(BLKID_EXIT_OTHER
, _("unsupported output format %s"), optarg
);
759 ctl
.offset
= strtosize_or_err(optarg
, _("invalid offset argument"));
762 ctl
.lowprobe_superblocks
= 1;
765 if (numtag
+ 1 >= sizeof(ctl
.show
) / sizeof(*ctl
.show
)) {
766 warnx(_("Too many tags specified"));
769 ctl
.show
[numtag
++] = optarg
;
772 ctl
.size
= strtosize_or_err(optarg
, _("invalid size argument"));
776 warnx(_("Can only search for "
777 "one NAME=value pair"));
780 if (blkid_parse_tag_string(optarg
,
783 warnx(_("-t needs NAME=value pair"));
789 fprintf(stdout
, _("%s from %s (libblkid %s, %s)\n"),
790 program_invocation_short_name
, PACKAGE_STRING
,
791 LIBBLKID_VERSION
, LIBBLKID_DATE
);
795 /* ignore - backward compatibility */
801 errtryhelp(EXIT_FAILURE
);
805 if (ctl
.lowprobe_topology
|| ctl
.lowprobe_superblocks
)
808 /* The rest of the args are device names */
810 devices
= xcalloc(argc
- optind
, sizeof(char *));
811 while (optind
< argc
)
812 devices
[numdev
++] = argv
[optind
++];
815 /* convert LABEL/UUID lookup to evaluate request */
816 if (ctl
.lookup
&& ctl
.output
== OUTPUT_DEVICE_ONLY
&& search_type
&&
817 (!strcmp(search_type
, "LABEL") || !strcmp(search_type
, "UUID"))) {
822 if (!ctl
.lowprobe
&& !ctl
.eval
&& blkid_get_cache(&cache
, read
) < 0)
826 blkid_gc_cache(cache
);
830 err
= BLKID_EXIT_NOTFOUND
;
832 if (ctl
.eval
== 0 && (ctl
.output
& OUTPUT_PRETTY_LIST
)) {
834 errx(BLKID_EXIT_OTHER
,
835 _("The low-level probing mode does not "
836 "support 'list' output format"));
837 pretty_print_dev(NULL
);
847 errx(BLKID_EXIT_OTHER
,
848 _("The low-level probing mode "
849 "requires a device"));
851 /* automatically enable 'export' format for I/O Limits */
852 if (!ctl
.output
&& ctl
.lowprobe_topology
)
853 ctl
.output
= OUTPUT_EXPORT_LIST
;
855 pr
= blkid_new_probe();
859 if (ctl
.lowprobe_superblocks
) {
860 blkid_probe_set_superblocks_flags(pr
,
861 BLKID_SUBLKS_LABEL
| BLKID_SUBLKS_UUID
|
862 BLKID_SUBLKS_TYPE
| BLKID_SUBLKS_SECTYPE
|
863 BLKID_SUBLKS_USAGE
| BLKID_SUBLKS_VERSION
);
867 blkid_probe_filter_superblocks_usage(pr
, fltr_flag
, fltr_usage
))
870 else if (fltr_type
&&
871 blkid_probe_filter_superblocks_type(pr
, fltr_flag
, fltr_type
))
875 for (i
= 0; i
< numdev
; i
++) {
876 err
= lowprobe_device(pr
, devices
[i
], &ctl
);
880 blkid_free_probe(pr
);
881 } else if (ctl
.eval
) {
885 char *res
= blkid_evaluate_tag(search_type
, search_value
, NULL
);
890 } else if (ctl
.lookup
) {
892 * Classic (cache based) API
897 errx(BLKID_EXIT_OTHER
,
898 _("The lookup option requires a "
899 "search type specified using -t"));
900 /* Load any additional devices not in the cache */
901 for (i
= 0; i
< numdev
; i
++)
902 blkid_get_dev(cache
, devices
[i
], BLKID_DEV_NORMAL
);
904 if ((dev
= blkid_find_dev_with_tag(cache
, search_type
,
906 print_tags(&ctl
, dev
);
909 /* If we didn't specify a single device, show all available devices */
910 } else if (!numdev
) {
911 blkid_dev_iterate iter
;
914 blkid_probe_all(cache
);
916 iter
= blkid_dev_iterate_begin(cache
);
917 blkid_dev_set_search(iter
, search_type
, search_value
);
918 while (blkid_dev_next(iter
, &dev
) == 0) {
919 dev
= blkid_verify(cache
, dev
);
922 print_tags(&ctl
, dev
);
925 blkid_dev_iterate_end(iter
);
926 /* Add all specified devices to cache (optionally display tags) */
927 } else for (i
= 0; i
< numdev
; i
++) {
928 blkid_dev dev
= blkid_get_dev(cache
, devices
[i
],
933 !blkid_dev_has_tag(dev
, search_type
,
936 print_tags(&ctl
, dev
);
944 free_types_list(fltr_type
);
945 if (!ctl
.lowprobe
&& !ctl
.eval
)
946 blkid_put_cache(cache
);