From: Karel Zak Date: Wed, 17 Oct 2012 09:43:39 +0000 (+0200) Subject: lib/loopdev: check for /sys X-Git-Tag: v2.23-rc1~608 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df0f2ad7633b3e2cc830298239cbaaa656e724cd;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 a552fb7556..dc93a69d7e 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)) { /*