xref: /linux/samples/vfs/samples-vfs.h (revision 100ceb4817a2ac650e29f107cf97161ce3e2289a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __SAMPLES_VFS_H
4 #define __SAMPLES_VFS_H
5 
6 #include <errno.h>
7 #include <linux/types.h>
8 #include <sys/ioctl.h>
9 #include <sys/syscall.h>
10 
11 #define die_errno(format, ...)                                             \
12 	do {                                                               \
13 		fprintf(stderr, "%m | %s: %d: %s: " format "\n", __FILE__, \
14 			__LINE__, __func__, ##__VA_ARGS__);                \
15 		exit(EXIT_FAILURE);                                        \
16 	} while (0)
17 
18 struct statmount {
19 	__u32 size;		/* Total size, including strings */
20 	__u32 mnt_opts;		/* [str] Options (comma separated, escaped) */
21 	__u64 mask;		/* What results were written */
22 	__u32 sb_dev_major;	/* Device ID */
23 	__u32 sb_dev_minor;
24 	__u64 sb_magic;		/* ..._SUPER_MAGIC */
25 	__u32 sb_flags;		/* SB_{RDONLY,SYNCHRONOUS,DIRSYNC,LAZYTIME} */
26 	__u32 fs_type;		/* [str] Filesystem type */
27 	__u64 mnt_id;		/* Unique ID of mount */
28 	__u64 mnt_parent_id;	/* Unique ID of parent (for root == mnt_id) */
29 	__u32 mnt_id_old;	/* Reused IDs used in proc/.../mountinfo */
30 	__u32 mnt_parent_id_old;
31 	__u64 mnt_attr;		/* MOUNT_ATTR_... */
32 	__u64 mnt_propagation;	/* MS_{SHARED,SLAVE,PRIVATE,UNBINDABLE} */
33 	__u64 mnt_peer_group;	/* ID of shared peer group */
34 	__u64 mnt_master;	/* Mount receives propagation from this ID */
35 	__u64 propagate_from;	/* Propagation from in current namespace */
36 	__u32 mnt_root;		/* [str] Root of mount relative to root of fs */
37 	__u32 mnt_point;	/* [str] Mountpoint relative to current root */
38 	__u64 mnt_ns_id;	/* ID of the mount namespace */
39 	__u32 fs_subtype;	/* [str] Subtype of fs_type (if any) */
40 	__u32 sb_source;	/* [str] Source string of the mount */
41 	__u32 opt_num;		/* Number of fs options */
42 	__u32 opt_array;	/* [str] Array of nul terminated fs options */
43 	__u32 opt_sec_num;	/* Number of security options */
44 	__u32 opt_sec_array;	/* [str] Array of nul terminated security options */
45 	__u64 __spare2[46];
46 	char str[];		/* Variable size part containing strings */
47 };
48 
49 struct mnt_id_req {
50 	__u32 size;
51 	__u32 spare;
52 	__u64 mnt_id;
53 	__u64 param;
54 	__u64 mnt_ns_id;
55 };
56 
57 #ifndef MNT_ID_REQ_SIZE_VER0
58 #define MNT_ID_REQ_SIZE_VER0	24 /* sizeof first published struct */
59 #endif
60 
61 #ifndef MNT_ID_REQ_SIZE_VER1
62 #define MNT_ID_REQ_SIZE_VER1	32 /* sizeof second published struct */
63 #endif
64 
65 /* Get the id for a mount namespace */
66 #ifndef NS_GET_MNTNS_ID
67 #define NS_GET_MNTNS_ID _IO(0xb7, 0x5)
68 #endif
69 
70 struct mnt_ns_info {
71 	__u32 size;
72 	__u32 nr_mounts;
73 	__u64 mnt_ns_id;
74 };
75 
76 #ifndef MNT_NS_INFO_SIZE_VER0
77 #define MNT_NS_INFO_SIZE_VER0 16 /* size of first published struct */
78 #endif
79 
80 #ifndef NS_MNT_GET_INFO
81 #define NS_MNT_GET_INFO _IOR(0xb7, 10, struct mnt_ns_info)
82 #endif
83 
84 #ifndef NS_MNT_GET_NEXT
85 #define NS_MNT_GET_NEXT _IOR(0xb7, 11, struct mnt_ns_info)
86 #endif
87 
88 #ifndef NS_MNT_GET_PREV
89 #define NS_MNT_GET_PREV _IOR(0xb7, 12, struct mnt_ns_info)
90 #endif
91 
92 #ifndef PIDFD_GET_MNT_NAMESPACE
93 #define PIDFD_GET_MNT_NAMESPACE _IO(0xFF, 3)
94 #endif
95 
96 #ifndef __NR_listmount
97 #define __NR_listmount 458
98 #endif
99 
100 #ifndef __NR_statmount
101 #define __NR_statmount 457
102 #endif
103 
104 #ifndef LSMT_ROOT
105 #define LSMT_ROOT		0xffffffffffffffff	/* root mount */
106 #endif
107 
108 /* @mask bits for statmount(2) */
109 #ifndef STATMOUNT_SB_BASIC
110 #define STATMOUNT_SB_BASIC		0x00000001U /* Want/got sb_... */
111 #endif
112 
113 #ifndef STATMOUNT_MNT_BASIC
114 #define STATMOUNT_MNT_BASIC		0x00000002U /* Want/got mnt_... */
115 #endif
116 
117 #ifndef STATMOUNT_PROPAGATE_FROM
118 #define STATMOUNT_PROPAGATE_FROM	0x00000004U /* Want/got propagate_from */
119 #endif
120 
121 #ifndef STATMOUNT_MNT_ROOT
122 #define STATMOUNT_MNT_ROOT		0x00000008U /* Want/got mnt_root  */
123 #endif
124 
125 #ifndef STATMOUNT_MNT_POINT
126 #define STATMOUNT_MNT_POINT		0x00000010U /* Want/got mnt_point */
127 #endif
128 
129 #ifndef STATMOUNT_FS_TYPE
130 #define STATMOUNT_FS_TYPE		0x00000020U /* Want/got fs_type */
131 #endif
132 
133 #ifndef STATMOUNT_MNT_NS_ID
134 #define STATMOUNT_MNT_NS_ID		0x00000040U /* Want/got mnt_ns_id */
135 #endif
136 
137 #ifndef STATMOUNT_MNT_OPTS
138 #define STATMOUNT_MNT_OPTS		0x00000080U /* Want/got mnt_opts */
139 #endif
140 
141 #ifndef STATMOUNT_FS_SUBTYPE
142 #define STATMOUNT_FS_SUBTYPE		0x00000100U /* Want/got fs_subtype */
143 #endif
144 
145 #ifndef STATMOUNT_SB_SOURCE
146 #define STATMOUNT_SB_SOURCE		0x00000200U /* Want/got sb_source */
147 #endif
148 
149 #ifndef STATMOUNT_OPT_ARRAY
150 #define STATMOUNT_OPT_ARRAY		0x00000400U /* Want/got opt_... */
151 #endif
152 
153 #ifndef STATMOUNT_OPT_SEC_ARRAY
154 #define STATMOUNT_OPT_SEC_ARRAY		0x00000800U /* Want/got opt_sec... */
155 #endif
156 
157 #ifndef STATX_MNT_ID_UNIQUE
158 #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
159 #endif
160 
161 #ifndef MOUNT_ATTR_RDONLY
162 #define MOUNT_ATTR_RDONLY	0x00000001 /* Mount read-only */
163 #endif
164 
165 #ifndef MOUNT_ATTR_NOSUID
166 #define MOUNT_ATTR_NOSUID	0x00000002 /* Ignore suid and sgid bits */
167 #endif
168 
169 #ifndef MOUNT_ATTR_NODEV
170 #define MOUNT_ATTR_NODEV	0x00000004 /* Disallow access to device special files */
171 #endif
172 
173 #ifndef MOUNT_ATTR_NOEXEC
174 #define MOUNT_ATTR_NOEXEC	0x00000008 /* Disallow program execution */
175 #endif
176 
177 #ifndef MOUNT_ATTR__ATIME
178 #define MOUNT_ATTR__ATIME	0x00000070 /* Setting on how atime should be updated */
179 #endif
180 
181 #ifndef MOUNT_ATTR_RELATIME
182 #define MOUNT_ATTR_RELATIME	0x00000000 /* - Update atime relative to mtime/ctime. */
183 #endif
184 
185 #ifndef MOUNT_ATTR_NOATIME
186 #define MOUNT_ATTR_NOATIME	0x00000010 /* - Do not update access times. */
187 #endif
188 
189 #ifndef MOUNT_ATTR_STRICTATIME
190 #define MOUNT_ATTR_STRICTATIME	0x00000020 /* - Always perform atime updates */
191 #endif
192 
193 #ifndef MOUNT_ATTR_NODIRATIME
194 #define MOUNT_ATTR_NODIRATIME	0x00000080 /* Do not update directory access times */
195 #endif
196 
197 #ifndef MOUNT_ATTR_IDMAP
198 #define MOUNT_ATTR_IDMAP	0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
199 #endif
200 
201 #ifndef MOUNT_ATTR_NOSYMFOLLOW
202 #define MOUNT_ATTR_NOSYMFOLLOW	0x00200000 /* Do not follow symlinks */
203 #endif
204 
205 #ifndef MS_RDONLY
206 #define MS_RDONLY	 1	/* Mount read-only */
207 #endif
208 
209 #ifndef MS_SYNCHRONOUS
210 #define MS_SYNCHRONOUS	16	/* Writes are synced at once */
211 #endif
212 
213 #ifndef MS_MANDLOCK
214 #define MS_MANDLOCK	64	/* Allow mandatory locks on an FS */
215 #endif
216 
217 #ifndef MS_DIRSYNC
218 #define MS_DIRSYNC	128	/* Directory modifications are synchronous */
219 #endif
220 
221 #ifndef MS_UNBINDABLE
222 #define MS_UNBINDABLE	(1<<17)	/* change to unbindable */
223 #endif
224 
225 #ifndef MS_PRIVATE
226 #define MS_PRIVATE	(1<<18)	/* change to private */
227 #endif
228 
229 #ifndef MS_SLAVE
230 #define MS_SLAVE	(1<<19)	/* change to slave */
231 #endif
232 
233 #ifndef MS_SHARED
234 #define MS_SHARED	(1<<20)	/* change to shared */
235 #endif
236 
237 #ifndef MS_LAZYTIME
238 #define MS_LAZYTIME	(1<<25) /* Update the on-disk [acm]times lazily */
239 #endif
240 
241 #endif /* __SAMPLES_VFS_H */
242