Whamcloud - gitweb
blkid.c (main, compare_search_type): Make blkid -t work more
authorTheodore Ts'o <tytso@mit.edu>
Fri, 28 Jan 2005 00:51:47 +0000 (19:51 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 28 Jan 2005 00:51:47 +0000 (19:51 -0500)
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
lib/blkid/blkid.h
lib/blkid/blkidP.h
lib/blkid/devname.c
lib/blkid/probe.c
lib/blkid/tag.c
misc/ChangeLog
misc/blkid.8.in
misc/blkid.c

index f0f01b6..ce9e5e8 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-27  Theodore Ts'o  <tytso@mit.edu>
+
+       * 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  <tytso@mit.edu>
 
        * version.c: Add functions to query the version of the blkid library.
index a628e63..2bfee7c 100644 (file)
@@ -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 */
 
index 7d90b5e..db23c2b 100644 (file)
@@ -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);
 
index 6e0e6d7..87d5cbe 100644 (file)
@@ -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;
                }
        }
index e8f3be2..14292b5 100644 (file)
@@ -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;
index 67cd374..63e5e7b 100644 (file)
@@ -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;
        }
index 33fffb3..7195929 100644 (file)
@@ -1,5 +1,9 @@
 2005-01-27  Theodore Ts'o  <tytso@mit.edu>
 
+       * 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
index d4fd670..0f6f7c8 100644 (file)
@@ -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.
index 60c7b37..ecbf8cf 100644 (file)
@@ -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;
                }