print_version(out);
fprintf(out,
- "usage:\t%s [-c <file>] [-h] [-o format] "
+ "usage:\t%s [-c <file>] [-hl] [-o format] "
"[-s <tag>] [-t <token>]\n [-v] [-w <file>] [dev ...]\n"
"\t-c\tcache file (default: /etc/blkid.tab, /dev/null = none)\n"
"\t-h\tprint this usage message and exit\n"
"\t-s\tshow specified tag(s) (default show all tags)\n"
"\t-t\tfind device with a specific token (NAME=value pair)\n"
+ "\t-l\tlookup the the first device with arguments specified by -t\n"
"\t-v\tprint version and exit\n"
"\t-w\twrite cache to different file (/dev/null = no write)\n"
"\tdev\tspecify device(s) to probe (default: all devices)\n",
printf("\n");
}
-int compare_search_type(blkid_dev dev, const char *search_type,
- const char *search_value)
-{
- blkid_tag_iterate tag_iter;
- const char *type, *value;
- int found = 0;
-
- tag_iter = blkid_tag_iterate_begin(dev);
- while (blkid_tag_next(tag_iter, &type, &value) == 0) {
- if (!strcmp(type, search_type) &&
- !strcmp(value, search_value)) {
- found++;
- break;
- }
- }
- blkid_tag_iterate_end(tag_iter);
-
- return found;
-}
-
int main(int argc, char **argv)
{
blkid_cache cache = NULL;
int err = 4;
unsigned int i;
int output_format = 0;
- char c;
+ int lookup = 0;
+ int c;
- while ((c = getopt (argc, argv, "c:f:ho:s:t:w:v")) != EOF)
+ while ((c = getopt (argc, argv, "c:f:hlo:s:t:w:v")) != EOF)
switch (c) {
case 'c':
if (optarg && !*optarg)
if (!write)
write = read;
break;
+ case 'l':
+ lookup++;
+ break;
case 'o':
if (!strcmp(optarg, "value"))
output_format = OUTPUT_VALUE_ONLY;
goto exit;
err = 2;
+ if (lookup) {
+ blkid_dev dev;
+
+ if (!search_type) {
+ fprintf(stderr, "The lookup option requires a "
+ "search type specified using -t\n");
+ exit(1);
+ }
+ /* Load any additional devices not in the cache */
+ for (i = 0; i < numdev; i++)
+ blkid_get_dev(cache, devices[i], BLKID_DEV_NORMAL);
+
+ if ((dev = blkid_find_dev_with_tag(cache, search_type,
+ search_value))) {
+ print_tags(dev, show, numtag, output_format);
+ err = 0;
+ }
/* If we didn't specify a single device, show all available devices */
- if (!numdev) {
+ } else if (!numdev) {
blkid_dev_iterate iter;
blkid_dev dev;
blkid_probe_all(cache);
iter = blkid_dev_iterate_begin(cache);
+ blkid_dev_set_search(iter, search_type, search_value);
while (blkid_dev_next(iter, &dev) == 0) {
dev = blkid_verify(cache, dev);
if (!dev)
continue;
- if (search_type &&
- !compare_search_type(dev, search_type,
- search_value))
- continue;
print_tags(dev, show, numtag, output_format);
err = 0;
}
BLKID_DEV_NORMAL);
if (dev) {
- if (search_type &&
- !compare_search_type(dev, search_type,
- search_value))
+ if (search_type &&
+ !blkid_dev_has_tag(dev, search_type,
+ search_value))
continue;
print_tags(dev, show, numtag, output_format);
err = 0;