[PATCH] blkid: add support to the -w option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



blkid -w should write an alternative cache file but it is not implemented.
The patch addresses this issue by adding a new interface to cache.c to set
the alternative cache filename.

Addresses-Launchpad-bug: #316322

Signed-off-by: Peng Tao <bergwolf@xxxxxxxxx>
---
 misc-utils/blkid.c         |    1 +
 shlibs/blkid/src/blkid.h   |    1 +
 shlibs/blkid/src/blkid.sym |    1 +
 shlibs/blkid/src/cache.c   |   21 +++++++++++++++++++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index e9622c3..b822b66 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -636,6 +636,7 @@ int main(int argc, char **argv)
 			err = 0;
 		}
 	}
+	blkid_set_cachefile(cache, write);
 
 exit:
 	free(search_type);
diff --git a/shlibs/blkid/src/blkid.h b/shlibs/blkid/src/blkid.h
index 6b495b6..57e0697 100644
--- a/shlibs/blkid/src/blkid.h
+++ b/shlibs/blkid/src/blkid.h
@@ -121,6 +121,7 @@ typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
 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);
+extern void blkid_set_cachefile(blkid_cache cache, const char *filename);
 
 /* dev.c */
 extern const char *blkid_dev_devname(blkid_dev dev);
diff --git a/shlibs/blkid/src/blkid.sym b/shlibs/blkid/src/blkid.sym
index 992d4e9..a696ba2 100644
--- a/shlibs/blkid/src/blkid.sym
+++ b/shlibs/blkid/src/blkid.sym
@@ -111,4 +111,5 @@ global:
 	blkid_topology_get_alignment_offset;
 	blkid_topology_get_minimum_io_size;
 	blkid_topology_get_optimal_io_size;
+	blkid_set_cachefile;
 } BLKID_2.15;
diff --git a/shlibs/blkid/src/cache.c b/shlibs/blkid/src/cache.c
index e71176b..3fcb1ab 100644
--- a/shlibs/blkid/src/cache.c
+++ b/shlibs/blkid/src/cache.c
@@ -257,6 +257,27 @@ void blkid_gc_cache(blkid_cache cache)
 	}
 }
 
+/**
+ * blkid_set_cachefile:
+ * @cache: cache handler
+ * @filename: new cache file
+ *
+ * Set cache filename, and mark cache changed if filename differ from the
+ * original cache file.
+ */
+void blkid_set_cachefile(blkid_cache cache, const char *filename)
+{
+	if (!cache || !filename)
+		return;
+
+	if (! strcmp(cache->bic_filename, filename))
+		return;
+	free(cache->bic_filename);
+	cache->bic_filename = blkid_strdup(filename);
+	/* Always mark cache changed if another cache file is specified */
+	cache->bic_flags |= BLKID_BIC_FL_CHANGED;
+}
+
 #ifdef TEST_PROGRAM
 int main(int argc, char** argv)
 {
-- 
1.6.2-rc2.GIT

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux