summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2016-12-08 14:24:41 +0100
committerKarel Zak2016-12-08 14:24:41 +0100
commit3ebe5477db75f372f2926d3d70599bcdeb7b5a17 (patch)
tree5d1cd4fead8578316d0ac2859ce13040c9fd39cf
parentfindmnt: add note about mount options (diff)
downloadkernel-qcow2-util-linux-3ebe5477db75f372f2926d3d70599bcdeb7b5a17.tar.gz
kernel-qcow2-util-linux-3ebe5477db75f372f2926d3d70599bcdeb7b5a17.tar.xz
kernel-qcow2-util-linux-3ebe5477db75f372f2926d3d70599bcdeb7b5a17.zip
findmnt: add --tree to allow to enable tree output for --mtab
The --mtab output is merge from kernel and utab on all modern systems (without classic /etc/mtab). It means we have all necessary information to generate tree output. For the backward compatibility --mtab is the list by default, the new option --tree allows to override the default and enable tree always when the table contains child-parent relations. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--bash-completion/findmnt1
-rw-r--r--misc-utils/findmnt.86
-rw-r--r--misc-utils/findmnt.c15
3 files changed, 19 insertions, 3 deletions
diff --git a/bash-completion/findmnt b/bash-completion/findmnt
index 946c22a98..5583fbf6c 100644
--- a/bash-completion/findmnt
+++ b/bash-completion/findmnt
@@ -127,6 +127,7 @@ _findmnt_module()
--target
--mountpoint
--help
+ --tree
--version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
index 6fc7da59e..144c8c613 100644
--- a/misc-utils/findmnt.8
+++ b/misc-utils/findmnt.8
@@ -110,7 +110,7 @@ Explicitly define the mountpoint file or directory. See also \fB\-\-target\fP.
.BR \-m , " \-\-mtab"
Search in
.IR /etc/mtab .
-The output is in the list format (see \fB\-\-list\fP). The output may include user
+The output is in the list format by default (see \fB\-\-tree\fP). The output may include user
space mount options.
.TP
.BR \-N , " \-\-task \fItid\fP"
@@ -216,6 +216,10 @@ to specify the filesystem types on which no action should be taken. For
more details see
.BR mount (8).
.TP
+.BR " \-\-tree"
+Enable tree-like output if possible. The options is silently ignored for
+tables where is missing child-parent relation (e.g. fstab).
+.TP
.BR \-U , " \-\-uniq"
Ignore filesystems with duplicate mount targets, thus effectively skipping
over-mounted mount points.
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index f2c0b27b4..564c74cc3 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -1227,6 +1227,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -S, --source <string> the device to mount (by name, maj:min, \n"
" LABEL=, UUID=, PARTUUID=, PARTLABEL=)\n"), out);
fputs(_(" -T, --target <path> the path to the filesystem to use\n"), out);
+ fputs(_(" --tree enable tree format output is possible\n"), out);
fputs(_(" -M, --mountpoint <dir> the mountpoint directory\n"), out);
fputs(_(" -t, --types <list> limit the set of filesystems by FS types\n"), out);
fputs(_(" -U, --uniq ignore filesystems with duplicate target\n"), out);
@@ -1262,11 +1263,13 @@ int main(int argc, char *argv[])
int ntabfiles = 0, tabtype = 0;
char *outarg = NULL;
size_t i;
+ int force_tree = 0, istree = 0;
struct libscols_table *table = NULL;
enum {
- FINDMNT_OPT_VERBOSE = CHAR_MAX + 1
+ FINDMNT_OPT_VERBOSE = CHAR_MAX + 1,
+ FINDMNT_OPT_TREE
};
static const struct option longopts[] = {
@@ -1306,6 +1309,7 @@ int main(int argc, char *argv[])
{ "verify", 0, 0, 'x' },
{ "version", 0, 0, 'V' },
{ "verbose", 0, 0, FINDMNT_OPT_VERBOSE },
+ { "tree", 0, 0, FINDMNT_OPT_TREE },
{ NULL, 0, 0, 0 }
};
@@ -1469,6 +1473,9 @@ int main(int argc, char *argv[])
case FINDMNT_OPT_VERBOSE:
flags |= FL_VERBOSE;
break;
+ case FINDMNT_OPT_TREE:
+ force_tree = 1;
+ break;
default:
usage(stderr);
break;
@@ -1551,7 +1558,11 @@ int main(int argc, char *argv[])
if (tabtype == TABTYPE_MTAB && tab_is_kernel(tb))
tabtype = TABTYPE_KERNEL;
- if ((flags & FL_TREE) && (ntabfiles > 1 || !tab_is_tree(tb)))
+ istree = tab_is_tree(tb);
+ if (istree && force_tree)
+ flags |= FL_TREE;
+
+ if ((flags & FL_TREE) && (ntabfiles > 1 || !istree))
flags &= ~FL_TREE;
if (!(flags & FL_NOCACHE)) {