]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: improve --df output
authorKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2012 09:43:29 +0000 (10:43 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2012 09:52:13 +0000 (10:52 +0100)
 * don't print pseudo-filesystems (except tmpfs)
 * add --all to disable built-in filters
 * don't overwrite --df --output=<list> with default columns

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

index e98233009d5a7a6ecd9641fd73946b5e9241b52a..d5a98b4e2cc267a8e42941f700c93befeaf65d9e 100644 (file)
@@ -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
index f985ed0d9aec2b368b847d8801705259f4ff7a7f..9ac7c460c893d44b4c6e40df5be62ba661716d41 100644 (file)
@@ -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 <num>    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;