]> git.ipfire.org Git - thirdparty/util-linux.git/commit
loopdev: report lost loop devices
authorJunxiao Bi <junxiao.bi@oracle.com>
Wed, 25 Oct 2023 20:36:03 +0000 (13:36 -0700)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Nov 2023 11:39:16 +0000 (12:39 +0100)
commita6ca0456cc6d704a786f6b66d8bb2d89ff18eba7
tree21f565cb6b94d589f05f0f57eecaa9cc24a1c5f6
parentd8379563fe5c8a4adba12804abbe20e43a8e1cde
loopdev: report lost loop devices

If a /dev/loopX is lost because someone might have removed it by mistake,
future losetup operations on that loop device will fail and losetup
--all and --list will not report the devices (although kernel still
uses it).

Since /sysfs still have the loop device intact, detect that and report it.

Changes:

* --list and --all add "(lost)" after device node path

  # losetup
  NAME              SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE    DIO LOG-SEC
  /dev/loop0 (lost)         0      0         0  0 /root/l0.img   0     512

  # losetup -a
  /dev/loop0 (lost): []: (/root/l0.img)

* use /sys to get devno rather than stat()

* report warning after failed operation

  # losetup -d /dev/loop0
  losetup: /dev/loop0: detach failed: No such file or directory
  losetup: device node /dev/loop0 (7:0) is lost. You may use mknod(1) to recover it.

* fix copy & past bugs in some API comments

Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/loopdev.h
lib/loopdev.c
sys-utils/losetup.c