* do not ignore all empty devices, we need more smart solution
* ignore only loop devices without backing file, for example:
# touch img
# losetup -f img
losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.
- old version display nothing
- new version:
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 0B 0 loop
Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
extern int loopdev_is_autoclear(const char *device);
extern char *loopdev_get_backing_file(const char *device);
+extern int loopdev_has_backing_file(const char *device);
extern int loopdev_is_used(const char *device, const char *filename,
uint64_t offset, uint64_t sizelimit, int flags);
extern char *loopdev_find_by_backing_file(const char *filename,
return res;
}
+int loopdev_has_backing_file(const char *device)
+{
+ char *tmp = loopdev_get_backing_file(device);
+
+ if (tmp) {
+ free(tmp);
+ return 1;
+ }
+ return 0;
+}
+
/*
* Returns: TRUE/FALSE
*/
#include "closestream.h"
#include "optutils.h"
#include "fileutils.h"
+#include "loopdev.h"
#include "lsblk.h"
device_to_scols(dev, NULL, tab, NULL);
}
+static int ignore_empty(struct lsblk_device *dev)
+{
+ if (dev->size != 0)
+ return 0;
+ if (dev->maj == LOOPDEV_MAJOR && loopdev_has_backing_file(dev->filename))
+ return 0;
+ return 1;
+}
+
/*
* Reads very basic information about the device from sysfs into the device struct
*/
dev->size <<= 9; /* in bytes */
/* Ignore devices of zero size */
- if (!lsblk->all_devices && dev->size == 0) {
+ if (!lsblk->all_devices && ignore_empty(dev)) {
DBG(DEV, ul_debugobj(dev, "zero size device -- ignore"));
return -1;
}