]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: don't use BLKRRPART to check loopdev usage
authorKarel Zak <kzak@redhat.com>
Fri, 17 Apr 2015 08:32:48 +0000 (10:32 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Apr 2015 08:32:48 +0000 (10:32 +0200)
It seesm that kernel always returns EINVAL for BLKRRPART on loop
devices, we call the ioctl to check if nobody else uses the device.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.c

index f34a45adc6cc9ab900f82991feaf2ea8ab14e679..67fa1d18f3c914e32dc40a9da8aeb2109d63a15e 100644 (file)
@@ -44,6 +44,7 @@
 #include "blkdev.h"
 #include "all-io.h"
 #include "rpmatch.h"
+#include "loopdev.h"
 
 #include "libfdisk.h"
 #include "fdisk-list.h"
@@ -1083,7 +1084,8 @@ static int is_device_used(struct sfdisk *sf)
        if (fd < 0)
                return 0;
 
-       if (fstat(fd, &st) == 0 && S_ISBLK(st.st_mode))
+       if (fstat(fd, &st) == 0 && S_ISBLK(st.st_mode)
+           && major(st.st_rdev) != LOOPDEV_MAJOR)
                return ioctl(fd, BLKRRPART) != 0;
 #endif
        return 0;