]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: use LOOP_CONFIGURE in a more robust way
authorKarel Zak <kzak@redhat.com>
Wed, 28 Jul 2021 09:05:36 +0000 (11:05 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 28 Jul 2021 09:05:36 +0000 (11:05 +0200)
32-bit userspace returns ENOTTY:
 ioctl(4, LOOP_CONFIGURE, {fd=3, block_size=0, info={lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_AUTOCLEAR, lo_file_name="/usr/install/iso/systemrescue-8.04-amd64.iso", ...}}) = -1 ENOTTY (Inappropriate ioctl for device)

64-bit userspace returns EINVAL:
 ioctl(4, LOOP_CONFIGURE, {fd=3, block_size=0, info={lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_AUTOCLEAR, lo_file_name="/usr/src/PACKAGES/systemrescue-8.04-amd64.iso", ...}}) = -1 EINVAL (Invalid argument)

The correct return value for an unknown ioctl is ENOTTY, but we need
to support already released kernels, so let's support both errnos.

Reported-by: Krzysztof Olędzki <ole@ans.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev.c

index 1eef15d8966286e6ae0eea07915fe1d440622d08..d9ea1d4a22ef5488921f4f5fcde1f6c64a161fd6 100644 (file)
@@ -1360,7 +1360,7 @@ int loopcxt_setup_device(struct loopdev_cxt *lc)
        if (ioctl(dev_fd, LOOP_CONFIGURE, &lc->config) < 0) {
                rc = -errno;
                errsv = errno;
-               if (errno != EINVAL) {
+               if (errno != EINVAL && errno != ENOTTY) {
                        DBG(SETUP, ul_debugobj(lc, "LOOP_CONFIGURE failed: %m"));
                        goto err;
                }