Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/samples/vfs/samples-vfs.h
26285 views
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
__u32 mnt_uidmap_num; /* Number of uid mappings */
46
__u32 mnt_uidmap; /* [str] Array of uid mappings */
47
__u32 mnt_gidmap_num; /* Number of gid mappings */
48
__u32 mnt_gidmap; /* [str] Array of gid mappings */
49
__u64 __spare2[44];
50
char str[]; /* Variable size part containing strings */
51
};
52
53
struct mnt_id_req {
54
__u32 size;
55
__u32 spare;
56
__u64 mnt_id;
57
__u64 param;
58
__u64 mnt_ns_id;
59
};
60
61
#ifndef MNT_ID_REQ_SIZE_VER0
62
#define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */
63
#endif
64
65
#ifndef MNT_ID_REQ_SIZE_VER1
66
#define MNT_ID_REQ_SIZE_VER1 32 /* sizeof second published struct */
67
#endif
68
69
/* Get the id for a mount namespace */
70
#ifndef NS_GET_MNTNS_ID
71
#define NS_GET_MNTNS_ID _IO(0xb7, 0x5)
72
#endif
73
74
struct mnt_ns_info {
75
__u32 size;
76
__u32 nr_mounts;
77
__u64 mnt_ns_id;
78
};
79
80
#ifndef MNT_NS_INFO_SIZE_VER0
81
#define MNT_NS_INFO_SIZE_VER0 16 /* size of first published struct */
82
#endif
83
84
#ifndef NS_MNT_GET_INFO
85
#define NS_MNT_GET_INFO _IOR(0xb7, 10, struct mnt_ns_info)
86
#endif
87
88
#ifndef NS_MNT_GET_NEXT
89
#define NS_MNT_GET_NEXT _IOR(0xb7, 11, struct mnt_ns_info)
90
#endif
91
92
#ifndef NS_MNT_GET_PREV
93
#define NS_MNT_GET_PREV _IOR(0xb7, 12, struct mnt_ns_info)
94
#endif
95
96
#ifndef PIDFD_GET_MNT_NAMESPACE
97
#define PIDFD_GET_MNT_NAMESPACE _IO(0xFF, 3)
98
#endif
99
100
#ifndef __NR_listmount
101
#define __NR_listmount 458
102
#endif
103
104
#ifndef __NR_statmount
105
#define __NR_statmount 457
106
#endif
107
108
#ifndef LSMT_ROOT
109
#define LSMT_ROOT 0xffffffffffffffff /* root mount */
110
#endif
111
112
/* @mask bits for statmount(2) */
113
#ifndef STATMOUNT_SB_BASIC
114
#define STATMOUNT_SB_BASIC 0x00000001U /* Want/got sb_... */
115
#endif
116
117
#ifndef STATMOUNT_MNT_BASIC
118
#define STATMOUNT_MNT_BASIC 0x00000002U /* Want/got mnt_... */
119
#endif
120
121
#ifndef STATMOUNT_PROPAGATE_FROM
122
#define STATMOUNT_PROPAGATE_FROM 0x00000004U /* Want/got propagate_from */
123
#endif
124
125
#ifndef STATMOUNT_MNT_ROOT
126
#define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */
127
#endif
128
129
#ifndef STATMOUNT_MNT_POINT
130
#define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */
131
#endif
132
133
#ifndef STATMOUNT_FS_TYPE
134
#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
135
#endif
136
137
#ifndef STATMOUNT_MNT_NS_ID
138
#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
139
#endif
140
141
#ifndef STATMOUNT_MNT_OPTS
142
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
143
#endif
144
145
#ifndef STATMOUNT_FS_SUBTYPE
146
#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
147
#endif
148
149
#ifndef STATMOUNT_SB_SOURCE
150
#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
151
#endif
152
153
#ifndef STATMOUNT_OPT_ARRAY
154
#define STATMOUNT_OPT_ARRAY 0x00000400U /* Want/got opt_... */
155
#endif
156
157
#ifndef STATMOUNT_OPT_SEC_ARRAY
158
#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U /* Want/got opt_sec... */
159
#endif
160
161
#ifndef STATX_MNT_ID_UNIQUE
162
#define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
163
#endif
164
165
#ifndef STATMOUNT_MNT_UIDMAP
166
#define STATMOUNT_MNT_UIDMAP 0x00002000U /* Want/got uidmap... */
167
#endif
168
169
#ifndef STATMOUNT_MNT_GIDMAP
170
#define STATMOUNT_MNT_GIDMAP 0x00004000U /* Want/got gidmap... */
171
#endif
172
173
#ifndef MOUNT_ATTR_RDONLY
174
#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
175
#endif
176
177
#ifndef MOUNT_ATTR_NOSUID
178
#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
179
#endif
180
181
#ifndef MOUNT_ATTR_NODEV
182
#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
183
#endif
184
185
#ifndef MOUNT_ATTR_NOEXEC
186
#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
187
#endif
188
189
#ifndef MOUNT_ATTR__ATIME
190
#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
191
#endif
192
193
#ifndef MOUNT_ATTR_RELATIME
194
#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
195
#endif
196
197
#ifndef MOUNT_ATTR_NOATIME
198
#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
199
#endif
200
201
#ifndef MOUNT_ATTR_STRICTATIME
202
#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
203
#endif
204
205
#ifndef MOUNT_ATTR_NODIRATIME
206
#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
207
#endif
208
209
#ifndef MOUNT_ATTR_IDMAP
210
#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
211
#endif
212
213
#ifndef MOUNT_ATTR_NOSYMFOLLOW
214
#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */
215
#endif
216
217
#ifndef MS_RDONLY
218
#define MS_RDONLY 1 /* Mount read-only */
219
#endif
220
221
#ifndef MS_SYNCHRONOUS
222
#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
223
#endif
224
225
#ifndef MS_MANDLOCK
226
#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
227
#endif
228
229
#ifndef MS_DIRSYNC
230
#define MS_DIRSYNC 128 /* Directory modifications are synchronous */
231
#endif
232
233
#ifndef MS_UNBINDABLE
234
#define MS_UNBINDABLE (1<<17) /* change to unbindable */
235
#endif
236
237
#ifndef MS_PRIVATE
238
#define MS_PRIVATE (1<<18) /* change to private */
239
#endif
240
241
#ifndef MS_SLAVE
242
#define MS_SLAVE (1<<19) /* change to slave */
243
#endif
244
245
#ifndef MS_SHARED
246
#define MS_SHARED (1<<20) /* change to shared */
247
#endif
248
249
#ifndef MS_LAZYTIME
250
#define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
251
#endif
252
253
#endif /* __SAMPLES_VFS_H */
254
255