+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.
/* 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);
#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;
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)
{