blkid: use proper statement instead of 0
PATCH 1/2 blkid: use proper statement instead of 0
NULL for pointers and '\0' for chars are more proper than 0.
Also fix a comment to match the code, bic_list should be bic_devs.
--- lib/blkid/blkidP.h | 2 +- lib/blkid/cache.c | 2 +- lib/blkid/read.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
lib/blkid/blkidP.h +1 -1
@@ -83,7 +83,7 @@ typedef struct blkid_struct_tag *blkid_tag;#define BLKID_PROBE_INTERVAL 200/* This describes an entire blkid cache file and probed devices. -* We can traverse all of the found devices via bic_list. +* We can traverse all of the found devices via bic_devs. * We can traverse all of the tag types by bic_tags, which hold empty tags * for each tag type. Those tags can be used as list_heads for iterating * through all devices with a specific tag type (e.g. LABEL).
lib/blkid/cache.c +1 -1
@@ -105,7 +105,7 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)INIT_LIST_HEAD (&cache->bic_tags);if (filename && !strlen (filename)) - filename =0 ; + filename =NULL ;if (!filename) filename =safe_getenv ("BLKID_FILE" );if (!filename)
lib/blkid/read.c +1 -1
@@ -415,7 +415,7 @@ void blkid_read_cache(blkid_cache cache)unsigned int end; lineno++; -if (buf[0 ] ==0 ) +if (buf[0 ] =='\0' )continue ; end =strlen (buf) -1 ;/* Continue reading next line if it ends with a backslash */
Signature · 1 line
1.8.2.1
PATCH 2/2 blkid: fix broken garbage collection
'blkid -g' fails to perform garbage collection on the blkid cache since commit
fe144e1 libblkid: Refuse to create a device structure for a non-existent device
Non-existent devices won't be added to the cache->bic_devs list, so blkid_gc_cache() couldn't even know the to-be-gc'ed devices.
To fix that a new cache flag BLKID_BIC_FL_GC is added to indicate that there are stale devices in cache to be gc'ed, as devices are all valid in cache->bic_devs we can just write out the cache to disk to perform the garbage collection.
Tested by adding non-existent device entry to blkid.tab and running 'blkid -g' to see whether the entry is removed. 'make -C lib/blkid check' reported no failures too.
Also fix the return value of 'blkid -g', return 0 instead.
--- lib/blkid/blkidP.h | 1 + lib/blkid/cache.c | 25 +++++++------------------ lib/blkid/devname.c | 4 +++- misc/blkid.c | 1 + 4 files changed, 12 insertions(+), 19 deletions(-)
lib/blkid/blkidP.h +1 -0
@@ -100,6 +100,7 @@ struct blkid_struct_cache#define BLKID_BIC_FL_PROBED 0x0002/* We probed /proc/partition devices */ #define BLKID_BIC_FL_CHANGED 0x0004/* Cache has changed from disk */ +#define BLKID_BIC_FL_GC 0x0008/* Cache has stale devices */ extern char *blkid_strdup (const char *s);extern char *blkid_strndup (const char *s,const int length);
lib/blkid/cache.c +7 -18
@@ -159,26 +159,15 @@ void blkid_put_cache(blkid_cache cache)void blkid_gc_cache (blkid_cache cache) { -struct list_head *p, *pnext; -struct stat st; - -if (!cache) +if (!cache || !(cache->bic_flags &BLKID_BIC_FL_GC ))return ; -list_for_each_safe (p, pnext, &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)); - } - } +/* +* Only valid devices are kept in cache, set BLKID_BIC_FL_CHANGED +* to write cache to disk to perform a garbage collection. +*/ + cache->bic_flags |=BLKID_BIC_FL_CHANGED ; +return ; }
lib/blkid/devname.c +3 -1
@@ -66,8 +66,10 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) }if (!dev && (flags &BLKID_DEV_CREATE )) { -if (access (devname,F_OK ) <0 ) +if (access (devname,F_OK ) <0 ) { + cache->bic_flags |=BLKID_BIC_FL_GC ;return NULL ; + } dev =blkid_new_dev ();if (!dev)return NULL ;
misc/blkid.c +1 -0
@@ -365,6 +365,7 @@ int main(int argc, char **argv) err =2 ;if (gc) {blkid_gc_cache (cache); + err =0 ; goto exit; }if (output_format &OUTPUT_PRETTY_LIST )
Signature · 1 line
1.8.2.1