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