]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add FSROOTS column
authorKarel Zak <kzak@redhat.com>
Fri, 8 Jan 2021 12:33:30 +0000 (13:33 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 8 Jan 2021 12:33:30 +0000 (13:33 +0100)
It displays filesystem root attached to system, for example
btrfs with two mounted subvolumes:

$ lsblk -oNAME,SIZE,MOUNTPOINTS,FSROOTS /dev/sdc1
NAME SIZE MOUNTPOINTS FSROOTS
sdc1  50M /mnt/A      /foo
  /mnt/B      /bar

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c

index d41743794302f766c99650ea3f961803477477d3..35c3465945b31d964ed882b9b45fd0b074a71a09 100644 (file)
@@ -74,6 +74,7 @@ enum {
        COL_FSTYPE,
        COL_FSUSED,
        COL_FSUSEPERC,
+       COL_FSROOTS,
        COL_FSVERSION,
        COL_TARGET,
        COL_TARGETS,
@@ -164,6 +165,7 @@ static struct colinfo infos[] = {
        [COL_FSTYPE]    = { "FSTYPE", 0.1, SCOLS_FL_TRUNC, N_("filesystem type") },
        [COL_FSUSED]    = { "FSUSED", 5, SCOLS_FL_RIGHT, N_("filesystem size used") },
        [COL_FSUSEPERC] = { "FSUSE%", 3, SCOLS_FL_RIGHT, N_("filesystem use percentage") },
+       [COL_FSROOTS]   = { "FSROOTS", 0.1, SCOLS_FL_WRAP, N_("mounted filesystem roots") },
        [COL_FSVERSION] = { "FSVER", 0.1, SCOLS_FL_TRUNC, N_("filesystem version") },
 
        [COL_TARGET]    = { "MOUNTPOINT",  0.10, SCOLS_FL_TRUNC, N_("where the device is mounted") },
@@ -825,6 +827,24 @@ static char *device_get_data(
                str = ul_buffer_get_data(&buf);
                break;
        }
+       case COL_FSROOTS:
+       {
+               size_t i, n = 0;
+               struct ul_buffer buf = UL_INIT_BUFFER;
+               struct libmnt_fs **fss = lsblk_device_get_filesystems(dev, &n);
+
+               for (i = 0; i < n; i++) {
+                       struct libmnt_fs *fs = fss[i];
+                       const char *root = mnt_fs_get_root(fs);
+                       if (mnt_fs_is_swaparea(fs))
+                               continue;
+                       ul_buffer_append_string(&buf, root ? root : "/");
+                       if (i + 1 < n)
+                               ul_buffer_append_data(&buf, "\n", 1);
+               }
+               str = ul_buffer_get_data(&buf);
+               break;
+       }
        case COL_LABEL:
                prop = lsblk_device_get_properties(dev);
                if (prop && prop->label)