diff options
-rw-r--r-- | configure.ac | 19 | ||||
-rw-r--r-- | misc-utils/Makefile.am | 3 | ||||
-rw-r--r-- | misc-utils/lsblk.c | 49 |
3 files changed, 66 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index fb0b0eb3..d12a4a03 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 300dab46..9b941f51 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 3c4555d8..f9c06fe0 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; } |