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