]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: allow to toggle ro/rw and mount again
authorKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2012 15:27:50 +0000 (16:27 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2012 15:27:50 +0000 (16:27 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/mountP.h
libmount/src/optstr.c

index 594f090f453494af7688cd0fbc050412a63df634..571a2496aee6b9383228b40695c2b396eb58f7ba 100644 (file)
@@ -1001,7 +1001,18 @@ int mnt_context_set_mflags(struct libmnt_context *cxt, unsigned long flags)
 {
        if (!cxt)
                return -EINVAL;
+
        cxt->mountflags = flags;
+
+       if ((cxt->flags & MNT_FL_MOUNTOPTS_FIXED) && cxt->fs)
+               /*
+                * the final mount options are already generated, refresh...
+                */
+               return mnt_optstr_apply_flags(
+                               &cxt->fs->vfs_optstr,
+                               cxt->mountflags,
+                               mnt_get_builtin_optmap(MNT_LINUX_MAP));
+
        return 0;
 }
 
index bb895425f65be7737c1d4354d0d67a665bd889d9..6f2a3dc116dca6ff59ac42e52358ac1253f0452b 100644 (file)
@@ -39,7 +39,7 @@ static int fix_optstr(struct libmnt_context *cxt)
 
        if (!cxt)
                return -EINVAL;
-       if (!cxt->fs)
+       if (!cxt->fs || (cxt->flags & MNT_FL_MOUNTOPTS_FIXED))
                return 0;
 
        DBG(CXT, mnt_debug_h(cxt, "mount: fixing optstr"));
@@ -133,6 +133,8 @@ static int fix_optstr(struct libmnt_context *cxt)
        fs->optstr = NULL;
        fs->optstr = mnt_fs_strdup_options(fs);
 done:
+       cxt->flags |= MNT_FL_MOUNTOPTS_FIXED;
+
        DBG(CXT, mnt_debug_h(cxt, "fixed options [rc=%d]: "
                "vfs: '%s' fs: '%s' user: '%s', optstr: '%s'", rc,
                fs->vfs_optstr, fs->fs_optstr, fs->user_optstr, fs->optstr));
index fa0567877cba166f08e14d90a9f5600ec28ae887..c321702b68766f03732cc5af82c7d227aafdae0e 100644 (file)
@@ -338,6 +338,7 @@ struct libmnt_context
 #define MNT_FL_PREPARED                (1 << 24)
 #define MNT_FL_HELPER          (1 << 25)       /* [u]mount.<type> */
 #define MNT_FL_LOOPDEV_READY   (1 << 26)       /* /dev/loop<N> initialized by library */
+#define MNT_FL_MOUNTOPTS_FIXED  (1 << 27)
 
 /* default flags */
 #define MNT_FL_DEFAULT         0
index 836838440e90482922c515e107e2a593a81aa1f0..260dc26a8127819e87754c1548746d711b6fee34 100644 (file)
@@ -652,7 +652,7 @@ int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
        if (!optstr || !map)
                return -EINVAL;
 
-       DBG(CXT, mnt_debug("applying 0x%08lu flags '%s'", flags, *optstr));
+       DBG(CXT, mnt_debug("applying 0x%08lu flags to '%s'", flags, *optstr));
 
        maps[0] = map;
        next = *optstr;
@@ -745,6 +745,7 @@ int mnt_optstr_apply_flags(char **optstr, unsigned long flags,
                }
        }
 
+       DBG(CXT, mnt_debug("new optstr '%s'", *optstr));
        return rc;
 err:
        DBG(CXT, mnt_debug("failed to apply flags [rc=%d]", rc));