From 18d12963335b04a402d097af1d714e8708805ada Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 27 Jan 2005 19:51:47 -0500 Subject: [PATCH] blkid.c (main, compare_search_type): Make blkid -t work more consistently when the blkid cache file is explicitly set to /dev/null. (Addresses Debian Bug #292425) Also expose blkid_verify() as a public function to the blkid library. --- lib/blkid/ChangeLog | 6 +++++ lib/blkid/blkid.h | 1 + lib/blkid/blkidP.h | 3 --- lib/blkid/devname.c | 4 ++-- lib/blkid/probe.c | 2 +- lib/blkid/tag.c | 2 +- misc/ChangeLog | 4 ++++ misc/blkid.8.in | 5 ++-- misc/blkid.c | 68 +++++++++++++++++++++++++---------------------------- 9 files changed, 50 insertions(+), 45 deletions(-) diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index f0f01b6..ce9e5e8 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,9 @@ +2005-01-27 Theodore Ts'o + + * blkid.h, blkidP.h: Rename blkid_verify_devname() to be + blkid_verify(), and make it be a publically exported + function. + 2005-01-26 Theodore Ts'o * version.c: Add functions to query the version of the blkid library. diff --git a/lib/blkid/blkid.h b/lib/blkid/blkid.h index a628e63..2bfee7c 100644 --- a/lib/blkid/blkid.h +++ b/lib/blkid/blkid.h @@ -71,6 +71,7 @@ extern blkid_loff_t blkid_get_dev_size(int fd); /* probe.c */ int blkid_known_fstype(const char *fstype); +extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev); /* read.c */ diff --git a/lib/blkid/blkidP.h b/lib/blkid/blkidP.h index 7d90b5e..db23c2b 100644 --- a/lib/blkid/blkidP.h +++ b/lib/blkid/blkidP.h @@ -212,9 +212,6 @@ static __inline__ void DEB_DUMP_CACHE(int mask, blkid_cache cache) /* lseek.c */ extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence); -/* probe.c */ -extern blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev); - /* read.c */ extern void blkid_read_cache(blkid_cache cache); diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c index 6e0e6d7..87d5cbe 100644 --- a/lib/blkid/devname.c +++ b/lib/blkid/devname.c @@ -71,7 +71,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) } if (flags & BLKID_DEV_VERIFY) - dev = blkid_verify_devname(cache, dev); + dev = blkid_verify(cache, dev); return dev; } @@ -91,7 +91,7 @@ static void probe_one(blkid_cache cache, const char *ptname, blkid_dev tmp = list_entry(p, struct blkid_struct_dev, bid_devs); if (tmp->bid_devno == devno) { - dev = blkid_verify_devname(cache, tmp); + dev = blkid_verify(cache, tmp); break; } } diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index e8f3be2..14292b5 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -532,7 +532,7 @@ static struct blkid_magic type_array[] = { * If we are unable to revalidate the data, we return the old data and * do not set the BLKID_BID_FL_VERIFIED flag on it. */ -blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev) +blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev) { struct blkid_magic *id; unsigned char *bufs[BLKID_BLK_OFFS + 1], *buf; diff --git a/lib/blkid/tag.c b/lib/blkid/tag.c index 67cd374..63e5e7b 100644 --- a/lib/blkid/tag.c +++ b/lib/blkid/tag.c @@ -326,7 +326,7 @@ try_again: } } if (dev && !(dev->bid_flags & BLKID_BID_FL_VERIFIED)) { - dev = blkid_verify_devname(cache, dev); + dev = blkid_verify(cache, dev); if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED)) goto try_again; } diff --git a/misc/ChangeLog b/misc/ChangeLog index 33fffb3..7195929 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,9 @@ 2005-01-27 Theodore Ts'o + * blkid.c (main, compare_search_type): Make blkid -t work more + consistently when the blkid cache file is explicitly set + to /dev/null. (Addresses Debian Bug #292425) + * mke2fs.c (PRS): Don't use a blocksize greater than 4k, even on 2.6 kernels, unless explicitly requested by the user; not all 2.6 kernels (includeing stock 2.6 kernels as of this diff --git a/misc/blkid.8.in b/misc/blkid.8.in index d4fd670..0f6f7c8 100644 --- a/misc/blkid.8.in +++ b/misc/blkid.8.in @@ -90,8 +90,7 @@ In order to just refresh the cache without showing any tokens use with no other options. .TP .B \-t -Search the blkid cache (plus any devices specifed on the command line) -for all block devices with tokens named +Search for block devices with tokens named .I NAME that have the value .IR value , @@ -103,6 +102,8 @@ include .BR LABEL , and .BR UUID . +If there are no devices specified on the command line, all block devices +will be searched; otherwise, only search the devices specified by the user. .TP .B \-v Display version number and exit. diff --git a/misc/blkid.c b/misc/blkid.c index 60c7b37..ecbf8cf 100644 --- a/misc/blkid.c +++ b/misc/blkid.c @@ -88,6 +88,26 @@ static void print_tags(blkid_dev dev, char *show[], int numtag, int output) 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; @@ -172,43 +192,8 @@ int main(int argc, char **argv) goto exit; err = 2; - /* If looking for a specific NAME=value pair, print only that */ - if (search_type) { - blkid_dev_iterate dev_iter; - blkid_tag_iterate tag_iter; - blkid_dev dev; - int found; - const char *type, *value; - - /* Load any additional devices not in the cache */ - for (i = 0; i < numdev; i++) - blkid_get_dev(cache, devices[i], BLKID_DEV_NORMAL); - - /* - * XXX We need better interfaces in the blkid library - * so we don't need to open code as much stuff. - */ - dev_iter = blkid_dev_iterate_begin(cache); - while (blkid_dev_next(dev_iter, &dev) == 0) { - 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++; - } - blkid_tag_iterate_end(tag_iter); - if (!found) - continue; - - print_tags(dev, show, numtag, output_format); - err = 0; - } - blkid_dev_iterate_end(dev_iter); - /* If we didn't specify a single device, show all available devices */ - } else if (!numdev) { + if (!numdev) { blkid_dev_iterate iter; blkid_dev dev; @@ -216,6 +201,13 @@ int main(int argc, char **argv) iter = blkid_dev_iterate_begin(cache); 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; } @@ -226,6 +218,10 @@ int main(int argc, char **argv) BLKID_DEV_NORMAL); if (dev) { + if (search_type && + !compare_search_type(dev, search_type, + search_value)) + continue; print_tags(dev, show, numtag, output_format); err = 0; } -- 1.8.3.1