mnt_context_enable_fork
mnt_context_enable_lazy
mnt_context_enable_loopdel
+mnt_context_enable_onlyonce
mnt_context_enable_rdonly_umount
mnt_context_enable_rwonly_mount
mnt_context_enable_sloppy
mnt_context_is_nocanonicalize
mnt_context_is_nohelpers
mnt_context_is_nomtab
+mnt_context_is_onlyonce
mnt_context_is_parent
mnt_context_is_rdonly_umount
mnt_context_is_restricted
return cxt->flags & MNT_FL_LAZY ? 1 : 0;
}
+/**
+ * mnt_context_enable_onlyonce:
+ * @cxt: mount context
+ * @enable: TRUE or FALSE
+ *
+ * Enable/disable only-once mount (check if FS is not already mounted).
+ *
+ * Returns: 0 on success, negative number in case of error.
+ */
+int mnt_context_enable_onlyonce(struct libmnt_context *cxt, int enable)
+{
+ return set_flag(cxt, MNT_FL_ONLYONCE, enable);
+}
+
+/**
+ * mnt_context_is_lazy:
+ * @cxt: mount context
+ *
+ * Returns: 1 if lazy umount is enabled or 0
+ */
+int mnt_context_is_onlyonce(struct libmnt_context *cxt)
+{
+ return cxt->flags & MNT_FL_ONLYONCE ? 1 : 0;
+}
+
/**
* mnt_context_enable_fork:
* @cxt: mount context
rc = mnt_context_prepare_target(cxt);
if (!rc)
rc = mnt_context_prepare_helper(cxt, "mount", NULL);
+
+ if (!rc && mnt_context_is_onlyonce(cxt)) {
+ int mounted = 0;
+ rc = mnt_context_is_fs_mounted(cxt, cxt->fs, &mounted);
+ if (rc == 0 && mounted == 1) {
+ rc = -MNT_ERR_ONLYONCE;
+ goto end;
+ }
+ }
if (rc) {
DBG(CXT, ul_debugobj(cxt, "mount: preparing failed"));
goto end;
}
+
cxt->flags |= MNT_FL_PREPARED;
end:
if (!cxt || !fs || !itr)
return -EINVAL;
+ /* ingore --onlyonce, it's default behavior for --all */
+ mnt_context_enable_onlyonce(cxt, 0);
+
rc = mnt_context_get_fstab(cxt, &fstab);
if (rc)
return rc;
if (buf)
snprintf(buf, bufsz, _("failed to switch namespace"));
return MNT_EX_SYSERR;
+ case -MNT_ERR_ONLYONCE:
+ if (buf)
+ snprintf(buf, bufsz, _("filesystem already mounted"));
+ return MNT_EX_FAIL;
default:
return mnt_context_get_generic_excode(rc, buf, bufsz, _("mount failed: %m"));
}
* failed to switch namespace
*/
#define MNT_ERR_NAMESPACE 5009
+/**
+ * MNT_ERR_ONLYONCE:
+ *
+ * filesystem mounted, but --onlyonce specified
+ */
+#define MNT_ERR_ONLYONCE 5010
/*
extern int mnt_context_set_optsmode(struct libmnt_context *cxt, int mode);
extern int mnt_context_disable_canonicalize(struct libmnt_context *cxt, int disable);
+extern int mnt_context_enable_onlyonce(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_lazy(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_rdonly_umount(struct libmnt_context *cxt, int enable);
extern int mnt_context_enable_rwonly_mount(struct libmnt_context *cxt, int enable);
extern int mnt_context_get_optsmode(struct libmnt_context *cxt);
+extern int mnt_context_is_onlyonce(struct libmnt_context *cxt)
+ __ul_attribute__((nonnull));
extern int mnt_context_is_lazy(struct libmnt_context *cxt)
__ul_attribute__((nonnull));
extern int mnt_context_is_rdonly_umount(struct libmnt_context *cxt)
MOUNT_2_38 {
mnt_fs_is_regularfs;
} MOUNT_2_37;
+
+MOUNT_2_39 {
+ mnt_context_enable_onlyonce;
+ mnt_context_is_lazy;
+} MOUNT_2_38;
#define MNT_FL_FORK (1 << 12)
#define MNT_FL_NOSWAPMATCH (1 << 13)
#define MNT_FL_RWONLY_MOUNT (1 << 14) /* explicit mount -w; never try read-only */
+#define MNT_FL_ONLYONCE (1 << 15)
#define MNT_FL_MOUNTDATA (1 << 20)
#define MNT_FL_TAB_APPLIED (1 << 21) /* mtab/fstab merged to cxt->fs */
+
For more details, see the *FILESYSTEM-INDEPENDENT MOUNT OPTIONS* and *FILESYSTEM-SPECIFIC MOUNT OPTIONS* sections.
+*--onlyonce*::
+Forces mount command to check if the filesystem is already mounted. This behavior is the default for *--all*; otherwise, it depends on the kernel filesystem driver. Some filesystems may be mounted more than once on the same mount point (e.g. tmpfs).
+
*--options-mode* _mode_::
Controls how to combine options from _fstab_/_mtab_ with options from the command line. _mode_ can be one of *ignore*, *append*, *prepend* or *replace*. For example, *append* means that options from _fstab_ are appended to options from the command line. The default value is *prepend* -- it means command line options are evaluated after _fstab_ options. Note that the last option wins if there are conflicting ones.
" --options-source-force\n"
" force use of options from fstab/mtab\n"));
fprintf(out, _(
+ " --onlyonce check if filesystem is already mounted\n"));
+ fprintf(out, _(
" -o, --options <list> comma-separated list of mount options\n"
" -O, --test-opts <list> limit the set of filesystems (use with -a)\n"
" -r, --read-only mount the filesystem read-only (same as -o ro)\n"
MOUNT_OPT_SOURCE,
MOUNT_OPT_OPTMODE,
MOUNT_OPT_OPTSRC,
- MOUNT_OPT_OPTSRC_FORCE
+ MOUNT_OPT_OPTSRC_FORCE,
+ MOUNT_OPT_ONLYONCE
};
static const struct option longopts[] = {
{ "target", required_argument, NULL, MOUNT_OPT_TARGET },
{ "target-prefix", required_argument, NULL, MOUNT_OPT_TARGET_PREFIX },
{ "source", required_argument, NULL, MOUNT_OPT_SOURCE },
+ { "onlyonce", no_argument, NULL, MOUNT_OPT_ONLYONCE },
{ "options-mode", required_argument, NULL, MOUNT_OPT_OPTMODE },
{ "options-source", required_argument, NULL, MOUNT_OPT_OPTSRC },
{ "options-source-force", no_argument, NULL, MOUNT_OPT_OPTSRC_FORCE},
case MOUNT_OPT_OPTSRC_FORCE:
optmode |= MNT_OMODE_FORCE;
break;
-
+ case MOUNT_OPT_ONLYONCE:
+ mnt_context_enable_onlyonce(cxt, 1);
+ break;
case 'h':
mnt_free_context(cxt);
usage();