diff options
-rw-r--r-- | sys-utils/mount.8 | 14 | ||||
-rw-r--r-- | sys-utils/mount.c | 21 |
2 files changed, 27 insertions, 8 deletions
diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index 6c222d032..fc4622d2b 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -115,13 +115,13 @@ options to avoid ambivalent interpretation of the given argument. For example .B The listing and help. .RS -Three forms of invocation do not actually mount anything: -.TP -.B "mount \-h" -prints a help message -.TP -.B "mount \-V" -prints a version string +The listing mode is maintained for backward compatibility only. + +For more robust and definable output use +.BR findmnt (8), +\fBespecially in your scripts\fP. Note that control characters in the +mountpoint name are replaced with '?'. + .TP .BR "mount " [ -l "] [" "-t \fItype\fP" ] lists all mounted filesystems (of type diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 3b9f2c4b6..2d1d2cd41 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -30,6 +30,7 @@ #include <sys/stat.h> #include <stdarg.h> #include <libmount.h> +#include <ctype.h> #include "nls.h" #include "c.h" @@ -130,6 +131,22 @@ static void encrypt_pass_release(struct libmnt_context *cxt munlockall(); } +/* + * Replace control chars with '?' to be compatible with coreutils. For more + * robust solution use findmnt(1) where we use \x?? hex encoding. + */ +static void safe_fputs(const char *data) +{ + const char *p; + + for (p = data; p && *p; p++) { + if (iscntrl((unsigned char) *p)) + fputc('?', stdout); + else + fputc(*p, stdout); + } +} + static void print_all(struct libmnt_context *cxt, char *pattern, int show_label) { struct libmnt_table *tb; @@ -157,7 +174,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); - printf ("%s on %s", xsrc ? xsrc : src, mnt_fs_get_target(fs)); + printf ("%s on ", xsrc ? xsrc : src); + safe_fputs(mnt_fs_get_target(fs)); + if (type) printf (" type %s", type); if (optstr) |