From: Karel Zak Date: Thu, 5 Aug 2010 10:26:00 +0000 (+0200) Subject: findmnt: add support for fs-root (subvolumes and bind mounts) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2214e1f3e6e58fce214c8d68c4c7a3660a2d362;p=util-linux findmnt: add support for fs-root (subvolumes and bind mounts) This patch modifies the default output for SOURCE column. All btrfs subvolume mountpoints and all bind-mount (where source is not root of FS) will be printed as: SOURCE TARGET /dev/sda1[/aaa] /mnt/test where /aaa is subvolume name or fs root for bind mounts, it means: # mount -t btrfs /dev/sda1 /mnt/test -o subvol=aaa or: # mount --bind /aaa /mnt/test The info about fs-root is 4th column in /proc/self/mountinfo. Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8 index 65cef44b..2f9dd74a 100644 --- a/misc-utils/findmnt.8 +++ b/misc-utils/findmnt.8 @@ -65,6 +65,8 @@ Print the first matching filesystem only. Invert the sense of matching. .IP "\fB\-l, \-\-list\fP" Use the list output format. +.IP "\fB\-v, \-\-nofsroot\fP" +Do not print a [/dir] in the SOURCE column for bind-mounts or btrfs subvolumes. .IP "\fB\-n, \-\-noheadings\fP" Do not print a header line. .IP "\fB\-u, \-\-notruncate\fP" diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 7314bb6e..4a83223f 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -46,6 +46,7 @@ enum { FL_FIRSTONLY = (1 << 3), FL_INVERT = (1 << 4), FL_NOSWAPMATCH = (1 << 6), + FL_NOFSROOT = (1 << 7), }; /* column IDs */ @@ -215,7 +216,9 @@ static const char *get_data(mnt_fs *fs, int num) switch(get_column_id(num)) { case COL_SOURCE: - /* dir or dev */ + { + const char *root = mnt_fs_get_root(fs); + str = mnt_fs_get_srcpath(fs); if (str && (flags & FL_CANONICALIZE)) @@ -226,7 +229,14 @@ static const char *get_data(mnt_fs *fs, int num) if (str && (flags & FL_EVALUATE)) str = mnt_resolve_spec(str, cache); } + if (root && str && !(flags & FL_NOFSROOT) && strcmp(root, "/")) { + char *tmp; + + if (asprintf(&tmp, "%s[%s]", str, root) > 0) + str = tmp; + } break; + } case COL_TARGET: str = mnt_fs_get_target(fs); break; @@ -450,6 +460,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) " -r, --raw use raw format output\n" " -a, --ascii use ascii chars for tree formatting\n" " -t, --types limit the set of filesystem by FS types\n" + " -v, --nofsroot don't print [/dir] for bind or btrfs mounts\n" " -S, --source device, LABEL= or UUID=device\n" " -T, --target mountpoint\n\n")); @@ -508,6 +519,7 @@ int main(int argc, char *argv[]) { "output", 1, 0, 'o' }, { "raw", 0, 0, 'r' }, { "types", 1, 0, 't' }, + { "fsroot", 0, 0, 'v' }, { "source", 1, 0, 'S' }, { "target", 1, 0, 'T' }, @@ -530,7 +542,7 @@ int main(int argc, char *argv[]) tt_flags |= TT_FL_TREE; while ((c = getopt_long(argc, argv, - "acd:ehifo:O:klmnrst:uS:T:", longopts, NULL)) != -1) { + "acd:ehifo:O:klmnrst:uvS:T:", longopts, NULL)) != -1) { switch(c) { case 'a': tt_flags |= TT_FL_ASCII; @@ -603,6 +615,9 @@ int main(int argc, char *argv[]) case 'n': tt_flags |= TT_FL_NOHEADINGS; break; + case 'v': + flags |= FL_NOFSROOT; + break; case 'S': set_match(COL_SOURCE, optarg); flags |= FL_NOSWAPMATCH; @@ -625,6 +640,7 @@ int main(int argc, char *argv[]) tt_flags &= ~TT_FL_TREE; } } + if (optind < argc && (get_match(COL_SOURCE) || get_match(COL_TARGET))) errx(EXIT_FAILURE, _( "options --target and --source can't be used together "