libmount: add MNT_OMODE_NOTAB
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
38a8d69e29
commit
374fd21add
|
@ -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));
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
/*** 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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue