]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't pass comments=/x-* to mount.<type> helpers
authorKarel Zak <kzak@redhat.com>
Wed, 25 Jan 2012 16:14:24 +0000 (17:14 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 25 Jan 2012 16:14:24 +0000 (17:14 +0100)
This patch add a new flag MNT_NOHLPS for mount options map, options
with this flag will not be passed to /sbin/mount.<type> helpers.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
libmount/src/libmount.h.in
libmount/src/optmap.c

index 17bbd428711e71d77a858d6df99e6433bcc7556f..b3a26fcc89ec3adbf6822324691ac9082a575145 100644 (file)
@@ -147,26 +147,50 @@ done:
  */
 static int generate_helper_optstr(struct libmnt_context *cxt, char **optstr)
 {
+       struct libmnt_optmap const *maps[1];
+       char *next, *name, *val;
+       size_t namesz, valsz;
        int rc = 0;
 
        assert(cxt);
        assert(cxt->fs);
        assert(optstr);
 
+       DBG(CXT, mnt_debug_h(cxt, "mount: generate heper mount options"));
+
        *optstr = mnt_fs_strdup_options(cxt->fs);
        if (!*optstr)
                return -ENOMEM;
 
        if (cxt->flags & MNT_FL_SAVED_USER)
                rc = mnt_optstr_set_option(optstr, "user", cxt->orig_user);
-       if (rc) {
-               free(*optstr);
-               *optstr = NULL;
+       if (rc)
+               goto err;
+
+       /* remove userspace options with MNT_NOHLPS flag */
+       maps[0] = mnt_get_builtin_optmap(MNT_USERSPACE_MAP);
+       next = *optstr;
+
+       while (!mnt_optstr_next_option(&next, &name, &namesz, &val, &valsz)) {
+               const struct libmnt_optmap *ent;
+
+               mnt_optmap_get_entry(maps, 1, name, namesz, &ent);
+               if (ent && ent->id && (ent->mask & MNT_NOHLPS)) {
+                       next = name;
+                       rc = mnt_optstr_remove_option_at(optstr, name,
+                                       val ? val + valsz : name + namesz);
+                       if (rc)
+                               goto err;
+               }
        }
+
+       return rc;
+err:
+       free(*optstr);
+       *optstr = NULL;
        return rc;
 }
 
-
 /*
  * this has to be called before fix_optstr()
  */
index 3cc1a79e7aa8629df970c548503276354d2a8044..c407b98a9b9e2588ca1a0b8afa9b0233e0ba1166 100644 (file)
@@ -70,6 +70,7 @@ struct libmnt_optmap
 #define MNT_INVERT     (1 << 1) /* invert the mountflag */
 #define MNT_NOMTAB     (1 << 2) /* skip in the mtab option string */
 #define MNT_PREFIX     (1 << 3) /* prefix used for some options (e.g. "x-foo") */
+#define MNT_NOHLPS     (1 << 4) /* don't add the option to mount.<type> helpers command line */
 
 /**
  * libmnt_fs:
index 7bd4da736c3f93ef3090b7ad0e79b08db7a340e8..4f11ce598a1678a245c14e462b737d9093206d01 100644 (file)
@@ -117,15 +117,13 @@ static const struct libmnt_optmap linux_flags_map[] =
 
 /*
  * userspace mount option (built-in MNT_USERSPACE_MAP)
- *
- * TODO: offset=, sizelimit=, encryption=, vfs=
  */
 static const struct libmnt_optmap userspace_opts_map[] =
 {
    { "defaults", 0, 0 },               /* default options */
 
-   { "auto",    MNT_MS_NOAUTO, MNT_INVERT | MNT_NOMTAB },  /* Can be mounted using -a */
-   { "noauto",  MNT_MS_NOAUTO, MNT_NOMTAB },               /* Can  only be mounted explicitly */
+   { "auto",    MNT_MS_NOAUTO, MNT_NOHLPS | MNT_INVERT | MNT_NOMTAB },  /* Can be mounted using -a */
+   { "noauto",  MNT_MS_NOAUTO, MNT_NOHLPS | MNT_NOMTAB },  /* Can  only be mounted explicitly */
 
    { "user[=]", MNT_MS_USER },                             /* Allow ordinary user to mount (mtab) */
    { "nouser",  MNT_MS_USER, MNT_INVERT | MNT_NOMTAB },    /* Forbid ordinary user to mount */
@@ -141,19 +139,19 @@ static const struct libmnt_optmap userspace_opts_map[] =
 
    { "_netdev", MNT_MS_NETDEV },                           /* Device requires network */
 
-   { "comment=", MNT_MS_COMMENT, MNT_NOMTAB },             /* fstab comment only */
-   { "x-",      MNT_MS_XCOMMENT, MNT_NOMTAB | MNT_PREFIX }, /* x- options */
+   { "comment=", MNT_MS_COMMENT, MNT_NOHLPS | MNT_NOMTAB },/* fstab comment only */
+   { "x-",      MNT_MS_XCOMMENT, MNT_NOHLPS | MNT_NOMTAB | MNT_PREFIX }, /* x- options */
 
-   { "loop[=]", MNT_MS_LOOP },                             /* use the loop device */
-   { "offset=", MNT_MS_OFFSET, MNT_NOMTAB },              /* loop device offset */
-   { "sizelimit=", MNT_MS_SIZELIMIT, MNT_NOMTAB },        /* loop device size limit */
-   { "encryption=", MNT_MS_ENCRYPTION, MNT_NOMTAB },      /* loop device encryption */
+   { "loop[=]", MNT_MS_LOOP, MNT_NOHLPS },                             /* use the loop device */
+   { "offset=", MNT_MS_OFFSET, MNT_NOHLPS | MNT_NOMTAB },                 /* loop device offset */
+   { "sizelimit=", MNT_MS_SIZELIMIT, MNT_NOHLPS | MNT_NOMTAB },           /* loop device size limit */
+   { "encryption=", MNT_MS_ENCRYPTION, MNT_NOHLPS | MNT_NOMTAB },         /* loop device encryption */
 
    { "nofail",  MNT_MS_NOFAIL, MNT_NOMTAB },               /* Do not fail if ENOENT on dev */
 
    { "uhelper=", MNT_MS_UHELPER },                        /* /sbin/umount.<helper> */
 
-   { "helper=", MNT_MS_HELPER },                          /* /sbin/umount.<helper> */
+   { "helper=", MNT_MS_HELPER },                          /* /sbin/mount.<helper> */
 
    { NULL, 0, 0 }
 };