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>