From 3ab4ef3ca9bf77b7dbb924fa75dcc9f7c6c3ea59 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Mar 2021 14:58:05 +0100 Subject: [PATCH] findmnt: add --shadowed Signed-off-by: Karel Zak --- misc-utils/findmnt.8 | 3 +++ misc-utils/findmnt.c | 16 +++++++++++++++- misc-utils/findmnt.h | 13 +++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8 index c93c01c20..658dda9eb 100644 --- a/misc-utils/findmnt.8 +++ b/misc-utils/findmnt.8 @@ -193,6 +193,9 @@ available for umount and remount actions .B \-\-pseudo Print only pseudo filesystems. .TP +.B \-\-shadowed +Print only filesystems over-mounted by another filesystem. +.TP .BR \-R , " \-\-submounts" Print recursively all submounts for the selected filesystems. The restrictions defined by options \fB\-t\fP, \fB\-O\fP, \fB\-S\fP, \fB\-T\fP and diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 774c059de..a1c692535 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -970,6 +970,14 @@ static int match_func(struct libmnt_fs *fs, if ((flags & FL_PSEUDO) && !mnt_fs_is_pseudofs(fs)) return rc; + if ((flags & FL_SHADOWED)) { + struct libmnt_table *tb = NULL; + + mnt_fs_get_table(fs, &tb); + if (tb && mnt_table_over_fs(tb, fs, NULL) != 0) + return rc; + } + return !rc; } @@ -1254,6 +1262,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" --output-all output all available columns\n"), out); fputs(_(" -P, --pairs use key=\"value\" output format\n"), out); fputs(_(" --pseudo print only pseudo-filesystems\n"), out); + fputs(_(" --shadowed print only filesystems over-mounted by another filesystem\n"), out); fputs(_(" -R, --submounts print all submounts for the matching filesystems\n"), out); fputs(_(" -r, --raw use raw output format\n"), out); fputs(_(" --real print only real filesystems\n"), out); @@ -1304,7 +1313,8 @@ int main(int argc, char *argv[]) FINDMNT_OPT_OUTPUT_ALL, FINDMNT_OPT_PSEUDO, FINDMNT_OPT_REAL, - FINDMNT_OPT_VFS_ALL + FINDMNT_OPT_VFS_ALL, + FINDMNT_OPT_SHADOWED }; static const struct option longopts[] = { @@ -1349,6 +1359,7 @@ int main(int argc, char *argv[]) { "real", no_argument, NULL, FINDMNT_OPT_REAL }, { "pseudo", no_argument, NULL, FINDMNT_OPT_PSEUDO }, { "vfs-all", no_argument, NULL, FINDMNT_OPT_VFS_ALL }, + { "shadowed", no_argument, NULL, FINDMNT_OPT_SHADOWED }, { NULL, 0, NULL, 0 } }; @@ -1526,6 +1537,9 @@ int main(int argc, char *argv[]) case FINDMNT_OPT_VFS_ALL: flags |= FL_VFS_ALL; break; + case FINDMNT_OPT_SHADOWED: + flags |= FL_SHADOWED; + break; case 'h': usage(); diff --git a/misc-utils/findmnt.h b/misc-utils/findmnt.h index 92d1119ae..ed7dea05a 100644 --- a/misc-utils/findmnt.h +++ b/misc-utils/findmnt.h @@ -21,14 +21,15 @@ enum { FL_PSEUDO = (1 << 17), FL_REAL = (1 << 18), FL_VFS_ALL = (1 << 19), + FL_SHADOWED = (1 << 20), /* basic table settings */ - FL_ASCII = (1 << 20), - FL_RAW = (1 << 21), - FL_NOHEADINGS = (1 << 22), - FL_EXPORT = (1 << 23), - FL_TREE = (1 << 24), - FL_JSON = (1 << 25), + FL_ASCII = (1 << 21), + FL_RAW = (1 << 22), + FL_NOHEADINGS = (1 << 23), + FL_EXPORT = (1 << 24), + FL_TREE = (1 << 25), + FL_JSON = (1 << 26), }; extern struct libmnt_cache *cache;