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 const char *msg
= NULL
;
230 if (mount_flags
& MF_MOUNTED
) {
232 msg
= _("(mounted, mtpt unknown)");
233 } else if (mount_flags
& MF_BUSY
)
236 msg
= _("(not mounted)");
239 xstrncpy(mtpt
, msg
, sizeof(mtpt
));
242 pretty_print_line(devname
, fs_type
, label
, mtpt
, uuid
);
245 static void print_udev_format(const char *name
, const char *value
)
247 char enc
[265], safe
[256];
248 size_t namelen
= strlen(name
);
252 if (!strcmp(name
, "TYPE") || !strcmp(name
, "VERSION")) {
253 blkid_encode_string(value
, enc
, sizeof(enc
));
254 printf("ID_FS_%s=%s\n", name
, enc
);
256 } else if (!strcmp(name
, "UUID") ||
257 !strncmp(name
, "LABEL", 5) ||
258 !strcmp(name
, "UUID_SUB")) {
260 blkid_safe_string(value
, safe
, sizeof(safe
));
261 printf("ID_FS_%s=%s\n", name
, safe
);
263 blkid_encode_string(value
, enc
, sizeof(enc
));
264 printf("ID_FS_%s_ENC=%s\n", name
, enc
);
266 } else if (!strcmp(name
, "PTUUID")) {
267 printf("ID_PART_TABLE_UUID=%s\n", value
);
269 } else if (!strcmp(name
, "PTTYPE")) {
270 printf("ID_PART_TABLE_TYPE=%s\n", value
);
272 } else if (!strcmp(name
, "PART_ENTRY_NAME") ||
273 !strcmp(name
, "PART_ENTRY_TYPE")) {
275 blkid_encode_string(value
, enc
, sizeof(enc
));
276 printf("ID_%s=%s\n", name
, enc
);
278 } else if (!strncmp(name
, "PART_ENTRY_", 11))
279 printf("ID_%s=%s\n", name
, value
);
281 else if (namelen
>= 15 && (
282 !strcmp(name
+ (namelen
- 12), "_SECTOR_SIZE") ||
283 !strcmp(name
+ (namelen
- 8), "_IO_SIZE") ||
284 !strcmp(name
, "ALIGNMENT_OFFSET")))
285 printf("ID_IOLIMIT_%s=%s\n", name
, value
);
287 printf("ID_FS_%s=%s\n", name
, value
);
290 static int has_item(const struct blkid_control
*ctl
, const char *item
)
294 for (p
= ctl
->show
; *p
!= NULL
; p
++)
295 if (!strcmp(item
, *p
))
300 static void print_value(const struct blkid_control
*ctl
, int num
,
301 const char *devname
, const char *value
,
302 const char *name
, size_t valsz
)
304 if (ctl
->output
& OUTPUT_VALUE_ONLY
) {
305 fputs(value
, stdout
);
308 } else if (ctl
->output
& OUTPUT_UDEV_LIST
) {
309 print_udev_format(name
, value
);
311 } else if (ctl
->output
& OUTPUT_EXPORT_LIST
) {
312 if (num
== 1 && devname
)
313 printf("DEVNAME=%s\n", devname
);
316 safe_print(ctl
, value
, valsz
, " \\\"'$`<>");
320 if (num
== 1 && devname
)
321 printf("%s:", devname
);
324 fputs("=\"", stdout
);
325 safe_print(ctl
, value
, valsz
, "\"\\");
330 static void print_tags(const struct blkid_control
*ctl
, blkid_dev dev
)
332 blkid_tag_iterate iter
;
333 const char *type
, *value
, *devname
;
335 static int first
= 1;
340 if (ctl
->output
& OUTPUT_PRETTY_LIST
) {
341 pretty_print_dev(dev
);
345 devname
= blkid_dev_devname(dev
);
347 if (ctl
->output
& OUTPUT_DEVICE_ONLY
) {
348 printf("%s\n", devname
);
352 iter
= blkid_tag_iterate_begin(dev
);
353 while (blkid_tag_next(iter
, &type
, &value
) == 0) {
354 if (ctl
->show
[0] && !has_item(ctl
, type
))
357 if (num
== 1 && !first
&&
358 (ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
359 /* add extra line between output from more devices */
362 print_value(ctl
, num
++, devname
, value
, type
, strlen(value
));
364 blkid_tag_iterate_end(iter
);
367 if (!(ctl
->output
& (OUTPUT_VALUE_ONLY
| OUTPUT_UDEV_LIST
|
368 OUTPUT_EXPORT_LIST
)))
375 static int append_str(char **res
, size_t *sz
, const char *a
, const char *b
)
378 size_t asz
= a
? strlen(a
) : 0;
379 size_t bsz
= b
? strlen(b
) : 0;
380 size_t len
= *sz
+ asz
+ bsz
;
385 *res
= str
= xrealloc(str
, len
+ 1);
402 * Compose and print ID_FS_AMBIVALENT for udev
404 static int print_udev_ambivalent(blkid_probe pr
)
408 int count
= 0, rc
= -1;
410 while (!blkid_do_probe(pr
)) {
411 const char *usage_txt
= NULL
, *type
= NULL
, *version
= NULL
;
414 blkid_probe_lookup_value(pr
, "USAGE", &usage_txt
, NULL
);
415 blkid_probe_lookup_value(pr
, "TYPE", &type
, NULL
);
416 blkid_probe_lookup_value(pr
, "VERSION", &version
, NULL
);
418 if (!usage_txt
|| !type
)
421 blkid_encode_string(usage_txt
, enc
, sizeof(enc
));
422 if (append_str(&val
, &valsz
, enc
, ":"))
425 blkid_encode_string(type
, enc
, sizeof(enc
));
426 if (append_str(&val
, &valsz
, enc
, version
? ":" : " "))
430 blkid_encode_string(version
, enc
, sizeof(enc
));
431 if (append_str(&val
, &valsz
, enc
, " "))
438 *(val
+ valsz
- 1) = '\0'; /* rem tailing whitespace */
439 printf("ID_FS_AMBIVALENT=%s\n", val
);
447 static int lowprobe_superblocks(blkid_probe pr
, struct blkid_control
*ctl
)
450 int rc
, fd
= blkid_probe_get_fd(pr
);
452 if (fd
< 0 || fstat(fd
, &st
))
455 blkid_probe_enable_partitions(pr
, 1);
457 if (!S_ISCHR(st
.st_mode
) && blkid_probe_get_size(pr
) <= 1024 * 1440 &&
458 blkid_probe_is_wholedisk(pr
)) {
460 * check if the small disk is partitioned, if yes then
461 * don't probe for filesystems.
463 blkid_probe_enable_superblocks(pr
, 0);
465 rc
= blkid_do_fullprobe(pr
);
467 return rc
; /* -1 = error, 1 = nothing, 0 = success */
469 if (blkid_probe_lookup_value(pr
, "PTTYPE", NULL
, NULL
) == 0)
470 return 0; /* partition table detected */
473 if (!ctl
->no_part_details
)
474 blkid_probe_set_partitions_flags(pr
, BLKID_PARTS_ENTRY_DETAILS
);
475 blkid_probe_enable_superblocks(pr
, 1);
477 return blkid_do_safeprobe(pr
);
480 static int lowprobe_topology(blkid_probe pr
)
482 /* enable topology probing only */
483 blkid_probe_enable_topology(pr
, 1);
485 blkid_probe_enable_superblocks(pr
, 0);
486 blkid_probe_enable_partitions(pr
, 0);
488 return blkid_do_fullprobe(pr
);
491 static int lowprobe_device(blkid_probe pr
, const char *devname
,
492 struct blkid_control
*ctl
)
496 int nvals
= 0, n
, num
= 1;
500 static int first
= 1;
502 fd
= open(devname
, O_RDONLY
|O_CLOEXEC
|O_NONBLOCK
);
504 warn(_("error: %s"), devname
);
505 return BLKID_EXIT_NOTFOUND
;
508 if (blkid_probe_set_device(pr
, fd
, ctl
->offset
, ctl
->size
)) {
510 warn(_("error: %s"), devname
);
514 if (ctl
->lowprobe_topology
)
515 rc
= lowprobe_topology(pr
);
516 if (rc
>= 0 && ctl
->lowprobe_superblocks
)
517 rc
= lowprobe_superblocks(pr
, ctl
);
522 nvals
= blkid_probe_numof_values(pr
);
524 if (nvals
&& !first
&& ctl
->output
& (OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
))
525 /* add extra line between output from devices */
528 if (nvals
&& (ctl
->output
& OUTPUT_DEVICE_ONLY
)) {
529 printf("%s\n", devname
);
533 for (n
= 0; n
< nvals
; n
++) {
534 if (blkid_probe_get_value(pr
, n
, &name
, &data
, &len
))
536 if (ctl
->show
[0] && !has_item(ctl
, name
))
538 len
= strnlen(data
, len
);
539 print_value(ctl
, num
++, devname
, data
, name
, len
);
545 if (nvals
>= 1 && !(ctl
->output
& (OUTPUT_VALUE_ONLY
|
546 OUTPUT_UDEV_LIST
| OUTPUT_EXPORT_LIST
)))
550 if (ctl
->output
& OUTPUT_UDEV_LIST
)
551 print_udev_ambivalent(pr
);
553 warnx(_("%s: ambivalent result (probably more "
554 "filesystems on the device, use wipefs(8) "
555 "to see more details)"),
561 return BLKID_EXIT_AMBIVAL
; /* ambivalent probing result */
563 return BLKID_EXIT_NOTFOUND
; /* nothing detected */
565 return 0; /* success */
568 /* converts comma separated list to BLKID_USAGE_* mask */
569 static int list_to_usage(const char *list
, int *flag
)
572 const char *word
= NULL
, *p
= list
;
574 if (p
&& strncmp(p
, "no", 2) == 0) {
575 *flag
= BLKID_FLTR_NOTIN
;
585 if (!strncmp(word
, "filesystem", 10))
586 mask
|= BLKID_USAGE_FILESYSTEM
;
587 else if (!strncmp(word
, "raid", 4))
588 mask
|= BLKID_USAGE_RAID
;
589 else if (!strncmp(word
, "crypto", 6))
590 mask
|= BLKID_USAGE_CRYPTO
;
591 else if (!strncmp(word
, "other", 5))
592 mask
|= BLKID_USAGE_OTHER
;
599 warnx(_("unknown keyword in -u <list> argument: '%s'"),
601 exit(BLKID_EXIT_OTHER
);
604 /* converts comma separated list to types[] */
605 static char **list_to_types(const char *list
, int *flag
)
608 const char *p
= list
;
611 if (p
&& strncmp(p
, "no", 2) == 0) {
612 *flag
= BLKID_FLTR_NOTIN
;
616 warnx(_("error: -u <list> argument is empty"));
619 for (i
= 1; p
&& (p
= strchr(p
, ',')); i
++, p
++);
621 res
= xcalloc(i
+ 1, sizeof(char *));
622 p
= *flag
& BLKID_FLTR_NOTIN
? list
+ 2 : list
;
626 const char *word
= p
;
628 res
[i
++] = p
? xstrndup(word
, p
- word
) : xstrdup(word
);
637 exit(BLKID_EXIT_OTHER
);
640 static void free_types_list(char *list
[])
646 for (n
= list
; *n
; n
++)
651 int main(int argc
, char **argv
)
653 struct blkid_control ctl
= { .output
= OUTPUT_FULL
, 0 };
654 blkid_cache cache
= NULL
;
655 char **devices
= NULL
;
656 char *search_type
= NULL
, *search_value
= NULL
;
659 char **fltr_type
= NULL
;
660 int fltr_flag
= BLKID_FLTR_ONLYIN
;
661 unsigned int numdev
= 0, numtag
= 0;
662 int err
= BLKID_EXIT_OTHER
;
666 static const struct option longopts
[] = {
667 { "cache-file", required_argument
, NULL
, 'c' },
668 { "no-encoding", no_argument
, NULL
, 'd' },
669 { "no-part-details", no_argument
, NULL
, 'D' },
670 { "garbage-collect", no_argument
, NULL
, 'g' },
671 { "output", required_argument
, NULL
, 'o' },
672 { "list-filesystems", no_argument
, NULL
, 'k' },
673 { "match-tag", required_argument
, NULL
, 's' },
674 { "match-token", required_argument
, NULL
, 't' },
675 { "list-one", no_argument
, NULL
, 'l' },
676 { "label", required_argument
, NULL
, 'L' },
677 { "uuid", required_argument
, NULL
, 'U' },
678 { "probe", no_argument
, NULL
, 'p' },
679 { "info", no_argument
, NULL
, 'i' },
680 { "size", required_argument
, NULL
, 'S' },
681 { "offset", required_argument
, NULL
, 'O' },
682 { "usages", required_argument
, NULL
, 'u' },
683 { "match-types", required_argument
, NULL
, 'n' },
684 { "version", no_argument
, NULL
, 'V' },
685 { "help", no_argument
, NULL
, 'h' },
689 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
693 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
695 setlocale(LC_ALL
, "");
696 bindtextdomain(PACKAGE
, LOCALEDIR
);
698 close_stdout_atexit();
700 strutils_set_exitcode(BLKID_EXIT_OTHER
);
702 while ((c
= getopt_long (argc
, argv
,
703 "c:DdghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts
, NULL
)) != -1) {
705 err_exclusive_options(c
, NULL
, excl
, excl_st
);
715 ctl
.no_part_details
= 1;
719 search_value
= xstrdup(optarg
);
720 search_type
= xstrdup("LABEL");
723 fltr_type
= list_to_types(optarg
, &fltr_flag
);
726 fltr_usage
= list_to_usage(optarg
, &fltr_flag
);
730 search_value
= xstrdup(optarg
);
731 search_type
= xstrdup("UUID");
734 ctl
.lowprobe_topology
= 1;
745 const char *name
= NULL
;
747 while (blkid_superblocks_get_name(idx
++, &name
, NULL
) == 0)
748 printf("%s\n", name
);
752 if (!strcmp(optarg
, "value"))
753 ctl
.output
= OUTPUT_VALUE_ONLY
;
754 else if (!strcmp(optarg
, "device"))
755 ctl
.output
= OUTPUT_DEVICE_ONLY
;
756 else if (!strcmp(optarg
, "list"))
757 ctl
.output
= OUTPUT_PRETTY_LIST
; /* deprecated */
758 else if (!strcmp(optarg
, "udev"))
759 ctl
.output
= OUTPUT_UDEV_LIST
;
760 else if (!strcmp(optarg
, "export"))
761 ctl
.output
= OUTPUT_EXPORT_LIST
;
762 else if (!strcmp(optarg
, "full"))
765 errx(BLKID_EXIT_OTHER
, _("unsupported output format %s"), optarg
);
768 ctl
.offset
= strtosize_or_err(optarg
, _("invalid offset argument"));
771 ctl
.lowprobe_superblocks
= 1;
774 if (numtag
+ 1 >= sizeof(ctl
.show
) / sizeof(*ctl
.show
)) {
775 warnx(_("Too many tags specified"));
778 ctl
.show
[numtag
++] = optarg
;
781 ctl
.size
= strtosize_or_err(optarg
, _("invalid size argument"));
785 warnx(_("Can only search for "
786 "one NAME=value pair"));
789 if (blkid_parse_tag_string(optarg
,
792 warnx(_("-t needs NAME=value pair"));
798 fprintf(stdout
, _("%s from %s (libblkid %s, %s)\n"),
799 program_invocation_short_name
, PACKAGE_STRING
,
800 LIBBLKID_VERSION
, LIBBLKID_DATE
);
804 /* ignore - backward compatibility */
810 errtryhelp(EXIT_FAILURE
);
814 if (ctl
.lowprobe_topology
|| ctl
.lowprobe_superblocks
)
817 /* The rest of the args are device names */
819 devices
= xcalloc(argc
- optind
, sizeof(char *));
820 while (optind
< argc
)
821 devices
[numdev
++] = argv
[optind
++];
824 /* convert LABEL/UUID lookup to evaluate request */
825 if (ctl
.lookup
&& ctl
.output
== OUTPUT_DEVICE_ONLY
&& search_type
&&
826 (!strcmp(search_type
, "LABEL") || !strcmp(search_type
, "UUID"))) {
831 if (!ctl
.lowprobe
&& !ctl
.eval
&& blkid_get_cache(&cache
, read
) < 0)
835 blkid_gc_cache(cache
);
839 err
= BLKID_EXIT_NOTFOUND
;
841 if (ctl
.eval
== 0 && (ctl
.output
& OUTPUT_PRETTY_LIST
)) {
843 errx(BLKID_EXIT_OTHER
,
844 _("The low-level probing mode does not "
845 "support 'list' output format"));
846 pretty_print_dev(NULL
);
856 errx(BLKID_EXIT_OTHER
,
857 _("The low-level probing mode "
858 "requires a device"));
860 /* automatically enable 'export' format for I/O Limits */
861 if (!ctl
.output
&& ctl
.lowprobe_topology
)
862 ctl
.output
= OUTPUT_EXPORT_LIST
;
864 pr
= blkid_new_probe();
868 if (ctl
.lowprobe_superblocks
) {
869 blkid_probe_set_superblocks_flags(pr
,
870 BLKID_SUBLKS_LABEL
| BLKID_SUBLKS_UUID
|
871 BLKID_SUBLKS_TYPE
| BLKID_SUBLKS_SECTYPE
|
872 BLKID_SUBLKS_USAGE
| BLKID_SUBLKS_VERSION
);
876 blkid_probe_filter_superblocks_usage(pr
, fltr_flag
, fltr_usage
))
879 else if (fltr_type
&&
880 blkid_probe_filter_superblocks_type(pr
, fltr_flag
, fltr_type
))
884 for (i
= 0; i
< numdev
; i
++) {
885 err
= lowprobe_device(pr
, devices
[i
], &ctl
);
889 blkid_free_probe(pr
);
890 } else if (ctl
.eval
) {
894 char *res
= blkid_evaluate_tag(search_type
, search_value
, NULL
);
899 } else if (ctl
.lookup
) {
901 * Classic (cache based) API
906 errx(BLKID_EXIT_OTHER
,
907 _("The lookup option requires a "
908 "search type specified using -t"));
909 /* Load any additional devices not in the cache */
910 for (i
= 0; i
< numdev
; i
++)
911 blkid_get_dev(cache
, devices
[i
], BLKID_DEV_NORMAL
);
913 if ((dev
= blkid_find_dev_with_tag(cache
, search_type
,
915 print_tags(&ctl
, dev
);
918 /* If we didn't specify a single device, show all available devices */
919 } else if (!numdev
) {
920 blkid_dev_iterate iter
;
923 blkid_probe_all(cache
);
925 iter
= blkid_dev_iterate_begin(cache
);
926 blkid_dev_set_search(iter
, search_type
, search_value
);
927 while (blkid_dev_next(iter
, &dev
) == 0) {
928 dev
= blkid_verify(cache
, dev
);
931 print_tags(&ctl
, dev
);
934 blkid_dev_iterate_end(iter
);
935 /* Add all specified devices to cache (optionally display tags) */
936 } else for (i
= 0; i
< numdev
; i
++) {
937 blkid_dev dev
= blkid_get_dev(cache
, devices
[i
],
942 !blkid_dev_has_tag(dev
, search_type
,
945 print_tags(&ctl
, dev
);
953 free_types_list(fltr_type
);
954 if (!ctl
.lowprobe
&& !ctl
.eval
)
955 blkid_put_cache(cache
);