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