Whamcloud - gitweb
Add new function blkid_gc_cache()
authorTheodore Ts'o <tytso@mit.edu>
Fri, 18 May 2007 04:02:35 +0000 (00:02 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 18 May 2007 04:02:35 +0000 (00:02 -0400)
New function which performs a garbage collection pass on the
/etc/blkid.tab file.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/blkid/ChangeLog
lib/blkid/blkid.h
lib/blkid/cache.c

index 4433ef4..303f7cf 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-17  Theodore Tso  <tytso@mit.edu>
+
+       * cache.c (blkid_gc_cache): New function which removes any devices
+               from the blkid cache if the device node does not exist.
+
 2007-03-23  Theodore Tso  <tytso@mit.edu>
 
        * read.c (parse_dev): Fix memory leak on error path.
index 892b798..f38a235 100644 (file)
@@ -50,6 +50,7 @@ typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
 /* cache.c */
 extern void blkid_put_cache(blkid_cache cache);
 extern int blkid_get_cache(blkid_cache *cache, const char *filename);
+extern void blkid_gc_cache(blkid_cache cache);
 
 /* dev.c */
 extern const char *blkid_dev_devname(blkid_dev dev);
index b47b488..1508d0f 100644 (file)
@@ -26,6 +26,9 @@
 #if (!defined(HAVE_PRCTL) && defined(linux))
 #include <sys/syscall.h>
 #endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
 #include "blkidP.h"
 
 int blkid_debug_mask = 0;
@@ -149,6 +152,31 @@ void blkid_put_cache(blkid_cache cache)
        free(cache);
 }
 
+void blkid_gc_cache(blkid_cache cache)
+{
+       struct list_head *p;
+       struct stat st;
+
+       if (!cache)
+               return;
+
+       list_for_each(p, &cache->bic_devs) {
+               blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
+               if (!p)
+                       break;
+               if (stat(dev->bid_name, &st) < 0) {
+                       DBG(DEBUG_CACHE, 
+                           printf("freeing %s\n", dev->bid_name));
+                       blkid_free_dev(dev);
+                       cache->bic_flags |= BLKID_BIC_FL_CHANGED;
+               } else {
+                       DBG(DEBUG_CACHE, 
+                           printf("Device %s exists\n", dev->bid_name));
+               }
+       }
+}
+
+
 #ifdef TEST_PROGRAM
 int main(int argc, char** argv)
 {