]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add MNT_OMODE_NOTAB
authorKarel Zak <kzak@redhat.com>
Mon, 16 Jan 2012 13:35:10 +0000 (14:35 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Jan 2012 13:35:10 +0000 (14:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/libmount.h.in
sys-utils/mount.c

index 571a2496aee6b9383228b40695c2b396eb58f7ba..ac48fce3683f2fb6cf36a6dafa3ce9addf69872e 100644 (file)
@@ -223,9 +223,31 @@ int mnt_context_is_restricted(struct libmnt_context *cxt)
 /**
  * mnt_context_set_optsmode
  * @cxt: mount context
- * @mode: mask, see MNT_OMASK_* flags in libmount mount.h
+ * @mode: MNT_OMASK_* flags
  *
- * Controls how to use mount options from fstab/mtab.
+ * Controls how to use mount optionsmsource and target paths from fstab/mtab.
+ *
+ * @MNT_OMODE_IGNORE: ignore mtab/fstab options
+ * @MNT_OMODE_APPEND: append mtab/fstab options to existing options
+ * @MNT_OMODE_PREPEND: prepend mtab/fstab options to existing options
+ * @MNT_OMODE_REPLACE: replace existing options with options from mtab/fstab
+ *
+ * @MNT_OMODE_FORCE: always read mtab/fstab (although source and target is defined)
+ *
+ * @MNT_OMODE_FSTAB: read from fstab
+ * @MNT_OMODE_MTAB: read from mtab if fstab not enabled or failed
+ * @MNT_OMODE_NOTAB: do not read fstab/mtab at all
+ *
+ * @MNT_OMODE_AUTO: default mode (MNT_OMODE_PREPEND | MNT_OMODE_FSTAB | MNT_OMODE_MTAB)
+ * @MNT_OMODE_USER: default for non-root users (MNT_OMODE_REPLACE | MNT_OMODE_FORCE | MNT_OMODE_FSTAB)
+ *
+ * Notes:
+ *
+ * - MNT_OMODE_USER is always used if mount context is in restricted mode
+ * - MNT_OMODE_AUTO is used if nothing other is defined
+ * - the flags are eavaluated in this order: MNT_OMODE_NOTAB, MNT_OMODE_FORCE,
+ *   MNT_OMODE_FSTAB, MNT_OMODE_MTAB and then the mount options from fstab/mtab
+ *   are set according to MNT_OMODE_{IGNORE,APPEND,PREPAND,REPLACE}
  *
  * Returns: 0 on success, negative number in case of error.
  */
@@ -1359,11 +1381,6 @@ int mnt_context_merge_mflags(struct libmnt_context *cxt)
                return rc;
        cxt->mountflags = fl;
 
-       /* TODO: if cxt->fs->fs_optstr contains 'ro' then set the MS_RDONLY to
-        * mount flags, it's possible that superblock is read-only, but VFS is
-        * read-write.
-        */
-
        fl = 0;
        rc = mnt_context_get_user_mflags(cxt, &fl);
        if (rc)
@@ -1579,7 +1596,10 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt)
        } else if (cxt->optsmode == 0) {
                DBG(CXT, mnt_debug_h(cxt, "use default optmode"));
                cxt->optsmode = MNT_OMODE_AUTO;
-
+       } else if (cxt->optsmode & MNT_OMODE_NOTAB) {
+               cxt->optsmode &= ~MNT_OMODE_FSTAB;
+               cxt->optsmode &= ~MNT_OMODE_MTAB;
+               cxt->optsmode &= ~MNT_OMODE_FORCE;
        }
 
        if (cxt->fs) {
@@ -1603,6 +1623,14 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt)
                return 0;
        }
 
+       if (!src && tgt
+           && !(cxt->optsmode & MNT_OMODE_FSTAB)
+           && !(cxt->optsmode & MNT_OMODE_MTAB)) {
+               DBG(CXT, mnt_debug_h(cxt, "only target; fstab/mtab not required "
+                                         "-- skip, probably MS_PROPAGATION"));
+               return 0;
+       }
+
        DBG(CXT, mnt_debug_h(cxt,
                "trying to apply fstab (src=%s, target=%s)", src, tgt));
 
index e677c362b1d35e1b29398614d948502ec0839d37..8ecc7f2385a8b7096ae779771224bd620c541320 100644 (file)
@@ -355,7 +355,9 @@ extern int mnt_tabdiff_next_change(struct libmnt_tabdiff *df,
 
 /* context.c */
 
-/* mode for mount options from fstab */
+/*
+ * Mode for mount options from fstab (or mtab), see mnt_context_set_optsmode().
+ */
 enum {
        MNT_OMODE_IGNORE  = (1 << 1),   /* ignore mtab/fstab options */
        MNT_OMODE_APPEND  = (1 << 2),   /* append mtab/fstab options to existing options */
@@ -366,6 +368,7 @@ enum {
 
        MNT_OMODE_FSTAB   = (1 << 10),  /* read from fstab */
        MNT_OMODE_MTAB    = (1 << 11),  /* read from mtab if fstab not enabled or failed */
+       MNT_OMODE_NOTAB   = (1 << 12),  /* do not read fstab/mtab at all */
 
        /* default */
        MNT_OMODE_AUTO   = (MNT_OMODE_PREPEND | MNT_OMODE_FSTAB | MNT_OMODE_MTAB),
index c81af1af917db7e0d4ad8b456e40f115018b049e..81ccb411b38515d8fb1ffd4cea77e6c2aefe869e 100644 (file)
 /*** TODO: DOCS:
  *
  *  --guess-fstype     is unsupported
+ *
+ *  --options-mode={ignore,append,prepend,replace}     MNT_OMODE_{IGNORE, ...}
+ *  --options-source={fstab,mtab,disable}              MNT_OMODE_{FSTAB,MTAB,NOTAB}
+ *  --options-source-force                             MNT_OMODE_FORCE
  */
 
 /* exit status */
@@ -801,9 +805,14 @@ int main(int argc, char **argv)
        } else
                usage(stderr);
 
-       if (oper)
+       if (oper) {
+               /* MS_PROPAGATION operations, let's set the mount flags */
                mnt_context_set_mflags(cxt, oper);
 
+               /* For -make* or --bind is fstab unnecessary */
+               mnt_context_set_optsmode(cxt, MNT_OMODE_NOTAB);
+       }
+
        rc = mnt_context_mount(cxt);
        rc = mk_exit_code(cxt, rc);