summaryrefslogtreecommitdiffstats
path: root/mount/fsprobe_blkid.c
diff options
context:
space:
mode:
authorKarel Zak2007-05-10 12:10:57 +0200
committerKarel Zak2007-05-17 12:52:40 +0200
commit4b9c399bf67501183389087437313c5b08f8f776 (patch)
treeb98e5576851f06914429d43507f542d58ff36a4d /mount/fsprobe_blkid.c
parentmount: fsprobe: make fsprobe_get_devname functions more generic (diff)
downloadkernel-qcow2-util-linux-4b9c399bf67501183389087437313c5b08f8f776.tar.gz
kernel-qcow2-util-linux-4b9c399bf67501183389087437313c5b08f8f776.tar.xz
kernel-qcow2-util-linux-4b9c399bf67501183389087437313c5b08f8f776.zip
mount: fsprobe: use blkid cache only when really necessary
The blkid_get_cache() parses /etc/blkid.tab, it's better do it only when we really need to resolve a spec (label or uuid). Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/fsprobe_blkid.c')
-rw-r--r--mount/fsprobe_blkid.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/mount/fsprobe_blkid.c b/mount/fsprobe_blkid.c
index 2dc734e5a..4d2889729 100644
--- a/mount/fsprobe_blkid.c
+++ b/mount/fsprobe_blkid.c
@@ -2,35 +2,55 @@
#include <blkid/blkid.h>
#include "fsprobe.h"
+#define BLKID_EMPTY_CACHE "/dev/null"
static blkid_cache blkid;
void
-fsprobe_init(void) {
- blkid_get_cache(&blkid, NULL);
+fsprobe_init(void)
+{
+ blkid = NULL;
}
void
-fsprobe_exit(void) {
- blkid_put_cache(blkid);
+fsprobe_exit(void)
+{
+ if (blkid)
+ blkid_put_cache(blkid);
}
const char *
-fsprobe_get_label_by_devname(const char *devname) {
+fsprobe_get_label_by_devname(const char *devname)
+{
+ if (!blkid)
+ blkid_get_cache(&blkid, NULL);
+
return blkid_get_tag_value(blkid, "LABEL", devname);
}
const char *
-fsprobe_get_uuid_by_devname(const char *devname) {
+fsprobe_get_uuid_by_devname(const char *devname)
+{
+ if (!blkid)
+ blkid_get_cache(&blkid, NULL);
+
return blkid_get_tag_value(blkid, "UUID", devname);
}
const char *
-fsprobe_get_devname_by_uuid(const char *uuid) {
+fsprobe_get_devname_by_uuid(const char *uuid)
+{
+ if (!blkid)
+ blkid_get_cache(&blkid, NULL);
+
return blkid_get_devname(blkid, "UUID", uuid);
}
const char *
-fsprobe_get_devname_by_label(const char *label) {
+fsprobe_get_devname_by_label(const char *label)
+{
+ if (!blkid)
+ blkid_get_cache(&blkid, NULL);
+
return blkid_get_devname(blkid, "LABEL", label);
}
@@ -41,7 +61,22 @@ fsprobe_known_fstype(const char *fstype)
}
const char *
-fsprobe_get_fstype_by_devname(const char *devname) {
- return blkid_get_tag_value(blkid, "TYPE", devname);
+fsprobe_get_fstype_by_devname(const char *devname)
+{
+ blkid_cache c;
+ const char *tp;
+
+ if (blkid)
+ return blkid_get_tag_value(blkid, "TYPE", devname);
+
+ /* The cache is not initialized yet. Use empty cache rather than waste
+ * time with /etc/blkid.tab. It seems that probe FS is faster than
+ * parse the cache file. -- kzak (17-May-2007)
+ */
+ blkid_get_cache(&c, BLKID_EMPTY_CACHE);
+ tp = blkid_get_tag_value(c, "TYPE", devname);
+ blkid_put_cache(c);
+
+ return tp;
}