]>
Commit | Line | Data |
---|---|---|
7f88a1a2 CB |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | ||
3 | #ifndef __LXC_MOUNT_UTILS_H | |
4 | #define __LXC_MOUNT_UTILS_H | |
5 | ||
74ed30d7 | 6 | #include <linux/types.h> |
7f88a1a2 CB |
7 | #include <stdio.h> |
8 | #include <stdlib.h> | |
9 | #include <sys/mount.h> | |
10 | ||
11 | #include "compiler.h" | |
1f3eb959 | 12 | #include "memory_utils.h" |
87545854 | 13 | #include "syscall_wrappers.h" |
7f88a1a2 | 14 | |
c146c54e CB |
15 | struct lxc_rootfs; |
16 | ||
7f88a1a2 | 17 | /* open_tree() flags */ |
041d1e30 CB |
18 | |
19 | #ifndef AT_RECURSIVE | |
20 | #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */ | |
21 | #endif | |
22 | ||
7f88a1a2 CB |
23 | #ifndef OPEN_TREE_CLONE |
24 | #define OPEN_TREE_CLONE 1 | |
25 | #endif | |
26 | ||
27 | #ifndef OPEN_TREE_CLOEXEC | |
28 | #define OPEN_TREE_CLOEXEC O_CLOEXEC | |
29 | #endif | |
30 | ||
31 | /* move_mount() flags */ | |
32 | #ifndef MOVE_MOUNT_F_SYMLINKS | |
33 | #define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ | |
34 | #endif | |
35 | ||
36 | #ifndef MOVE_MOUNT_F_AUTOMOUNTS | |
37 | #define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ | |
38 | #endif | |
39 | ||
40 | #ifndef MOVE_MOUNT_F_EMPTY_PATH | |
41 | #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ | |
42 | #endif | |
43 | ||
44 | #ifndef MOVE_MOUNT_T_SYMLINKS | |
45 | #define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ | |
46 | #endif | |
47 | ||
48 | #ifndef MOVE_MOUNT_T_AUTOMOUNTS | |
49 | #define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ | |
50 | #endif | |
51 | ||
52 | #ifndef MOVE_MOUNT_T_EMPTY_PATH | |
53 | #define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ | |
54 | #endif | |
55 | ||
56 | #ifndef MOVE_MOUNT__MASK | |
57 | #define MOVE_MOUNT__MASK 0x00000077 | |
58 | #endif | |
59 | ||
60 | /* fsopen() flags */ | |
61 | #ifndef FSOPEN_CLOEXEC | |
62 | #define FSOPEN_CLOEXEC 0x00000001 | |
63 | #endif | |
64 | ||
65 | /* fspick() flags */ | |
66 | #ifndef FSPICK_CLOEXEC | |
67 | #define FSPICK_CLOEXEC 0x00000001 | |
68 | #endif | |
69 | ||
70 | #ifndef FSPICK_SYMLINK_NOFOLLOW | |
71 | #define FSPICK_SYMLINK_NOFOLLOW 0x00000002 | |
72 | #endif | |
73 | ||
74 | #ifndef FSPICK_NO_AUTOMOUNT | |
75 | #define FSPICK_NO_AUTOMOUNT 0x00000004 | |
76 | #endif | |
77 | ||
78 | #ifndef FSPICK_EMPTY_PATH | |
79 | #define FSPICK_EMPTY_PATH 0x00000008 | |
80 | #endif | |
81 | ||
82 | /* fsconfig() commands */ | |
83 | #ifndef FSCONFIG_SET_FLAG | |
84 | #define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */ | |
85 | #endif | |
86 | ||
87 | #ifndef FSCONFIG_SET_STRING | |
88 | #define FSCONFIG_SET_STRING 1 /* Set parameter, supplying a string value */ | |
89 | #endif | |
90 | ||
91 | #ifndef FSCONFIG_SET_BINARY | |
92 | #define FSCONFIG_SET_BINARY 2 /* Set parameter, supplying a binary blob value */ | |
93 | #endif | |
94 | ||
95 | #ifndef FSCONFIG_SET_PATH | |
96 | #define FSCONFIG_SET_PATH 3 /* Set parameter, supplying an object by path */ | |
97 | #endif | |
98 | ||
99 | #ifndef FSCONFIG_SET_PATH_EMPTY | |
100 | #define FSCONFIG_SET_PATH_EMPTY 4 /* Set parameter, supplying an object by (empty) path */ | |
101 | #endif | |
102 | ||
103 | #ifndef FSCONFIG_SET_FD | |
104 | #define FSCONFIG_SET_FD 5 /* Set parameter, supplying an object by fd */ | |
105 | #endif | |
106 | ||
107 | #ifndef FSCONFIG_CMD_CREATE | |
108 | #define FSCONFIG_CMD_CREATE 6 /* Invoke superblock creation */ | |
109 | #endif | |
110 | ||
111 | #ifndef FSCONFIG_CMD_RECONFIGURE | |
112 | #define FSCONFIG_CMD_RECONFIGURE 7 /* Invoke superblock reconfiguration */ | |
113 | #endif | |
114 | ||
115 | /* fsmount() flags */ | |
116 | #ifndef FSMOUNT_CLOEXEC | |
117 | #define FSMOUNT_CLOEXEC 0x00000001 | |
118 | #endif | |
119 | ||
120 | /* mount attributes */ | |
121 | #ifndef MOUNT_ATTR_RDONLY | |
122 | #define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */ | |
123 | #endif | |
124 | ||
125 | #ifndef MOUNT_ATTR_NOSUID | |
126 | #define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */ | |
127 | #endif | |
128 | ||
129 | #ifndef MOUNT_ATTR_NODEV | |
130 | #define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */ | |
131 | #endif | |
132 | ||
133 | #ifndef MOUNT_ATTR_NOEXEC | |
134 | #define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */ | |
135 | #endif | |
136 | ||
137 | #ifndef MOUNT_ATTR__ATIME | |
138 | #define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */ | |
139 | #endif | |
140 | ||
141 | #ifndef MOUNT_ATTR_RELATIME | |
142 | #define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */ | |
143 | #endif | |
144 | ||
145 | #ifndef MOUNT_ATTR_NOATIME | |
146 | #define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */ | |
147 | #endif | |
148 | ||
149 | #ifndef MOUNT_ATTR_STRICTATIME | |
150 | #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */ | |
151 | #endif | |
152 | ||
153 | #ifndef MOUNT_ATTR_NODIRATIME | |
154 | #define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */ | |
155 | #endif | |
156 | ||
031e0285 CB |
157 | #ifndef MOUNT_ATTR_IDMAP |
158 | #define MOUNT_ATTR_IDMAP 0x00100000 | |
159 | #endif | |
160 | ||
7f88a1a2 CB |
161 | __hidden extern int mnt_attributes_new(unsigned int old_flags, unsigned int *new_flags); |
162 | ||
163 | __hidden extern int mnt_attributes_old(unsigned int new_flags, unsigned int *old_flags); | |
164 | ||
1f3eb959 CB |
165 | __hidden extern int fs_prepare(const char *fs_name, int dfd_from, |
166 | const char *path_from, __u64 o_flags_from, | |
167 | __u64 resolve_flags_from); | |
168 | __hidden extern int fs_set_property(int fd_fs, const char *key, const char *val); | |
289b707b | 169 | __hidden extern int fs_set_flag(int fd_fs, const char *key); |
1f3eb959 CB |
170 | __hidden extern int fs_attach(int fd_fs, int dfd_to, const char *path_to, |
171 | __u64 o_flags_to, __u64 resolve_flags_to, | |
172 | unsigned int attr_flags); | |
173 | ||
174 | static inline int fs_mount(const char *fs_name, int dfd_from, | |
175 | const char *path_from, __u64 o_flags_from, | |
176 | __u64 resolve_flags_from, int dfd_to, | |
177 | const char *path_to, __u64 o_flags_to, | |
178 | __u64 resolve_flags_to, | |
179 | unsigned int attr_flags) | |
180 | { | |
181 | __do_close int fd_fs = -EBADF; | |
182 | ||
183 | fd_fs = fs_prepare(fs_name, dfd_from, path_from, o_flags_from, resolve_flags_from); | |
184 | if (fd_fs < 0) | |
185 | return -errno; | |
186 | return fs_attach(fd_fs, dfd_to, path_to, o_flags_to, resolve_flags_to, attr_flags); | |
187 | } | |
74ed30d7 | 188 | |
8cf6a646 CB |
189 | __hidden extern int __fd_bind_mount(int dfd_from, const char *path_from, |
190 | __u64 o_flags_from, | |
191 | __u64 resolve_flags_from, int dfd_to, | |
192 | const char *path_to, __u64 o_flags_to, | |
704cadd5 CB |
193 | __u64 resolve_flags_to, __u64 attr_set, |
194 | __u64 attr_clr, __u64 propagation, | |
8cf6a646 CB |
195 | int userns_fd, bool recursive); |
196 | static inline int fd_mount_idmapped(int dfd_from, const char *path_from, | |
197 | __u64 o_flags_from, | |
198 | __u64 resolve_flags_from, int dfd_to, | |
199 | const char *path_to, __u64 o_flags_to, | |
704cadd5 CB |
200 | __u64 resolve_flags_to, __u64 attr_set, |
201 | __u64 attr_clr, __u64 propagation, | |
8cf6a646 CB |
202 | int userns_fd, bool recursive) |
203 | { | |
704cadd5 CB |
204 | return __fd_bind_mount(dfd_from, path_from, o_flags_from, |
205 | resolve_flags_from, dfd_to, path_to, o_flags_to, | |
206 | resolve_flags_to, attr_set, attr_clr, | |
207 | propagation, userns_fd, recursive); | |
8cf6a646 CB |
208 | } |
209 | ||
210 | static inline int fd_bind_mount(int dfd_from, const char *path_from, | |
211 | __u64 o_flags_from, __u64 resolve_flags_from, | |
212 | int dfd_to, const char *path_to, | |
213 | __u64 o_flags_to, __u64 resolve_flags_to, | |
704cadd5 CB |
214 | __u64 attr_set, __u64 attr_clr, |
215 | __u64 propagation, bool recursive) | |
8cf6a646 CB |
216 | { |
217 | return __fd_bind_mount(dfd_from, path_from, o_flags_from, resolve_flags_from, | |
218 | dfd_to, path_to, o_flags_to, resolve_flags_to, | |
704cadd5 | 219 | attr_set, attr_clr, propagation, -EBADF, recursive); |
8cf6a646 | 220 | } |
d347d356 | 221 | __hidden extern int create_detached_idmapped_mount(const char *path, |
704cadd5 CB |
222 | int userns_fd, bool recursive, |
223 | __u64 attr_set, __u64 attr_clr); | |
d347d356 CB |
224 | __hidden extern int move_detached_mount(int dfd_from, int dfd_to, |
225 | const char *path_to, __u64 o_flags_to, | |
226 | __u64 resolve_flags_to); | |
e26cf563 | 227 | |
ac11febd CB |
228 | __hidden extern int calc_remount_flags_new(int dfd_from, const char *path_from, |
229 | __u64 o_flags_from, | |
230 | __u64 resolve_flags_from, | |
231 | bool remount, unsigned long cur_flags, | |
232 | unsigned int *new_flags); | |
233 | ||
234 | __hidden extern int calc_remount_flags_old(int dfd_from, const char *path_from, | |
235 | __u64 o_flags_from, | |
236 | __u64 resolve_flags_from, | |
237 | bool remount, unsigned long cur_flags, | |
238 | unsigned int *old_flags); | |
239 | ||
240 | __hidden extern unsigned long add_required_remount_flags(const char *s, | |
241 | const char *d, | |
242 | unsigned long flags); | |
243 | ||
de7f9f33 | 244 | __hidden extern bool can_use_mount_api(void); |
d4e07569 | 245 | __hidden extern bool can_use_bind_mounts(void); |
8b0ccdaa CB |
246 | __hidden extern int mount_at(int dfd_from, const char *path_from, |
247 | __u64 resolve_flags_from, int dfd_to, | |
248 | const char *path_to, __u64 resolve_flags_to, | |
249 | const char *fs_name, unsigned int flags, | |
250 | const void *data); | |
251 | static inline int mount_fd(int fd_from, int fd_to, const char *fs_name, | |
252 | unsigned int flags, const void *data) | |
253 | { | |
254 | return mount_at(fd_from, "", 0, fd_to, "", 0, fs_name, flags, data); | |
255 | } | |
de7f9f33 | 256 | |
7f88a1a2 | 257 | #endif /* __LXC_MOUNT_UTILS_H */ |