diff options
author | Karel Zak <kzak@redhat.com> | 2007-05-15 00:52:07 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2007-05-18 13:07:59 +0200 |
commit | c4e33ad025411157535b3eda347c20a03db47c62 (patch) | |
tree | f0f069f3dd4fc0c778366bf2ab531c8400f958b9 /mount/fsprobe_volumeid.c | |
parent | 40f07ff767e50d6e3b0e778d2c35f3c1e4d94106 (diff) | |
download | util-linux-old-c4e33ad025411157535b3eda347c20a03db47c62.tar.gz |
mount: fsprobe: add libvolume_id support
Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/fsprobe_volumeid.c')
-rw-r--r-- | mount/fsprobe_volumeid.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c new file mode 100644 index 00000000..8c13987a --- /dev/null +++ b/mount/fsprobe_volumeid.c @@ -0,0 +1,123 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stddef.h> +#include <sys/mount.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <libvolume_id.h> + +#include "fsprobe.h" +#include "realpath.h" +#include "mount_paths.h" +#include "sundries.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; + char *value = NULL; + + fd = open(device, O_RDONLY); + if (fd < 0) + return NULL; + + id = volume_id_open_fd(fd); + if (!id) + return NULL; + + /* TODO: use blkdev_get_size() */ + if (ioctl(fd, BLKGETSIZE64, &size) != 0) + size = 0; + + if (volume_id_probe_all(id, 0, size) == 0) { + switch(type) { + case VOLUME_ID_LABEL: + value = xstrdup(id->label); + break; + case VOLUME_ID_UUID: + value = xstrdup(id->uuid); + break; + case VOLUME_ID_TYPE: + value = xstrdup(id->type); + break; + default: + break; + } + } + + volume_id_close(id); + return value; +} + +void +fsprobe_init(void) +{ +} + +void +fsprobe_exit(void) +{ +} + +int +fsprobe_known_fstype(const char *fstype) +{ + /* TODO + if (volume_id_get_prober_by_type(fstype) != NULL) + return 1; + */ + return 0; +} + +const char * +fsprobe_get_uuid_by_devname(const char *devname) +{ + return probe(devname, VOLUME_ID_UUID); +} + +const char * +fsprobe_get_label_by_devname(const char *devname) +{ + return probe(devname, VOLUME_ID_LABEL); +} + +const char * +fsprobe_get_fstype_by_devname(const char *devname) +{ + return probe(devname, VOLUME_ID_TYPE); +} + +const char * +fsprobe_get_devname_by_uuid(const char *uuid) +{ + char dev[PATH_MAX]; + + if (!uuid) + return NULL; + + snprintf(dev, sizeof(dev), PATH_DEV_BYUUID "/%s", uuid); + return canonicalize(dev); +} + +const char * +fsprobe_get_devname_by_label(const char *label) +{ + char dev[PATH_MAX]; + + if (!label) + return NULL; + + snprintf(dev, sizeof(dev), PATH_DEV_BYLABEL "/%s", label); + return canonicalize(dev); +} + |