]>
Commit | Line | Data |
---|---|---|
013e0db4 CB |
1 | #ifndef UTIL_LINUX_MOUNT_API_UTILS |
2 | #define UTIL_LINUX_MOUNT_API_UTILS | |
3 | ||
4 | #if defined(__linux__) | |
5 | #include <sys/syscall.h> | |
10efb9ea | 6 | #include <linux/mount.h> |
013e0db4 | 7 | |
013e0db4 CB |
8 | /* Accepted by both open_tree() and mount_setattr(). */ |
9 | #ifndef AT_RECURSIVE | |
1e5381cb | 10 | # define AT_RECURSIVE 0x8000 |
013e0db4 CB |
11 | #endif |
12 | ||
13 | #ifndef OPEN_TREE_CLONE | |
1e5381cb | 14 | # define OPEN_TREE_CLONE 1 |
013e0db4 CB |
15 | #endif |
16 | ||
17 | #ifndef OPEN_TREE_CLOEXEC | |
1e5381cb | 18 | # define OPEN_TREE_CLOEXEC O_CLOEXEC |
013e0db4 CB |
19 | #endif |
20 | ||
e087a188 | 21 | #if !defined(HAVE_OPEN_TREE) && defined(SYS_open_tree) |
013e0db4 CB |
22 | static inline int open_tree(int dfd, const char *filename, unsigned int flags) |
23 | { | |
e087a188 | 24 | return syscall(SYS_open_tree, dfd, filename, flags); |
013e0db4 | 25 | } |
1e5381cb | 26 | #endif |
013e0db4 CB |
27 | |
28 | #ifndef MOVE_MOUNT_F_SYMLINKS | |
1e5381cb | 29 | # define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ |
013e0db4 CB |
30 | #endif |
31 | ||
32 | #ifndef MOVE_MOUNT_F_AUTOMOUNTS | |
1e5381cb | 33 | # define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ |
013e0db4 CB |
34 | #endif |
35 | ||
36 | #ifndef MOVE_MOUNT_F_EMPTY_PATH | |
1e5381cb | 37 | # define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ |
013e0db4 CB |
38 | #endif |
39 | ||
40 | #ifndef MOVE_MOUNT_T_SYMLINKS | |
1e5381cb | 41 | # define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ |
013e0db4 CB |
42 | #endif |
43 | ||
44 | #ifndef MOVE_MOUNT_T_AUTOMOUNTS | |
1e5381cb | 45 | # define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ |
013e0db4 CB |
46 | #endif |
47 | ||
48 | #ifndef MOVE_MOUNT_T_EMPTY_PATH | |
1e5381cb | 49 | # define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ |
013e0db4 CB |
50 | #endif |
51 | ||
52 | #ifndef MOVE_MOUNT__MASK | |
1e5381cb | 53 | # define MOVE_MOUNT__MASK 0x00000077 |
013e0db4 CB |
54 | #endif |
55 | ||
e087a188 | 56 | #if !defined(HAVE_MOVE_MOUNT) && defined(SYS_move_mount) |
013e0db4 CB |
57 | static inline int move_mount(int from_dfd, const char *from_pathname, int to_dfd, |
58 | const char *to_pathname, unsigned int flags) | |
59 | { | |
e087a188 | 60 | return syscall(SYS_move_mount, from_dfd, from_pathname, to_dfd, |
013e0db4 CB |
61 | to_pathname, flags); |
62 | } | |
1e5381cb | 63 | #endif |
013e0db4 CB |
64 | |
65 | #ifndef MOUNT_ATTR_RDONLY | |
1e5381cb | 66 | # define MOUNT_ATTR_RDONLY 0x00000001 |
013e0db4 CB |
67 | #endif |
68 | ||
69 | #ifndef MOUNT_ATTR_NOSUID | |
1e5381cb | 70 | # define MOUNT_ATTR_NOSUID 0x00000002 |
013e0db4 CB |
71 | #endif |
72 | ||
73 | #ifndef MOUNT_ATTR_NOEXEC | |
1e5381cb | 74 | # define MOUNT_ATTR_NOEXEC 0x00000008 |
013e0db4 CB |
75 | #endif |
76 | ||
77 | #ifndef MOUNT_ATTR_NODIRATIME | |
1e5381cb | 78 | # define MOUNT_ATTR_NODIRATIME 0x00000080 |
013e0db4 CB |
79 | #endif |
80 | ||
81 | #ifndef MOUNT_ATTR__ATIME | |
1e5381cb | 82 | # define MOUNT_ATTR__ATIME 0x00000070 |
013e0db4 CB |
83 | #endif |
84 | ||
85 | #ifndef MOUNT_ATTR_RELATIME | |
1e5381cb | 86 | # define MOUNT_ATTR_RELATIME 0x00000000 |
013e0db4 CB |
87 | #endif |
88 | ||
89 | #ifndef MOUNT_ATTR_NOATIME | |
1e5381cb | 90 | # define MOUNT_ATTR_NOATIME 0x00000010 |
013e0db4 CB |
91 | #endif |
92 | ||
93 | #ifndef MOUNT_ATTR_STRICTATIME | |
1e5381cb | 94 | # define MOUNT_ATTR_STRICTATIME 0x00000020 |
013e0db4 CB |
95 | #endif |
96 | ||
97 | #ifndef MOUNT_ATTR_IDMAP | |
1e5381cb | 98 | # define MOUNT_ATTR_IDMAP 0x00100000 |
013e0db4 CB |
99 | #endif |
100 | ||
1e5381cb | 101 | #ifndef HAVE_STRUCT_MOUNT_ATTR |
43d3c908 | 102 | # include <inttypes.h> |
013e0db4 | 103 | struct mount_attr { |
43d3c908 KZ |
104 | uint64_t attr_set; |
105 | uint64_t attr_clr; | |
106 | uint64_t propagation; | |
107 | uint64_t userns_fd; | |
013e0db4 | 108 | }; |
1e5381cb | 109 | #endif |
013e0db4 | 110 | |
e087a188 | 111 | #if !defined(HAVE_MOUNT_SETATTR) && defined(SYS_mount_setattr) |
013e0db4 CB |
112 | static inline int mount_setattr(int dfd, const char *path, unsigned int flags, |
113 | struct mount_attr *attr, size_t size) | |
114 | { | |
e087a188 | 115 | return syscall(SYS_mount_setattr, dfd, path, flags, attr, size); |
013e0db4 | 116 | } |
1e5381cb | 117 | #endif |
013e0db4 | 118 | |
0120be6f KZ |
119 | #ifndef HAVE_ENUM_FSCONFIG_COMMAND |
120 | enum fsconfig_command { | |
121 | FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */ | |
122 | FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */ | |
123 | FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */ | |
124 | FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */ | |
125 | FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */ | |
126 | FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */ | |
127 | FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */ | |
128 | FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */ | |
129 | }; | |
130 | #endif | |
131 | ||
132 | #if !defined(HAVE_FSCONFIG) && defined(SYS_fsconfig) | |
133 | static inline int fsconfig(int fd, unsigned int cmd, const char *key, | |
134 | const void *value, int aux) | |
135 | { | |
136 | return syscall(SYS_fsconfig, fd, cmd, key, value, aux); | |
137 | } | |
138 | #endif | |
139 | ||
140 | #ifndef FSOPEN_CLOEXEC | |
141 | # define FSOPEN_CLOEXEC 0x00000001 | |
142 | #endif | |
143 | ||
144 | #if !defined(HAVE_FSOPEN) && defined(SYS_fsopen) | |
145 | static inline int fsopen(const char *fsname, unsigned int flags) | |
146 | { | |
147 | return syscall(SYS_fsopen, fsname, flags); | |
148 | } | |
149 | #endif | |
150 | ||
151 | #ifndef FSMOUNT_CLOEXEC | |
152 | # define FSMOUNT_CLOEXEC 0x00000001 | |
153 | #endif | |
154 | ||
155 | #if !defined(HAVE_FSMOUNT) && defined(SYS_fsmount) | |
156 | static inline int fsmount(int fd, unsigned int flags, unsigned int mount_attrs) | |
157 | { | |
158 | return syscall(SYS_fsmount, fd, flags, mount_attrs); | |
159 | } | |
160 | #endif | |
161 | ||
162 | #ifndef FSPICK_CLOEXEC | |
163 | # define FSPICK_CLOEXEC 0x00000001 | |
164 | #endif | |
165 | ||
166 | #ifndef FSPICK_SYMLINK_NOFOLLOW | |
167 | # define FSPICK_SYMLINK_NOFOLLOW 0x00000002 | |
168 | #endif | |
169 | ||
170 | #ifndef FSPICK_NO_AUTOMOUNT | |
171 | # define FSPICK_NO_AUTOMOUNT 0x00000004 | |
172 | #endif | |
173 | ||
174 | #ifdef FSPICK_EMPTY_PATH | |
175 | # define FSPICK_EMPTY_PATH 0x00000008 | |
176 | #endif | |
177 | ||
178 | #if !defined(HAVE_FSPICK) && defined(SYS_fspick) | |
179 | static inline int fspick(int dfd, const char *pathname, unsigned int flags) | |
180 | { | |
181 | return syscall(SYS_fspick, dfd, pathname, flags); | |
182 | } | |
183 | #endif | |
184 | ||
013e0db4 | 185 | |
e087a188 KZ |
186 | /* |
187 | * UL_HAVE_MOUNT_API is used by applications to check that all new mount API is | |
188 | * avalable. | |
189 | */ | |
190 | #if defined(SYS_open_tree) && \ | |
191 | defined(SYS_mount_setattr) && \ | |
0120be6f KZ |
192 | defined(SYS_move_mount) && \ |
193 | defined(SYS_fsconfig) && \ | |
194 | defined(SYS_fsopen) && \ | |
195 | defined(SYS_fsmount) && \ | |
196 | defined(SYS_fspick) | |
e087a188 KZ |
197 | |
198 | # define UL_HAVE_MOUNT_API 1 | |
199 | #endif | |
013e0db4 CB |
200 | |
201 | #endif /* __linux__ */ | |
202 | #endif /* UTIL_LINUX_MOUNT_API_UTILS */ | |
203 |