Debian Codegraph @

src/shared/mstack.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "discover-image.h"
5 #include "shared-forward.h"
6
7 typedef enum MStackFlags {
8 MSTACK_MKDIR = 1 << 0, /* when mounting, create top-level inode to mount on top */
9 MSTACK_RDONLY = 1 << 1,
10 } MStackFlags;
11
12 typedef enum MStackMountType {
13 MSTACK_ROOT, /* optional "root" entry used as root, with the layer@/rw layers only used for /usr/ */
14 MSTACK_LAYER, /* "layer@…" entries that are the lower (read-only) layers of an overlayfs stack */
15 MSTACK_RW, /* "rw" entry that is the upper (writable) layer of an overlayfs stack (contains two subdirs: 'data' + 'work') */
16 MSTACK_BIND, /* "bind@…" entries that are (writable) bind mounted on top of the overlayfs */
17 MSTACK_ROBIND, /* "robind@…" similar, but read-only */
18 _MSTACK_MOUNT_TYPE_MAX,
19 _MSTACK_MOUNT_TYPE_INVALID = -EINVAL,
20 } MStackMountType;
21
22 typedef struct MStackMount {
23 MStackMountType mount_type;
24 char *what;
25 int what_fd;
26 int mount_fd;
27 char *sort_key;
28 char *where;
29 ImageType image_type;
30 DissectedImage *dissected_image;
31 } MStackMount;
32
33 typedef struct MStack {
34 char *path;
35 MStackMount *mounts;
36 size_t n_mounts;
37 bool has_tmpfs_root; /* If true, we need a throw-away tmpfs as root */
38 bool has_overlayfs; /* Indicates whether we need overlayfs (i.e. if there are more than a single layer */
39 MStackMount *root_mount; /* If there's a MOUNT_BIND/MOUNT_ROBIND/MOUNT_ROOT mount, this points to it */
40 int root_mount_fd;
41 int usr_mount_fd;
42 } MStack;
43
44 #define MSTACK_INIT \
45 (MStack) { \
46 .root_mount_fd = -EBADF, \
47 .usr_mount_fd = -EBADF, \
48 }
49
50 MStack* mstack_free(MStack *mstack);
51 DEFINE_TRIVIAL_CLEANUP_FUNC(MStack*, mstack_free);
52
53 int mstack_load(const char *dir, int dir_fd, MStack **ret);
54 int mstack_open_images(MStack *mstack, sd_varlink *mountfsd_link, int userns_fd, const ImagePolicy *image_policy, const ImageFilter *image_filter, MStackFlags flags);
55 int mstack_make_mounts(MStack *mstack, const char *temp_mount_dir, MStackFlags flags);
56 int mstack_bind_mounts(MStack *mstack, const char *where, int where_fd, MStackFlags flags, int *ret_root_fd);
57
58 /* The four calls above in one */
59 int mstack_apply(
60 const char *dir,
61 int dir_fd,
62 const char *where,
63 const char *temp_mount_dir,
64 sd_varlink *mountfsd_link,
65 int userns_fd,
66 const ImagePolicy *image_policy,
67 const ImageFilter *image_filter,
68 MStackFlags flags,
69 int *ret_root_fd);
70
71 int mstack_is_read_only(MStack *mstack);
72 int mstack_is_foreign_uid_owned(MStack *mstack);
73
74 DECLARE_STRING_TABLE_LOOKUP_TO_STRING(mstack_mount_type, MStackMountType);