summaryrefslogtreecommitdiffstats
path: root/mount/sundries.c
diff options
context:
space:
mode:
authorKarel Zak2007-05-14 14:31:28 +0200
committerKarel Zak2007-05-17 12:10:18 +0200
commit65a567e837338052ab0714ee5eab925d74f4a6c1 (patch)
tree454d9a6c8ca8ee7c5ae9a9d4a9085af3f396c8df /mount/sundries.c
parentmount: fsprobe: rename the rest of API routines to fsprobe_* (diff)
downloadkernel-qcow2-util-linux-65a567e837338052ab0714ee5eab925d74f4a6c1.tar.gz
kernel-qcow2-util-linux-65a567e837338052ab0714ee5eab925d74f4a6c1.tar.xz
kernel-qcow2-util-linux-65a567e837338052ab0714ee5eab925d74f4a6c1.zip
mount: fsprobe: make fsprobe_get_devname functions more generic
The blkid supports NAME=value parsing, but use the library for this simple task is overkill. (The libblkid requires initialized blkid cache all time, for all calls.) This patch makes the fsprobe_get_devname_for_mounting() and fsprobe_get_devname() generic for all fsprobe implementations. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/sundries.c')
-rw-r--r--mount/sundries.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/mount/sundries.c b/mount/sundries.c
index cdfbb42e5..45404c5cf 100644
--- a/mount/sundries.c
+++ b/mount/sundries.c
@@ -247,3 +247,41 @@ canonicalize (const char *path) {
return xstrdup(path);
}
+
+
+/*
+ * Parses NAME=value, returns -1 on parse error, 0 success. The success is also
+ * when the 'spec' doesn't contain name=value pair (because the spec could be
+ * a devname too). In particular case the pointer 'name' is set to NULL.
+
+ * The result is a new allocated string (the 'name' pointer).
+ */
+int
+parse_spec(const char *spec, char **name, char **value)
+{
+ char *vl, *tk, *cp;
+
+ *name = NULL;
+ *value = NULL;
+
+ if (!(cp = strchr(spec, '=')))
+ return 0; /* no name= */
+
+ tk = xstrdup(spec);
+ vl = tk + (cp - spec);
+ *vl++ = '\0';
+
+ if (*vl == '"' || *vl == '\'') {
+ if (!(cp = strrchr(vl+1, *vl))) {
+ free(tk);
+ return -1; /* parse error */
+ }
+ vl++;
+ *cp = '\0';
+ }
+
+ *name = tk;
+ *value = vl;
+ return 0;
+}
+