]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/loopdev: make is_loopdev() more robust
authorKarel Zak <kzak@redhat.com>
Tue, 12 Jan 2021 10:43:31 +0000 (11:43 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 10 Feb 2021 09:08:57 +0000 (10:08 +0100)
commit547130444d893c284ab91d757b98b9435c5f3d01
tree0c14a22962a5cc80f3a2961ffcca470a76a5cc07
parent5affd1f92d2dd9150f7f5210d819db61965adae3
lib/loopdev: make is_loopdev() more robust

It seems the current kernel can create a loop devices with a different
major number. For example

  # losetup /dev/loop12345678 file.img
  # lsblk /dev/loop12345678
  NAME          MAJ:MIN    RM SIZE RO TYPE MOUNTPOINT
  loop12345678   15:811342  0   5M  0 loop

We need a way how to verify the device is loopdev also when the device is
not associated with any backing file -- in this case there is no "loop"
directory in /sys/dev/block/<maj:min>/, but we can cannonicalize this sysfs
symlink as it points to /sys/devices/virtual/block/loop<n> (see "loop" in
the path).

Note that without this change losetup is not able to list and delete
the loop device.

Addresses: https://github.com/karelzak/util-linux/issues/1202
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/loopdev.c