From: Karel Zak Date: Wed, 17 Oct 2012 09:43:39 +0000 (+0200) Subject: lib/loopdev: check for /sys X-Git-Tag: v2.22.2~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=939636dd664cc608232c272de77be96e6f089235;p=thirdparty%2Futil-linux.git lib/loopdev: check for /sys The current loopdev code prefers /sys to get information about loop devices. The old methods like scan /dev are fallback solution only. Unfortunately, the code does not check if /sys is mounted. Addresses: http://blog.flameeyes.eu/2012/10/sophistication-can-be-bad Signed-off-by: Karel Zak --- diff --git a/lib/loopdev.c b/lib/loopdev.c index 0e6033a255..f62af83c28 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -167,6 +167,12 @@ int loopcxt_init(struct loopdev_cxt *lc, int flags) if (rc) return rc; + if (stat(_PATH_SYS_BLOCK, &st) || !S_ISDIR(st.st_mode)) { + lc->flags |= LOOPDEV_FL_NOSYSFS; + lc->flags &= ~LOOPDEV_FL_NOIOCTL; + DBG(lc, loopdev_debug("init: disable /sys usage")); + } + if (!(lc->flags & LOOPDEV_FL_NOSYSFS) && get_linux_version() >= KERNEL_VERSION(2,6,37)) { /*