summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/mount-util.c23
-rw-r--r--src/shared/mount-util.h5
2 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c
index ef128dd595..ff95fbc569 100644
--- a/src/shared/mount-util.c
+++ b/src/shared/mount-util.c
@@ -16,6 +16,7 @@
#include "fileio.h"
#include "fs-util.h"
#include "hashmap.h"
+#include "label.h"
#include "libmount-util.h"
#include "missing_mount.h"
#include "missing_syscall.h"
@@ -1071,3 +1072,25 @@ int remount_idmap(
return 0;
}
+
+int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode) {
+ assert(st);
+ assert(dest);
+
+ if (S_ISDIR(st->st_mode))
+ return mkdir_label(dest, mode);
+ else
+ return mknod(dest, S_IFREG|(mode & ~0111), 0);
+}
+
+int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode) {
+ struct stat st;
+
+ assert(source);
+ assert(dest);
+
+ if (stat(source, &st) < 0)
+ return -errno;
+
+ return make_mount_point_inode_from_stat(&st, dest, mode);
+}
diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h
index 0169083980..36501c2c4a 100644
--- a/src/shared/mount-util.h
+++ b/src/shared/mount-util.h
@@ -3,6 +3,7 @@
#include <mntent.h>
#include <stdio.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "alloc-util.h"
@@ -108,3 +109,7 @@ int mount_image_in_namespace(pid_t target, const char *propagate_path, const cha
int make_mount_point(const char *path);
int remount_idmap(const char *p, uid_t uid_shift, uid_t uid_range);
+
+/* Creates a mount point (not parents) based on the source path or stat - ie, a file or a directory */
+int make_mount_point_inode_from_stat(const struct stat *st, const char *dest, mode_t mode);
+int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode);