]> 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>
Tue, 12 Jan 2021 10:43:31 +0000 (11:43 +0100)
commitfbc2fe824dd3450df122d8416da8689f82fb0b4c
treea665a562daccb8f0608c1d15ed8c43d5fefbc5e3
parenta7d5efbb9ae8591b8ebcd3756a59ce30a36d80fc
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