(all this already supported by libmount)
- - add x-mount-mkdir mount option to libmount to allow "mkdir /mountpoint"
-
- support MS_PROPAGATION flags in fstab -- note that kernel assumes that
these flags are not mixed with another mount flags, it means that:
return 0;
}
+/* create a mountpoint if x-mount.mkdir[=<mode>] specified */
+static int mkdir_target(const char *tgt, struct libmnt_fs *fs)
+{
+ char *mstr = NULL;
+ size_t mstr_sz = 0;
+ mode_t mode = 0;
+ struct stat st;
+ int rc;
+
+ assert(tgt);
+ assert(fs);
+
+ if (mnt_optstr_get_option(fs->user_optstr, "x-mount.mkdir", &mstr, &mstr_sz) != 0)
+ return 0;
+ if (stat(tgt, &st) == 0)
+ return 0;
+
+ if (mstr && mstr_sz) {
+ char *end = NULL;
+
+ errno = 0;
+ mode = strtol(mstr, &end, 8);
+
+ if (errno || !end || mstr + mstr_sz != end) {
+ DBG(CXT, mnt_debug("failed to parse mkdir mode '%s'", mstr));
+ return -MNT_ERR_MOUNTOPT;
+ }
+ }
+
+ if (!mode)
+ mode = S_IRWXU | /* 0755 */
+ S_IRGRP | S_IXGRP |
+ S_IROTH | S_IXOTH;
+
+ rc = mkdir_p(tgt, mode);
+ if (rc)
+ DBG(CXT, mnt_debug("mkdir %s failed: %m", tgt));
+
+ return rc;
+}
+
int mnt_context_prepare_target(struct libmnt_context *cxt)
{
const char *tgt;
if (!tgt)
return 0;
+ /* mkdir target */
+ if (cxt->action == MNT_ACT_MOUNT
+ && !mnt_context_is_restricted(cxt)
+ && cxt->user_mountflags & MNT_MS_XCOMMENT) {
+
+ rc = mkdir_target(tgt, cxt->fs);
+ if (rc)
+ return rc; /* mkdir or parse error */
+ }
+
+ /* canonicalize the path */
cache = mnt_context_get_cache(cxt);
if (cache) {
char *path = mnt_resolve_path(tgt, cache);
to mount.<type> helpers or
.B mount(2)
system call. The suggested format is x-<appname>.<option> (e.g. x-systemd.automount).
+.TP
+.B x-mount.mkdir[=<mode>]
+Allow to make a target directory (mountpoint). The optional argument <mode>
+specifies the file system access mode used for
+.B mkdir (2)
+in octal notation. The default mode is 0755. This functionality is supported
+only for root users.
.SH "FILESYSTEM SPECIFIC MOUNT OPTIONS"
The following options apply only to certain filesystems.
LABEL=libmount-test
UUID=$(uuidgen)
MOUNTPOINT="$TS_MOUNTPOINT"
+TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex"
+[ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST
#set -x
echo "umount failed: found $MOUNTPOINT in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest
+ts_init_subtest "x-mount.mkdir"
+$TS_CMD_MOUNT -o x-mount.mkdir --bind $MOUNTPOINT $TS_NOEXIST >> $TS_OUTPUT 2>&1 &&
+ echo "successfully mounted" >> $TS_OUTPUT
+ts_finalize_subtest
+
+$TS_CMD_UMOUNT $TS_NOEXIST
+rmdir $TS_NOEXIST
+
ts_log "...done."
rmmod scsi_debug
ts_finalize