]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/nspawn/nspawn-mount.h
7a77e795996ee2c1c7f0c9a9f3e0d7e0d61b705e
[thirdparty/systemd.git] / src / nspawn / nspawn-mount.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2015 Lennart Poettering
6 ***/
7
8 #include <stdbool.h>
9
10 #include "cgroup-util.h"
11 #include "volatile-util.h"
12
13 typedef enum MountSettingsMask {
14 MOUNT_FATAL = 1 << 0, /* if set, a mount error is considered fatal */
15 MOUNT_USE_USERNS = 1 << 1, /* if set, mounts are patched considering uid/gid shifts in a user namespace */
16 MOUNT_IN_USERNS = 1 << 2, /* if set, the mount is executed in the inner child, otherwise in the outer child */
17 MOUNT_APPLY_APIVFS_RO = 1 << 3, /* if set, /proc/sys, and /sys will be mounted read-only, otherwise read-write. */
18 MOUNT_APPLY_APIVFS_NETNS = 1 << 4, /* if set, /proc/sys/net will be mounted read-write.
19 Works only if MOUNT_APPLY_APIVFS_RO is also set. */
20 MOUNT_INACCESSIBLE_REG = 1 << 5, /* if set, create an inaccessible regular file first and use as bind mount source */
21 } MountSettingsMask;
22
23 typedef enum CustomMountType {
24 CUSTOM_MOUNT_BIND,
25 CUSTOM_MOUNT_TMPFS,
26 CUSTOM_MOUNT_OVERLAY,
27 _CUSTOM_MOUNT_TYPE_MAX,
28 _CUSTOM_MOUNT_TYPE_INVALID = -1
29 } CustomMountType;
30
31 typedef struct CustomMount {
32 CustomMountType type;
33 bool read_only;
34 char *source; /* for overlayfs this is the upper directory */
35 char *destination;
36 char *options;
37 char *work_dir;
38 char **lower;
39 char *rm_rf_tmpdir;
40 } CustomMount;
41
42 CustomMount* custom_mount_add(CustomMount **l, size_t *n, CustomMountType t);
43 void custom_mount_free_all(CustomMount *l, size_t n);
44 int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n);
45
46 int bind_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only);
47 int tmpfs_mount_parse(CustomMount **l, size_t *n, const char *s);
48 int overlay_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only);
49
50 int mount_all(const char *dest, MountSettingsMask mount_settings, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
51 int mount_sysfs(const char *dest, MountSettingsMask mount_settings);
52
53 int mount_cgroups(const char *dest, CGroupUnified unified_requested, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context, bool use_cgns);
54 int mount_systemd_cgroup_writable(const char *dest, CGroupUnified unified_requested);
55
56 int mount_custom(const char *dest, CustomMount *mounts, size_t n, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
57
58 int setup_volatile(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
59 int setup_volatile_state(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
60
61 int pivot_root_parse(char **pivot_root_new, char **pivot_root_old, const char *s);
62 int setup_pivot_root(const char *directory, const char *pivot_root_new, const char *pivot_root_old);