diff options
author | LaMont Jones <lamont@debian.org> | 2009-07-21 15:45:04 -0600 |
---|---|---|
committer | LaMont Jones <lamont@debian.org> | 2009-07-21 15:45:04 -0600 |
commit | 7a22bb9abcb56d1010cefd204709e3888f95f735 (patch) | |
tree | 5c38b4485f79ee8f6a9d5f9537e973f1f663f027 /lib | |
parent | 4e13a18f57a5b427c559f3b466b9655db14d28f8 (diff) | |
parent | 741064af10ec81635d708e9fb8373f96341246eb (diff) | |
download | util-linux-old-7a22bb9abcb56d1010cefd204709e3888f95f735.tar.gz |
Merge commit 'origin/master'
Conflicts:
AUTHORS
NEWS
config/include-Makefile.am
configure.ac
mount/lomount.c
po/POTFILES.in
po/ca.po
po/cs.po
po/da.po
po/de.po
po/es.po
po/et.po
po/eu.po
po/fi.po
po/fr.po
po/hu.po
po/id.po
po/it.po
po/ja.po
po/nl.po
po/pl.po
po/pt_BR.po
po/ru.po
po/sl.po
po/sv.po
po/tr.po
po/uk.po
po/util-linux-ng.pot
po/vi.po
po/zh_CN.po
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fsprobe.c | 159 |
1 files changed, 7 insertions, 152 deletions
diff --git a/lib/fsprobe.c b/lib/fsprobe.c index c5fa8c63..b47de0ec 100644 --- a/lib/fsprobe.c +++ b/lib/fsprobe.c @@ -18,7 +18,9 @@ #include "pathnames.h" #include "fsprobe.h" -#if defined(HAVE_BLKID_EVALUATE_TAG) || defined(HAVE_LIBVOLUME_ID) +static blkid_cache blcache; + +#ifdef HAVE_BLKID_EVALUATE_TAG /* ask kernel developers why we need such ugly open() method... */ static int open_device(const char *devname) @@ -45,35 +47,16 @@ open_device(const char *devname) * 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 fsprobe_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 = strdup(spec); - vl = tk + (cp - spec); - *vl++ = '\0'; + if (strchr(spec, '=')) + return blkid_parse_tag_string(spec, name, value); - if (*vl == '"' || *vl == '\'') { - if (!(cp = strrchr(vl+1, *vl))) { - free(tk); - return -1; /* parse error */ - } - vl++; - *cp = '\0'; - } - - *name = tk; - *value = vl; return 0; } @@ -94,16 +77,14 @@ fsprobe_get_devname_by_spec(const char *spec) else if (!strcmp(name,"UUID")) nspec = fsprobe_get_devname_by_uuid(value); - free((void *) name); + free(name); + free(value); return nspec; } return canonicalize_path(spec); } -#ifdef HAVE_LIBBLKID -static blkid_cache blcache; - void fsprobe_init(void) { @@ -266,129 +247,3 @@ fsprobe_get_uuid_by_devname(const char *devname) } #endif /* !HAVE_BLKID_EVALUATE_TAG */ -#else /* !HAVE_LIBBLKID */ - -/* - * libvolume_id from udev - * -- deprecated - */ -#include <libvolume_id.h> - -enum probe_type { - VOLUME_ID_NONE, - VOLUME_ID_LABEL, - VOLUME_ID_UUID, - VOLUME_ID_TYPE, -}; - -static char -*probe(const char *device, enum probe_type type) -{ - int fd; - uint64_t size; - struct volume_id *id; - const char *val; - char *value = NULL; - int retries = 0; - - fd = open_device(devname); - if (fd < 0) - return NULL; - id = volume_id_open_fd(fd); - if (!id) { - close(fd); - return NULL; - } - if (blkdev_get_size(fd, &size) != 0) - size = 0; - if (volume_id_probe_all(id, 0, size) == 0) { - switch(type) { - case VOLUME_ID_LABEL: - if (volume_id_get_label(id, &val)) - value = strdup(val); - break; - case VOLUME_ID_UUID: - if (volume_id_get_uuid(id, &val)) - value = strdup(val); - break; - case VOLUME_ID_TYPE: - if (volume_id_get_type(id, &val)) - value = strdup(val); - break; - default: - break; - } - } - volume_id_close(id); - close(fd); - return value; -} - -void -fsprobe_init(void) -{ -} - -void -fsprobe_exit(void) -{ -} - -int -fsprobe_known_fstype(const char *fstype) -{ - if (volume_id_get_prober_by_type(fstype) != NULL) - return 1; - return 0; -} - -char * -fsprobe_get_uuid_by_devname(const char *devname) -{ - return probe(devname, VOLUME_ID_UUID); -} - -char * -fsprobe_get_label_by_devname(const char *devname) -{ - return probe(devname, VOLUME_ID_LABEL); -} - -char * -fsprobe_get_fstype_by_devname(const char *devname) -{ - return probe(devname, VOLUME_ID_TYPE); -} - -char * -fsprobe_get_devname_by_uuid(const char *uuid) -{ - char dev[PATH_MAX]; - size_t len; - - if (!uuid) - return NULL; - - strcpy(dev, _PATH_DEV_BYUUID "/"); - len = strlen(_PATH_DEV_BYUUID "/"); - if (!volume_id_encode_string(uuid, &dev[len], sizeof(dev) - len)) - return NULL; - return canonicalize_path(dev); -} - -char * -fsprobe_get_devname_by_label(const char *label) -{ - char dev[PATH_MAX]; - size_t len; - - if (!label) - return NULL; - strcpy(dev, _PATH_DEV_BYLABEL "/"); - len = strlen(_PATH_DEV_BYLABEL "/"); - if (!volume_id_encode_string(label, &dev[len], sizeof(dev) - len)) - return NULL; - return canonicalize_path(dev); -} - -#endif /* HAVE_LIBVOLUME_ID */ |