summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/mount.822
-rw-r--r--sys-utils/mount.c85
2 files changed, 106 insertions, 1 deletions
diff --git a/sys-utils/mount.8 b/sys-utils/mount.8
index b64d956e3..15d74df6d 100644
--- a/sys-utils/mount.8
+++ b/sys-utils/mount.8
@@ -696,6 +696,28 @@ sections.
.RE
.TP
+.BR "\-\-options\-mode " \fImode
+Controls how to combine options from fstab/mtab with options from command line.
+\fImode\fR can be one of
+.BR ignore ", " append ", " prepend " or " replace .
+For example \fBappend\fR means that options from fstab are appended to options from command line.
+Default value is \fBprepend\fR.
+
+.TP
+.BR "\-\-options\-source " \fIsource
+Source of default options.
+\fIsource\fR is comma separated list of
+.BR fstab ", " mtab " and " disable .
+\fBdisable\fR disables
+.BR fstab " and " mtab
+and disables \fB\-\-options\-source\-force\fR.
+Default value is \fBfstab,mtab\fR.
+
+.TP
+.BR \-\-options\-source\-force
+Use options from fstab/mtab even if both \fIdevice\fR and \fIdir\fR are specified.
+
+.TP
.BR \-R , " \-\-rbind"
Remount a subtree and all possible submounts somewhere else (so that its
contents are available in both places). See above, the subsection
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index 83cccf63e..72e8a455e 100644
--- a/sys-utils/mount.c
+++ b/sys-utils/mount.c
@@ -413,6 +413,13 @@ static void __attribute__((__noreturn__)) usage(void)
fprintf(out, _(
" -n, --no-mtab don't write to /etc/mtab\n"));
fprintf(out, _(
+ " --options-mode <mode>\n"
+ " what to do with options loaded from fstab\n"
+ " --options-source <source>\n"
+ " mount options source\n"
+ " --options-source-force\n"
+ " force use of options from fstab/mtab\n"));
+ 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"
" -r, --read-only mount the filesystem read-only (same as -o ro)\n"
@@ -463,6 +470,46 @@ static void __attribute__((__noreturn__)) usage(void)
exit(MNT_EX_SUCCESS);
}
+struct flag_str {
+ int value;
+ char *str;
+};
+
+static int omode2mask(const char *str)
+{
+ size_t i;
+
+ static const struct flag_str flags[] = {
+ { MNT_OMODE_IGNORE, "ignore" },
+ { MNT_OMODE_APPEND, "append" },
+ { MNT_OMODE_PREPEND, "prepend" },
+ { MNT_OMODE_REPLACE, "replace" },
+ };
+
+ for (i = 0; i < ARRAY_SIZE(flags); i++) {
+ if (!strcmp(str, flags[i].str))
+ return flags[i].value;
+ }
+ return -EINVAL;
+}
+
+static long osrc2mask(const char *str, size_t len)
+{
+ size_t i;
+
+ static const struct flag_str flags[] = {
+ { MNT_OMODE_FSTAB, "fstab" },
+ { MNT_OMODE_MTAB, "mtab" },
+ { MNT_OMODE_NOTAB, "disable" },
+ };
+
+ for (i = 0; i < ARRAY_SIZE(flags); i++) {
+ if (!strncmp(str, flags[i].str, len) && !flags[i].str[len])
+ return flags[i].value;
+ }
+ return -EINVAL;
+}
+
int main(int argc, char **argv)
{
int c, rc = MNT_EX_SUCCESS, all = 0, show_labels = 0;
@@ -472,6 +519,7 @@ int main(int argc, char **argv)
char *types = NULL;
unsigned long oper = 0;
int propa = 0;
+ int optmode = 0, optmode_mode = 0, optmode_src = 0;
enum {
MOUNT_OPT_SHARED = CHAR_MAX + 1,
@@ -483,7 +531,10 @@ int main(int argc, char **argv)
MOUNT_OPT_RPRIVATE,
MOUNT_OPT_RUNBINDABLE,
MOUNT_OPT_TARGET,
- MOUNT_OPT_SOURCE
+ MOUNT_OPT_SOURCE,
+ MOUNT_OPT_OPTMODE,
+ MOUNT_OPT_OPTSRC,
+ MOUNT_OPT_OPTSRC_FORCE
};
static const struct option longopts[] = {
@@ -520,6 +571,9 @@ int main(int argc, char **argv)
{ "show-labels", no_argument, NULL, 'l' },
{ "target", required_argument, NULL, MOUNT_OPT_TARGET },
{ "source", required_argument, NULL, MOUNT_OPT_SOURCE },
+ { "options-mode", required_argument, NULL, MOUNT_OPT_OPTMODE },
+ { "options-source", required_argument, NULL, MOUNT_OPT_OPTSRC },
+ { "options-source-force", no_argument, NULL, MOUNT_OPT_OPTSRC_FORCE},
{ NULL, 0, NULL, 0 }
};
@@ -673,6 +727,26 @@ int main(int argc, char **argv)
mnt_context_disable_swapmatch(cxt, 1);
mnt_context_set_source(cxt, optarg);
break;
+ case MOUNT_OPT_OPTMODE:
+ optmode_mode = omode2mask(optarg);
+ if (optmode_mode == -EINVAL) {
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
+ }
+ break;
+ case MOUNT_OPT_OPTSRC:
+ {
+ unsigned long tmp = 0;
+ if (string_to_bitmask(optarg, &tmp, osrc2mask)) {
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
+ }
+ optmode_src = tmp;
+ break;
+ }
+ case MOUNT_OPT_OPTSRC_FORCE:
+ optmode |= MNT_OMODE_FORCE;
+ break;
default:
errtryhelp(MNT_EX_USAGE);
}
@@ -681,6 +755,15 @@ int main(int argc, char **argv)
argc -= optind;
argv += optind;
+ optmode |= optmode_mode | optmode_src;
+ if (optmode) {
+ if (!optmode_mode)
+ optmode |= MNT_OMODE_PREPEND;
+ if (!optmode_src)
+ optmode |= MNT_OMODE_FSTAB | MNT_OMODE_MTAB;
+ mnt_context_set_optsmode(cxt, optmode);
+ }
+
if (fstab && !mnt_context_is_nocanonicalize(cxt)) {
/*
* We have external (context independent) fstab instance, let's