- clean up error codes
- use err() and warn() macros rather than fprintf(stderr, ...)
+
+losetup
+-------
+
+ - don't use ioclts if sysfs supports loop attributes (since 2.6.37,
+ block/loopN/loop/* files)
+
+ - don't open loopdev in looplist_next(), check if /sys/block/loopN/loop
+ exists and returns ll.name rather than file descriptor
+
+ - add sysfs based version of show_loop() and use it for non-root users
+
+sysfs
+-----
+
+ - add lib/sysfs.c with functions that read block device attributes from /sys.
+ For more details see devno.c from libblkid, lsblk.c and lomount.c.
+
+
libblkid
--------
- add support for dasd PT (used for example on s390)
+
blkid(8)
-------
#define LLFLG_SUBDIR (1 << 5) /* /dev/loop/N */
#define LLFLG_DFLT (1 << 6) /* directly try to check default loops */
+/* TODO: move to lib/sysfs.c */
+static char *loopfile_from_sysfs(const char *device)
+{
+ FILE *f;
+ struct stat st;
+ char buf[PATH_MAX], *res = NULL;
+
+ if (stat(device, &st) || !S_ISBLK(st.st_mode))
+ return NULL;
+
+ snprintf(buf, sizeof(buf), _PATH_SYS_DEVBLOCK "/%d:%d/loop/backing_file",
+ major(st.st_rdev), minor(st.st_rdev));
+
+ f = fopen(buf, "r");
+ if (!f)
+ return NULL;
+
+ if (fgets(buf, sizeof(buf), f)) {
+ size_t sz = strlen(buf);
+ if (sz) {
+ buf[sz - 1] = '\0';
+ res = xstrdup(buf);
+ }
+ }
+
+ fclose(f);
+ return res;
+}
+
int
is_loop_device (const char *device) {
struct stat st;
if (ioctl(fd, LOOP_GET_STATUS64, &loopinfo64) == 0) {
+ char *lofile = NULL;
+
loopinfo64.lo_file_name[LO_NAME_SIZE-2] = '*';
loopinfo64.lo_file_name[LO_NAME_SIZE-1] = 0;
loopinfo64.lo_crypt_name[LO_NAME_SIZE-1] = 0;
+ /* ioctl has limited buffer for backing file name, since
+ * kernel 2.6.37 the filename is available in sysfs too
+ */
+ if (strlen((char *) loopinfo64.lo_file_name) == LO_NAME_SIZE - 1)
+ lofile = loopfile_from_sysfs(device);
+ if (!lofile)
+ lofile = (char *) loopinfo64.lo_file_name;
+
printf("%s: [%04" PRIx64 "]:%" PRIu64 " (%s)",
device, loopinfo64.lo_device, loopinfo64.lo_inode,
- loopinfo64.lo_file_name);
+ lofile);
+
+ if (lofile != (char *) loopinfo64.lo_file_name)
+ free(lofile);
if (loopinfo64.lo_offset)
printf(_(", offset %" PRIu64 ), loopinfo64.lo_offset);