From cd4ed46f984f59d20af62107f85988548884ac2d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 20 Mar 2012 10:43:29 +0100 Subject: [PATCH] findmnt: improve --df output * don't print pseudo-filesystems (except tmpfs) * add --all to disable built-in filters * don't overwrite --df --output= with default columns Signed-off-by: Karel Zak --- misc-utils/findmnt.8 | 10 +++++++--- misc-utils/findmnt.c | 30 +++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8 index e98233009..d5a98b4e2 100644 --- a/misc-utils/findmnt.8 +++ b/misc-utils/findmnt.8 @@ -47,11 +47,17 @@ The output is in the list format (see --list). Search in .IR /proc/self/mountinfo . The output is in the tree-like format. This is the default. + +.IP "\fB\-A, \-\-all\fP" +Disable all built-in filters and print all filesystems. +.IP "\fB\-a, \-\-ascii\fP" +Use ascii characters for tree formatting. .IP "\fB\-c, \-\-canonicalize\fP" Canonicalize all printed paths. .IP "\fB\-D, \-\-df\fP" Imitate the output of df(1). This option is equivalent to -"-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET". +"-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET", but excludes all +pseudo filesystem. Use \fB\-\-all\fP to print all filesystems. .IP "\fB\-d, \-\-direction \fIword\fP" The search direction - .IR forward @@ -148,8 +154,6 @@ available for umount and remount actions Use key="value" output format. .IP "\fB\-r, \-\-raw\fP" Use raw output format. -.IP "\fB\-a, \-\-ascii\fP" -Use ascii characters for tree formatting. .IP "\fB\-t, \-\-types \fIlist\fP" Limit the set of printed filesystems. More than one type may be specified in a comma-separated list. The list of filesystem types can be diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index f985ed0d9..9ac7c460c 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -51,7 +51,9 @@ enum { FL_NOSWAPMATCH = (1 << 6), FL_NOFSROOT = (1 << 7), FL_SUBMOUNTS = (1 << 8), - FL_POLL = (1 << 9) + FL_POLL = (1 << 9), + FL_DF = (1 << 10), + FL_ALL = (1 << 11) }; /* column IDs */ @@ -192,6 +194,9 @@ static int is_tabdiff_column(int id) */ static int is_listall_mode(void) { + if ((flags & FL_DF) && !(flags & FL_ALL)) + return 0; + return (!get_match(COL_SOURCE) && !get_match(COL_TARGET) && !get_match(COL_FSTYPE) && @@ -638,6 +643,16 @@ static int match_func(struct libmnt_fs *fs, if (m && !mnt_fs_match_options(fs, m)) return rc; + if ((flags & FL_DF) && !(flags & FL_ALL)) { + const char *type = mnt_fs_get_fstype(fs); + + if (type && strstr(type, "tmpfs")) /* tmpfs is wanted */ + return !rc; + + if (mnt_fs_is_pseudofs(fs)) + return rc; + } + return !rc; } @@ -881,6 +896,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) " -w, --timeout upper limit in milliseconds that --poll will block\n\n")); fprintf(out, _( + " -A, --all disable all built-in filters, print all filesystems\n" " -a, --ascii use ASCII chars for tree formatting\n" " -c, --canonicalize canonicalize printed paths\n" " -D, --df imitate the output of df(1)\n" @@ -930,13 +946,14 @@ int main(int argc, char *argv[]) struct libmnt_table *tb = NULL; char **tabfiles = NULL; int direction = MNT_ITER_FORWARD; - int i, c, rc = -1, timeout = -1, df_output = 0; + int i, c, rc = -1, timeout = -1; int ntabfiles = 0, tabtype = 0; /* table.h */ struct tt *tt = NULL; static const struct option longopts[] = { + { "all", 0, 0, 'A' }, { "ascii", 0, 0, 'a' }, { "canonicalize", 0, 0, 'c' }, { "direction", 1, 0, 'd' }, @@ -977,9 +994,12 @@ int main(int argc, char *argv[]) tt_flags |= TT_FL_TREE; while ((c = getopt_long(argc, argv, - "acDd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:", + "AacDd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:", longopts, NULL)) != -1) { switch(c) { + case 'A': + flags |= FL_ALL; + break; case 'a': tt_flags |= TT_FL_ASCII; break; @@ -988,7 +1008,7 @@ int main(int argc, char *argv[]) break; case 'D': tt_flags &= ~TT_FL_TREE; - df_output = 1; + flags |= FL_DF; break; case 'd': if (!strcmp(optarg, "forward")) @@ -1099,7 +1119,7 @@ int main(int argc, char *argv[]) } } - if (df_output) { + if (!ncolumns && (flags & FL_DF)) { columns[ncolumns++] = COL_SOURCE; columns[ncolumns++] = COL_FSTYPE; columns[ncolumns++] = COL_SIZE;