util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mount: overwrite options from /etc/fstab when given on the commandline
@ 2012-08-01  9:11 Niels de Vos
  2012-08-01  9:48 ` Karel Zak
  0 siblings, 1 reply; 9+ messages in thread
From: Niels de Vos @ 2012-08-01  9:11 UTC (permalink / raw)
  To: util-linux; +Cc: Niels de Vos

Hi all,

it seems that some of the options given in /etc/fstab are not overloaded by
options given on the mount-commandline. Some options are not allowed to be
passed multiple times (like the SElinux context options) and mounting will fail
if options are present in both /etc/fstab and on the commandline.

Is there a reason for not overloading the options from /etc/fstab by the
options given on the commandline?

The patch below changes the behaviour of mount so that options on the
commandline replace options given in /etc/fstab. This example is based on the
now deprecated code of mount in util-linux-2.17.2. I'd like to receive some
responses if this change would be acceptible, or if this was done by design.

If this can be accepted, I'll happily look into the libmount code and provide
a patch for the current util-linux version.

Many thanks,
Niels

---
 mount/mount.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/mount/mount.c b/mount/mount.c
index 45f9699..e594f5e 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -294,6 +294,48 @@ print_all (char *types) {
      exit (0);
 }
 
+/* reallocates its first arg
+ * opt is the single option, val is the opt=val pair */
+static char *
+merge_one_opt(char *s, const char *opt, const char *val)
+{
+	char *old_opt, *next_opt;
+
+	if (!opt)
+		return s;
+	if (!s)
+		return xstrdup(val);		/* opt & opt=val */
+	if (!val)
+		return s;				/* s,opt */
+
+	old_opt = strstr(s, opt);
+	if (old_opt) {
+		next_opt = strchr(old_opt, ',');
+		if (!next_opt)
+			memset(old_opt, '\0', 1);
+		else
+			memmove(old_opt, next_opt + 1, strlen(next_opt) + 1);
+	}
+	return xstrconcat3(s, ",", val);		/* s,opt=val */
+}
+
+/* reallocates its first arg */
+static char *
+merge_opts(char *s, const char *extra_opts)
+{
+	char *new_opts = xstrdup(extra_opts);
+	char *opt, *opt_pos, *o;
+
+	opt = strtok_r(new_opts, ",", &opt_pos);
+	while (opt != NULL) {
+		o = xstrndup(opt, strchrnul(opt, '=') - opt);
+		s = merge_one_opt(s, o, opt);
+		opt = strtok_r(NULL, ",", &opt_pos);
+	}
+
+	return s;
+}
+
 /* reallocates its first arg */
 static char *
 append_opt(char *s, const char *opt, const char *val)
@@ -1701,7 +1743,7 @@ mount_one (const char *spec, const char *node, const char *types,
 	opts = usersubst(fstabopts);
 
 	/* Merge the fstab and command line options.  */
-	opts = append_opt(opts, cmdlineopts, NULL);
+	opts = merge_opts(opts, cmdlineopts);
 
 	if (types == NULL && !mounttype && !is_existing_file(spec)) {
 		if (strchr (spec, ':') != NULL) {
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-08-02  9:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-01  9:11 [RFC] mount: overwrite options from /etc/fstab when given on the commandline Niels de Vos
2012-08-01  9:48 ` Karel Zak
2012-08-01 10:03   ` Karel Zak
2012-08-01 10:14     ` Niels de Vos
2012-08-01 10:32       ` Karel Zak
2012-08-01 11:58         ` Niels de Vos
2012-08-01 17:08           ` Karel Zak
2012-08-02  9:46             ` Niels de Vos
2012-08-01 10:11   ` Niels de Vos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).