Signed-off-by: Matthias Koenig <[EMAIL PROTECTED]>
Signed-off-by: Kay Sievers <[EMAIL PROTECTED]>
Signed-off-by: Karel Zak <[EMAIL PROTECTED]>
---
 mount/Makefile.am        |    9 +++
 mount/fsprobe_volumeid.c |  123 ++++++++++++++++++++++++++++++++++++++++++++++
 mount/mount.8            |    5 +-
 mount/mount_paths.h      |    4 ++
 4 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/mount/Makefile.am b/mount/Makefile.am
index e61261f..4562b2d 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -37,6 +37,15 @@ umount_LDADD += -lblkid -luuid
 swapon_LDADD = -lblkid -luuid
 endif
 
+if HAVE_VOLUME_ID
+mount_SOURCES += fsprobe_volumeid.c
+umount_SOURCES += fsprobe_volumeid.c
+swapon_SOURCES += fsprobe_volumeid.c
+mount_LDADD += -lvolume_id
+umount_LDADD += -lvolume_id
+swapon_LDADD = -lvolume_id
+endif
+
 if HAVE_PIVOT_ROOT
 sbin_PROGRAMS += pivot_root
 man_MANS += pivot_root.8
diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c
new file mode 100644
index 0000000..8c13987
--- /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);
+}
+
diff --git a/mount/mount.8 b/mount/mount.8
index 8ed5a11..be6e537 100644
--- a/mount/mount.8
+++ b/mount/mount.8
@@ -477,9 +477,8 @@ If no
 option is given, or if the
 .B auto
 type is specified, mount will try to guess the desired type.
-If mount was compiled with the blkid library, the guessing is done
-by this library. Otherwise, mount guesses itself by probing the
-superblock; if that does not turn up anything that looks familiar,
+Mount uses the blkid or volume_id library for guessing the filesystem
+type; if that does not turn up anything that looks familiar,
 mount will try to read the file
 .IR /etc/filesystems ,
 or, if that does not exist,
diff --git a/mount/mount_paths.h b/mount/mount_paths.h
index 9093b10..d726d06 100644
--- a/mount/mount_paths.h
+++ b/mount/mount_paths.h
@@ -15,4 +15,8 @@
 #define ETC_FILESYSTEMS                "/etc/filesystems"
 #define PROC_FILESYSTEMS       "/proc/filesystems"
 
+/* udev paths */
+#define PATH_DEV_BYLABEL       "/dev/disk/by-label"
+#define PATH_DEV_BYUUID                "/dev/disk/by-uuid"
+
 #endif /* MOUNT_PATHS_H */
-- 
1.5.0.6

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to