Skip to contentSkip to conversation

Add mount -P to hide pseudo filesystems

PATCH In review David Wilson 4 participants 7 messages Dec 6, 2015 – Dec 10, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add mount -P to hide pseudo filesystems

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

---
 sys-utils/mount.8 |  4 ++++
 sys-utils/mount.c | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
sys-utils/mount.8 +4 -0
index 004a513..311b514 100644
@@ -663,6 +663,10 @@ sections.
 .RE
 
 .TP
+.BR \-P , " \-\-no\-pseudofs"
+Inhibit listing of pseudo filesystem mounts. Only mounts backed by a network
+location or block device are displayed.
+.TP
 .BR \-R , " \-\-rbind"
 Remount a subtree and all possible submounts somewhere else (so that its
 contents are available in both places).  See above.
sys-utils/mount.c +13 -4
index 73f9d0b..17dba9e 100644
@@ -120,7 +120,8 @@ static void safe_fputs(const char *data)
 	}
 }
 
-static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
+static void print_all(struct libmnt_context *cxt, char *pattern,
+		      int show_label, int no_pseudofs)
 {
 	struct libmnt_table *tb;
 	struct libmnt_iter *itr = NULL;
@@ -147,6 +148,9 @@ static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
 
 		if (!mnt_fs_is_pseudofs(fs))
 			xsrc = mnt_pretty_path(src, cache);
+		else if (no_pseudofs)
+			continue;
+
 		printf ("%s on ", xsrc ? xsrc : src);
 		safe_fputs(mnt_fs_get_target(fs));
 
@@ -740,6 +744,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 	fprintf(out, _(
 	" -o, --options <list>    comma-separated list of mount options\n"
 	" -O, --test-opts <list>  limit the set of filesystems (use with -a)\n"
+	" -P, --no-pseudofs       inhibit listing of pseudo filesystems\n"
 	" -r, --read-only         mount the filesystem read-only (same as -o ro)\n"
 	" -t, --types <list>      limit the set of filesystem types\n"));
 	fprintf(out, _(
@@ -792,6 +797,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
 	int c, rc = MOUNT_EX_SUCCESS, all = 0, show_labels = 0;
+	int no_pseudofs = 0;
 	struct libmnt_context *cxt;
 	struct libmnt_table *fstab = NULL;
 	char *srcbuf = NULL;
@@ -842,6 +848,7 @@ int main(int argc, char **argv)
 		{ "make-rprivate", 0, 0, MOUNT_OPT_RPRIVATE },
 		{ "make-runbindable", 0, 0, MOUNT_OPT_RUNBINDABLE },
 		{ "no-canonicalize", 0, 0, 'c' },
+		{ "no-pseudofs", 0, 0, 'P' },
 		{ "internal-only", 0, 0, 'i' },
 		{ "show-labels", 0, 0, 'l' },
 		{ "target", 1, 0, MOUNT_OPT_TARGET },
@@ -869,12 +876,12 @@ int main(int argc, char **argv)
 
 	mnt_context_set_tables_errcb(cxt, table_parser_errcb);
 
-	while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:rRsU:vVwt:T:",
+	while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:PrRsU:vVwt:T:",
 					longopts, NULL)) != -1) {
 
 		/* only few options are allowed for non-root users */
 		if (mnt_context_is_restricted(cxt) &&
-		    !strchr("hlLUVvrist", c) &&
+		    !strchr("hlLUVvPrist", c) &&
 		    c != MOUNT_OPT_TARGET &&
 		    c != MOUNT_OPT_SOURCE)
 			exit_non_root(option_to_longopt(c, longopts));
@@ -939,6 +946,8 @@ int main(int argc, char **argv)
 		case 'l':
 			show_labels = 1;
 			break;
+		case 'P':
+			no_pseudofs = 1;
 		case 't':
 			types = optarg;
 			break;
@@ -1021,7 +1030,7 @@ int main(int argc, char **argv)
 	    !all) {
 		if (oper || mnt_context_get_options(cxt))
 			usage(stderr);
-		print_all(cxt, types, show_labels);
+		print_all(cxt, types, show_labels, no_pseudofs);
 		goto done;
 	}
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 64 lines · David Wilson

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

---
 sys-utils/mount.8 |  4 ++++
 sys-utils/mount.c | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
sys-utils/mount.8 +4 -0
index 004a513..311b514 100644
@@ -663,6 +663,10 @@ sections.
 .RE
 
 .TP
+.BR \-P , " \-\-no\-pseudofs"
+Inhibit listing of pseudo filesystem mounts. Only mounts backed by a network
+location or block device are displayed.
+.TP
 .BR \-R , " \-\-rbind"
 Remount a subtree and all possible submounts somewhere else (so that its
 contents are available in both places).  See above.
sys-utils/mount.c +7 -1
index 73f9d0b..17dba9e 100644
@@ -120,7 +120,8 @@ static void safe_fputs(const char *data)
        }
 }
 
-static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
+static void print_all(struct libmnt_context *cxt, char *pattern,
+                     int show_label, int no_pseudofs)
 {
        struct libmnt_table *tb;
        struct libmnt_iter *itr = NULL;
@@ -147,6 +148,9 @@ static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
 
                if (!mnt_fs_is_pseudofs(fs))
                        xsrc = mnt_pretty_path(src, cache);
+               else if (no_pseudofs)
+                       continue;
+
                printf ("%s on ", xsrc ? xsrc : src);
                safe_fputs(mnt_fs_get_target(fs));
 
@@ -740,6 +744,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fprintf(out, _(
        " -o, --options <list>    comma-separated list of mount options\n"
        " -O, --test-opts <list>  limit the set of filesystems (use with -a)\n"
+       " -P, --no-pseudofs       inhibit listing of pseudo filesystems\n"
        " -r, --read-only         mount the filesystem read-only (same as -o ro)\n"
        " -t, --types <list>      limit the set of filesystem types\n"));
        fprintf(out, _(
@@ -792,6 +797,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
        int c, rc = MOUNT_EX_SUCCESS, all = 0, show_labels = 0;
+       int no_pseudofs = 0;
        struct libmnt_context *cxt;
        struct libmnt_table *fstab = NULL;
        char *srcbuf = NULL;

sys-utils/mount.c int main(int argc, char **argv) · line 851

Quoted 4 lines
sys-utils/mount.c +1 -0
@@ -842,6 +848,7 @@ int main(int argc, char **argv)
                { "make-rprivate", 0, 0, MOUNT_OPT_RPRIVATE },
                { "make-runbindable", 0, 0, MOUNT_OPT_RUNBINDABLE },
                { "no-canonicalize", 0, 0, 'c' },
+               { "no-pseudofs", 0, 0, 'P' },

Hi David,

I doubt this is common enough case to assign short option. How about long-only option, see MOUNT_OPT_RUNBINDABLE for an example how to make that work.

Quoted 42 lines
sys-utils/mount.c +5 -4
                { "internal-only", 0, 0, 'i' },
                { "show-labels", 0, 0, 'l' },
                { "target", 1, 0, MOUNT_OPT_TARGET },
@@ -869,12 +876,12 @@ int main(int argc, char **argv)
 
        mnt_context_set_tables_errcb(cxt, table_parser_errcb);
 
-       while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:rRsU:vVwt:T:",
+       while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:PrRsU:vVwt:T:",
                                        longopts, NULL)) != -1) {
 
                /* only few options are allowed for non-root users */
                if (mnt_context_is_restricted(cxt) &&
-                   !strchr("hlLUVvrist", c) &&
+                   !strchr("hlLUVvPrist", c) &&
                    c != MOUNT_OPT_TARGET &&
                    c != MOUNT_OPT_SOURCE)
                        exit_non_root(option_to_longopt(c, longopts));
@@ -939,6 +946,8 @@ int main(int argc, char **argv)
                case 'l':
                        show_labels = 1;
                        break;
+               case 'P':
+                       no_pseudofs = 1;
                case 't':
                        types = optarg;
                        break;
@@ -1021,7 +1030,7 @@ int main(int argc, char **argv)
            !all) {
                if (oper || mnt_context_get_options(cxt))
                        usage(stderr);
-               print_all(cxt, types, show_labels);
+               print_all(cxt, types, show_labels, no_pseudofs);
                goto done;
        }
 
--

2.1.4
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#2 lore raw
Quoted 72 lines · Sami Kerola
Quoted 64 lines · David Wilson

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

---
 sys-utils/mount.8 |  4 ++++
 sys-utils/mount.c | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
sys-utils/mount.8 +4 -0
index 004a513..311b514 100644
@@ -663,6 +663,10 @@ sections.
 .RE
 
 .TP
+.BR \-P , " \-\-no\-pseudofs"
+Inhibit listing of pseudo filesystem mounts. Only mounts backed by a network
+location or block device are displayed.
+.TP
 .BR \-R , " \-\-rbind"
 Remount a subtree and all possible submounts somewhere else (so that its
 contents are available in both places).  See above.
sys-utils/mount.c +7 -1
index 73f9d0b..17dba9e 100644
@@ -120,7 +120,8 @@ static void safe_fputs(const char *data)
        }
 }
 
-static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
+static void print_all(struct libmnt_context *cxt, char *pattern,
+                     int show_label, int no_pseudofs)
 {
        struct libmnt_table *tb;
        struct libmnt_iter *itr = NULL;
@@ -147,6 +148,9 @@ static void print_all(struct libmnt_context *cxt, char *pattern, int show_label)
 
                if (!mnt_fs_is_pseudofs(fs))
                        xsrc = mnt_pretty_path(src, cache);
+               else if (no_pseudofs)
+                       continue;
+
                printf ("%s on ", xsrc ? xsrc : src);
                safe_fputs(mnt_fs_get_target(fs));
 
@@ -740,6 +744,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fprintf(out, _(
        " -o, --options <list>    comma-separated list of mount options\n"
        " -O, --test-opts <list>  limit the set of filesystems (use with -a)\n"
+       " -P, --no-pseudofs       inhibit listing of pseudo filesystems\n"
        " -r, --read-only         mount the filesystem read-only (same as -o ro)\n"
        " -t, --types <list>      limit the set of filesystem types\n"));
        fprintf(out, _(
@@ -792,6 +797,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
        int c, rc = MOUNT_EX_SUCCESS, all = 0, show_labels = 0;
+       int no_pseudofs = 0;
        struct libmnt_context *cxt;
        struct libmnt_table *fstab = NULL;
        char *srcbuf = NULL;

sys-utils/mount.c int main(int argc, char **argv) · line 851

Quoted 4 lines
sys-utils/mount.c +1 -0
@@ -842,6 +848,7 @@ int main(int argc, char **argv)
                { "make-rprivate", 0, 0, MOUNT_OPT_RPRIVATE },
                { "make-runbindable", 0, 0, MOUNT_OPT_RUNBINDABLE },
                { "no-canonicalize", 0, 0, 'c' },
+               { "no-pseudofs", 0, 0, 'P' },

Hi David,

Quoted 3 lines

I doubt this is common enough case to assign short option. How about long-only option, see MOUNT_OPT_RUNBINDABLE for an example how to make that work.

I agree, although I see little value in a patch if it becomes hard to type. At that point copying around a wrapper script named 'mountp' is probably easier. :)

How about some shorter spelling for --no-pseudofs, say, --real or --plain, or maybe it just becomes neater to extend -t. How about spellings of -t like:

"-t [no]pseudo" -> anon_inodefs,bdev,cgroup,..,tmpfs "-t [no]net" -> cifs,smbfs,...,9p
"-t [no]plain" -> nopseudo,nonet

David

Quoted 50 lines
Quoted 39 lines
sys-utils/mount.c +5 -4
                { "internal-only", 0, 0, 'i' },
                { "show-labels", 0, 0, 'l' },
                { "target", 1, 0, MOUNT_OPT_TARGET },
@@ -869,12 +876,12 @@ int main(int argc, char **argv)
 
        mnt_context_set_tables_errcb(cxt, table_parser_errcb);
 
-       while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:rRsU:vVwt:T:",
+       while ((c = getopt_long(argc, argv, "aBcfFhilL:Mno:O:PrRsU:vVwt:T:",
                                        longopts, NULL)) != -1) {
 
                /* only few options are allowed for non-root users */
                if (mnt_context_is_restricted(cxt) &&
-                   !strchr("hlLUVvrist", c) &&
+                   !strchr("hlLUVvPrist", c) &&
                    c != MOUNT_OPT_TARGET &&
                    c != MOUNT_OPT_SOURCE)
                        exit_non_root(option_to_longopt(c, longopts));
@@ -939,6 +946,8 @@ int main(int argc, char **argv)
                case 'l':
                        show_labels = 1;
                        break;
+               case 'P':
+                       no_pseudofs = 1;
                case 't':
                        types = optarg;
                        break;
@@ -1021,7 +1030,7 @@ int main(int argc, char **argv)
            !all) {
                if (oper || mnt_context_get_options(cxt))
                        usage(stderr);
-               print_all(cxt, types, show_labels);
+               print_all(cxt, types, show_labels, no_pseudofs);
                goto done;
        }
 
--
Quoted 5 lines

2.1.4
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Sami Kerola
http://www.iki.fi/kerolasa/

#3 lore raw
Quoted 18 lines · David Wilson
Quoted 9 lines · Sami Kerola

sys-utils/mount.c int main(int argc, char **argv) · line 851

Quoted 5 lines · David Wilson
sys-utils/mount.c +1 -0
@@ -842,6 +848,7 @@ int main(int argc, char **argv)
                { "make-rprivate", 0, 0, MOUNT_OPT_RPRIVATE },
                { "make-runbindable", 0, 0, MOUNT_OPT_RUNBINDABLE },
                { "no-canonicalize", 0, 0, 'c' },
+               { "no-pseudofs", 0, 0, 'P' },

Hi David,

Quoted 3 lines

I doubt this is common enough case to assign short option. How about long-only option, see MOUNT_OPT_RUNBINDABLE for an example how to make that work.

I agree, although I see little value in a patch if it becomes hard to type. At that point copying around a wrapper script named 'mountp' is probably easier. :)

Quoted 7 lines

How about some shorter spelling for --no-pseudofs, say, --real or --plain, or maybe it just becomes neater to extend -t. How about spellings of -t like:

"-t [no]pseudo" -> anon_inodefs,bdev,cgroup,..,tmpfs "-t [no]net" -> cifs,smbfs,...,9p
"-t [no]plain" -> nopseudo,nonet

Hi David,

Maybe you can rely gnu getops doing the right thing with '--no-p' when typing. In scripts I recommend to use the full option. Try the following ls(1) examples to see how the getops allows truncating long options. I think it is unfortunate option shortening is not widely know.

ls --h
ls --he

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
maintainer
#4 lore raw
In reply to David Wilson
Quoted 3 lines · David Wilson

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

I don't plan to improve mount(8) list output in any way to duplicate findmnt(8). Please, let's use (and improve) findmnt(8). Thanks.

Anyway,

     --real
     --net
     --pseudo

sounds good for findmnt. Look forward for a patch :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw
Quoted 8 lines · Karel Zak
Quoted 3 lines · David Wilson

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

I don't plan to improve mount(8) list output in any way to duplicate findmnt(8). Please, let's use (and improve) findmnt(8). Thanks.

Quoted 7 lines

Anyway,

      --real
      --net
      --pseudo

sounds good for findmnt. Look forward for a patch :-)

Is it possible to detect --bind in findmnt?

-- Bruce

maintainer
#6 lore raw
Quoted 11 lines · Bruce Dubbs
Quoted 10 lines · Karel Zak
Quoted 3 lines · David Wilson

This is just shorthand for an increasingly necessary yet cumbersome and error-prone "grep -v" pipe. The alternative was to extend -t to accept "nopseudofs", but that is tougher on the fingers.

I don't plan to improve mount(8) list output in any way to duplicate findmnt(8). Please, let's use (and improve) findmnt(8). Thanks.

Anyway,

Quoted 7 lines
Quoted 5 lines
     --real
     --net
     --pseudo

sounds good for findmnt. Look forward for a patch :-)

Is it possible to detect --bind in findmnt?

No, nowhere in the system is information about a way how the filesystem has been mounted to the system. (Well, except obsolete classic /etc/mtab.)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com