From c1fb95a3d859a2bbccbdf333363d518ba9b798d7 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 19 Mar 2024 11:20:22 -0500 Subject: [PATCH] Teach mount to show file= option when displaying loopback mounts. --- toys/lsb/mount.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c index 9fbd432c..2b397f34 100644 --- a/toys/lsb/mount.c +++ b/toys/lsb/mount.c @@ -373,13 +373,28 @@ void mount_main(void) // show mounts from /proc/mounts } else if (!dev) { for (mtl = xgetmountlist(0); mtl && (mm = dlist_pop(&mtl)); free(mm)) { - char *s = 0; + char *s = mm->device, *ss = ""; + struct stat st; if (TT.t && strcmp(TT.t, mm->type)) continue; - if (*mm->device == '/') s = xabspath(mm->device, 0); - xprintf("%s on %s type %s (%s)\n", - s ? s : mm->device, mm->dir, mm->type, mm->opts); - free(s); + if (*s == '/') { + s = xabspath(mm->device, 0); + if (!stat(s, &st) && S_ISBLK(st.st_mode) &&dev_major(st.st_rdev)==7) { + char *temp = xmprintf("/sys/block/loop%d/loop/backing_file", + dev_minor(st.st_rdev)); + + ss = chomp(readfile(temp, 0, 0)); + free(temp); + if (ss) { + temp = xmprintf(",file=%s"+!*mm->opts, ss); + free(ss); + ss = temp; + } + } + } + xprintf("%s on %s type %s (%s%s)\n", s, mm->dir, mm->type, mm->opts, ss); + if (s != mm->device) free(s); + if (*ss) free(ss); } // two arguments -- 2.39.2