Some tools add non-standard mount flags beginning with "x-", which are commonly used for adding comments and metadata to mountpoints. These can be optionally safely ignored, as they don't affect the functionality of the mount and would otherwise cause Busybox to fail to mount the device.
Some examples for such mount flags are "x-gdu.hide" and "x-gvfs-hide", both of which are used to indicate to userspace programs that a given mount should not be shown in a list of mounted partitions/filesystems. This patch does not change the current default behaviour; the mount flags will only be ignored if this feature is enabled. An additional verbose option has also been added to enable the ability to report that the mount flags have been ignored, rather than silently ignoring them. Signed-off-by: Isaac True <[email protected]> --- util-linux/mount.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/util-linux/mount.c b/util-linux/mount.c index 4e65b6b46..418aca171 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -107,6 +107,23 @@ //config: default y //config: help //config: Support mount -T (specifying an alternate fstab) +//config: +//config:config FEATURE_MOUNT_IGNORE_X_FLAGS +//config: depends on MOUNT +//config: bool "Ignore any mount flags starting with 'x-'" +//config: default n +//config: help +//config: Ignore any mount flags starting with 'x-', which are generally +//config: used for adding comments/metadata to mount points. Normally, +//config: the mount command would fail if one of these options is added. +//config: +//config:config FEATURE_MOUNT_IGNORE_X_FLAGS_VERBOSE +//config: depends on FEATURE_MOUNT_IGNORE_X_FLAGS +//config: bool "Report ignored mount flags" +//config: default y +//config: help +//config: If any mount flags starting with "x-" are being ignored, report +//config: them to the user. Otherwise, silently ignore them. /* On full-blown systems, requires suid for user mounts. * But it's not unthinkable to have it available in non-suid flavor on some systems, @@ -1964,6 +1981,73 @@ static unsigned long long cut_out_ull_opt(char *opts, const char *name_eq) } } +// Find any mount options beginning with "x-" and remove them. These are used +// to add metadata and comments to the mounts, which isn't currently supported +// by Busybox. +static void cut_out_x_opts(char *opts) +{ + const char *const x_opt = "x-"; + const size_t x_opt_len = strlen(x_opt); + char *opt = opts; + const char *const opts_end = opts + strlen(opts); + + if (!opts) + return; + + for (;;) { + if (strlen(opt) < x_opt_len) { + // Option string is too small to fit such an option + break; + } + + if (!strncmp(opt, x_opt, x_opt_len)) { + // Found a matching option. Now remove it + char *current_opt = NULL; + char *end = strstr(opt, ","); + + if (ENABLE_FEATURE_MOUNT_IGNORE_X_FLAGS_VERBOSE) { + // Make a copy for verbose reporting + current_opt = xstrdup(opt); + } + + if (end == NULL) { + // No comma found, this is the last/only flag. Null it out so + // that it's not parsed. + *opt = '\0'; + } else { + // There are more options; move them up to remove the current + // option + memmove(opt, end + 1, opts_end - end); + if (ENABLE_FEATURE_MOUNT_IGNORE_X_FLAGS_VERBOSE) { + // Null out where the next comma is to single out the + // current option for optional verbose reporting + current_opt[end - opt] = '\0'; + } + } + + if (ENABLE_FEATURE_MOUNT_IGNORE_X_FLAGS_VERBOSE) { + bb_perror_msg("ignoring unsupported option: %s", + current_opt); + free(current_opt); + } + + // The string has been modified; check this + // memory address for the target string again + continue; + } + + // Go to the next option + opt = strstr(opt, ","); + if (opt == NULL) { + // No more commas - we're at the last option + break; + } + + // Skip over the comma + opt++; + } +} + // Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem // type detection. Returns 0 for success, nonzero for failure. // NB: mp->xxx fields may be trashed on exit @@ -1978,6 +2062,10 @@ static int singlemount(struct mntent *mp, int ignore_busy) errno = 0; + if (ENABLE_FEATURE_MOUNT_IGNORE_X_FLAGS) { + cut_out_x_opts(mp->mnt_opts); + } + vfsflags = parse_mount_options(mp->mnt_opts, &filteropts, NULL); // Treat fstype "auto" as unspecified -- 2.37.2 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
