diff options
author | Karel Zak <kzak@redhat.com> | 2007-05-14 14:31:28 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2007-05-17 12:10:18 +0200 |
commit | 65a567e837338052ab0714ee5eab925d74f4a6c1 (patch) | |
tree | 454d9a6c8ca8ee7c5ae9a9d4a9085af3f396c8df /mount/fsprobe.c | |
parent | 950f648f8a773359bbec7f30820c9b3159e66e1c (diff) | |
download | util-linux-old-65a567e837338052ab0714ee5eab925d74f4a6c1.tar.gz |
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/fsprobe.c')
-rw-r--r-- | mount/fsprobe.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/mount/fsprobe.c b/mount/fsprobe.c index 4b578026..2629d0d5 100644 --- a/mount/fsprobe.c +++ b/mount/fsprobe.c @@ -162,3 +162,64 @@ fsprobe_procfsloop_mount( int (*mount_fn)(struct mountargs *), } return 1; } + +const char * +fsprobe_get_devname_for_mounting(const char *spec) +{ + char *name, *value; + + if (!spec) + return NULL; + + if (parse_spec(spec, &name, &value) != 0) + return NULL; /* parse error */ + + if (name) { + const char *nspec = NULL; + + if (!strcmp(name,"LABEL")) + nspec = fsprobe_get_devname_by_label(value); + else if (!strcmp(name,"UUID")) + nspec = fsprobe_get_devname_by_uuid(value); + + if (nspec && verbose > 1) + printf(_("mount: going to mount %s by %s\n"), spec, name); + + free((void *) name); + return nspec; + } + + /* no LABEL, no UUID, .. probably a path */ + if (verbose > 1) + printf(_("mount: no LABEL=, no UUID=, going to mount %s by path\n"), spec); + + return canonicalize(spec); +} + +/* like fsprobe_get_devname_for_mounting(), but without verbose messages */ +const char * +fsprobe_get_devname(const char *spec) +{ + char *name, *value; + + if (!spec) + return NULL; + + if (parse_spec(spec, &name, &value) != 0) + return NULL; /* parse error */ + + if (name) { + const char *nspec = NULL; + + if (!strcmp(name,"LABEL")) + nspec = fsprobe_get_devname_by_label(value); + else if (!strcmp(name,"UUID")) + nspec = fsprobe_get_devname_by_uuid(value); + + free((void *) name); + return nspec; + } + + return canonicalize(spec); +} + |