summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlias Mamedov2011-10-03 14:22:42 +0200
committerKarel Zak2011-10-03 14:25:43 +0200
commitf17f5f481a1c1d61853f1e01858311b38f7ee6ab (patch)
tree163b0e8736b6d993102ee287103601d50be78cad
parentdocs: add prlimit to the TODO file (diff)
downloadkernel-qcow2-util-linux-f17f5f481a1c1d61853f1e01858311b38f7ee6ab.tar.gz
kernel-qcow2-util-linux-f17f5f481a1c1d61853f1e01858311b38f7ee6ab.tar.xz
kernel-qcow2-util-linux-f17f5f481a1c1d61853f1e01858311b38f7ee6ab.zip
lsblk: add udev support
[kzak@redhat.com: - enable udev support by default - don't check for libudev.h - minor udev code refactoring in lsblk.c] Signed-off-by: Ilias Mamedov <arknir@yandex.ru> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--configure.ac19
-rw-r--r--misc-utils/Makefile.am3
-rw-r--r--misc-utils/lsblk.c49
3 files changed, 66 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index fb0b0eb37..d12a4a037 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1111,11 +1111,28 @@ else
UTIL_CHECK_LIB(audit, audit_log_user_message)
case "$with_audit:$have_audit" in
yes:no)
- AC_MSG_ERROR([Audit selected but libaudit not found (or doesn't support audit_log_user_message())])
+ AC_MSG_ERROR([Audit selected but libaudit not found (or does not support audit_log_user_message())])
;;
esac
fi
+
+AC_ARG_WITH([udev], AS_HELP_STRING([--without-udev], [compile without udev support]),
+ [], with_udev=auto
+)
+
+if test "x$with_udev" = xno; then
+ AM_CONDITIONAL(HAVE_UDEV, false)
+else
+ UTIL_CHECK_LIB(udev, udev_new)
+ case "$with_udev:$have_udev" in
+ yes:no)
+ AC_MSG_ERROR([udev selected but libudev not found])
+ ;;
+ esac
+fi
+
+
AC_ARG_ENABLE([schedutils],
AS_HELP_STRING([--disable-schedutils], [do not build chrt, ionice, teskset]),
[], enable_schedutils=yes
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index 300dab46e..9b941f518 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -66,6 +66,9 @@ lsblk_SOURCES = lsblk.c \
$(top_srcdir)/lib/at.c
lsblk_LDADD = $(ul_libblkid_la)
lsblk_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
+if HAVE_UDEV
+lsblk_LDADD += -ludev
+endif
endif
if HAVE_STATIC_BLKID
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 3c4555d87..f9c06fe07 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -41,6 +41,10 @@
#include <blkid.h>
+#ifdef HAVE_LIBUDEV
+#include <libudev.h>
+#endif
+
#include <assert.h>
#include "pathnames.h"
@@ -284,20 +288,58 @@ static char *get_device_mountpoint(struct blkdev_cxt *cxt)
return strlen(mnt) ? xstrdup(mnt) : NULL;
}
-/* TODO: read info from udev db (if possible) for non-root users
- */
+#ifndef HAVE_LIBUDEV
+static int probe_device_by_udev(struct blkdev_cxt *cxt
+ __attribute__((__unused__)))
+{
+ return -1;
+}
+#else
+static int probe_device_by_udev(struct blkdev_cxt *cxt)
+{
+ struct udev *udev;
+ struct udev_device *dev;
+
+ udev = udev_new();
+ if (!udev)
+ return -1;
+
+ dev = udev_device_new_from_subsystem_sysname(udev, "block", cxt->name);
+ if (dev) {
+ const char *data;
+
+ if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL")))
+ cxt->label = xstrdup(data);
+ if ((data = udev_device_get_property_value(dev, "ID_FS_TYPE")))
+ cxt->fstype = xstrdup(data);
+ if ((data = udev_device_get_property_value(dev, "ID_FS_UUID")))
+ cxt->uuid = xstrdup(data);
+
+ udev_device_unref(dev);
+ }
+
+ udev_unref(udev);
+ return 0;
+}
+#endif /* HAVE_LIBUDEV */
+
static void probe_device(struct blkdev_cxt *cxt)
{
- char *path = NULL;
blkid_probe pr = NULL;
if (cxt->probed)
return;
+
cxt->probed = 1;
if (!cxt->size)
return;
+ /* try udev DB */
+ if (probe_device_by_udev(cxt) == 0)
+ return; /* success */
+
+ /* try libblkid */
pr = blkid_new_probe_from_filename(cxt->filename);
if (!pr)
return;
@@ -320,7 +362,6 @@ static void probe_device(struct blkdev_cxt *cxt)
cxt->label = xstrdup(data);
}
- free(path);
blkid_free_probe(pr);
return;
}