]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | #pragma once | |
4 | ||
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2010 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
11 | under the terms of the GNU Lesser General Public License as published by | |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | Lesser General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU Lesser General Public License | |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
22 | ***/ | |
23 | ||
24 | /* Missing glibc definitions to access certain kernel APIs */ | |
25 | ||
26 | #include <sys/resource.h> | |
27 | #include <sys/syscall.h> | |
28 | #include <fcntl.h> | |
29 | #include <stdlib.h> | |
30 | #include <unistd.h> | |
60f067b4 | 31 | #include <errno.h> |
663996b3 | 32 | #include <linux/oom.h> |
14228c0d | 33 | #include <linux/input.h> |
60f067b4 JS |
34 | #include <linux/if_link.h> |
35 | #include <linux/loop.h> | |
f47781d8 MP |
36 | #include <linux/audit.h> |
37 | #include <linux/capability.h> | |
e3bff60a | 38 | #include <linux/neighbour.h> |
663996b3 MS |
39 | |
40 | #ifdef HAVE_AUDIT | |
41 | #include <libaudit.h> | |
42 | #endif | |
43 | ||
663996b3 MS |
44 | #ifdef ARCH_MIPS |
45 | #include <asm/sgidefs.h> | |
46 | #endif | |
47 | ||
e735f4d4 MP |
48 | #ifdef HAVE_LINUX_BTRFS_H |
49 | #include <linux/btrfs.h> | |
50 | #endif | |
51 | ||
52 | #include "macro.h" | |
53 | ||
663996b3 MS |
54 | #ifndef RLIMIT_RTTIME |
55 | #define RLIMIT_RTTIME 15 | |
56 | #endif | |
57 | ||
60f067b4 JS |
58 | /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */ |
59 | #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS) | |
60 | ||
663996b3 MS |
61 | #ifndef F_LINUX_SPECIFIC_BASE |
62 | #define F_LINUX_SPECIFIC_BASE 1024 | |
63 | #endif | |
64 | ||
65 | #ifndef F_SETPIPE_SZ | |
66 | #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7) | |
67 | #endif | |
68 | ||
69 | #ifndef F_GETPIPE_SZ | |
70 | #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8) | |
71 | #endif | |
72 | ||
5eef597e MP |
73 | #ifndef F_ADD_SEALS |
74 | #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) | |
75 | #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) | |
76 | ||
77 | #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ | |
78 | #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ | |
79 | #define F_SEAL_GROW 0x0004 /* prevent file from growing */ | |
80 | #define F_SEAL_WRITE 0x0008 /* prevent writes */ | |
81 | #endif | |
82 | ||
e735f4d4 MP |
83 | #ifndef F_OFD_GETLK |
84 | #define F_OFD_GETLK 36 | |
85 | #define F_OFD_SETLK 37 | |
86 | #define F_OFD_SETLKW 38 | |
87 | #endif | |
88 | ||
5eef597e | 89 | #ifndef MFD_ALLOW_SEALING |
f47781d8 MP |
90 | #define MFD_ALLOW_SEALING 0x0002U |
91 | #endif | |
92 | ||
93 | #ifndef MFD_CLOEXEC | |
94 | #define MFD_CLOEXEC 0x0001U | |
5eef597e MP |
95 | #endif |
96 | ||
663996b3 MS |
97 | #ifndef IP_FREEBIND |
98 | #define IP_FREEBIND 15 | |
99 | #endif | |
100 | ||
101 | #ifndef OOM_SCORE_ADJ_MIN | |
102 | #define OOM_SCORE_ADJ_MIN (-1000) | |
103 | #endif | |
104 | ||
105 | #ifndef OOM_SCORE_ADJ_MAX | |
106 | #define OOM_SCORE_ADJ_MAX 1000 | |
107 | #endif | |
108 | ||
109 | #ifndef AUDIT_SERVICE_START | |
110 | #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */ | |
111 | #endif | |
112 | ||
113 | #ifndef AUDIT_SERVICE_STOP | |
114 | #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */ | |
115 | #endif | |
116 | ||
117 | #ifndef TIOCVHANGUP | |
118 | #define TIOCVHANGUP 0x5437 | |
119 | #endif | |
120 | ||
121 | #ifndef IP_TRANSPARENT | |
122 | #define IP_TRANSPARENT 19 | |
123 | #endif | |
124 | ||
60f067b4 JS |
125 | #ifndef SOL_NETLINK |
126 | #define SOL_NETLINK 270 | |
127 | #endif | |
128 | ||
663996b3 MS |
129 | #if !HAVE_DECL_PIVOT_ROOT |
130 | static inline int pivot_root(const char *new_root, const char *put_old) { | |
131 | return syscall(SYS_pivot_root, new_root, put_old); | |
132 | } | |
133 | #endif | |
134 | ||
f47781d8 MP |
135 | #ifndef __NR_memfd_create |
136 | # if defined __x86_64__ | |
5eef597e | 137 | # define __NR_memfd_create 319 |
f47781d8 | 138 | # elif defined __arm__ |
5eef597e | 139 | # define __NR_memfd_create 385 |
e735f4d4 MP |
140 | # elif defined __aarch64__ |
141 | # define __NR_memfd_create 279 | |
f47781d8 MP |
142 | # elif defined _MIPS_SIM |
143 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
144 | # define __NR_memfd_create 4354 | |
145 | # endif | |
146 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
147 | # define __NR_memfd_create 6318 | |
148 | # endif | |
149 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
150 | # define __NR_memfd_create 5314 | |
151 | # endif | |
152 | # elif defined __i386__ | |
5eef597e | 153 | # define __NR_memfd_create 356 |
f47781d8 MP |
154 | # else |
155 | # warning "__NR_memfd_create unknown for your architecture" | |
156 | # define __NR_memfd_create 0xffffffff | |
663996b3 | 157 | # endif |
663996b3 MS |
158 | #endif |
159 | ||
5eef597e MP |
160 | #ifndef HAVE_MEMFD_CREATE |
161 | static inline int memfd_create(const char *name, unsigned int flags) { | |
162 | return syscall(__NR_memfd_create, name, flags); | |
663996b3 MS |
163 | } |
164 | #endif | |
165 | ||
f47781d8 MP |
166 | #ifndef __NR_getrandom |
167 | # if defined __x86_64__ | |
168 | # define __NR_getrandom 318 | |
169 | # elif defined(__i386__) | |
170 | # define __NR_getrandom 355 | |
e735f4d4 | 171 | # elif defined(__arm__) |
f47781d8 | 172 | # define __NR_getrandom 384 |
e735f4d4 MP |
173 | # elif defined(__aarch64__) |
174 | # define __NR_getrandom 278 | |
f47781d8 MP |
175 | # elif defined(__ia64__) |
176 | # define __NR_getrandom 1339 | |
177 | # elif defined(__m68k__) | |
178 | # define __NR_getrandom 352 | |
179 | # elif defined(__s390x__) | |
180 | # define __NR_getrandom 349 | |
e735f4d4 MP |
181 | # elif defined(__powerpc__) |
182 | # define __NR_getrandom 359 | |
e3bff60a MP |
183 | # elif defined _MIPS_SIM |
184 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
185 | # define __NR_getrandom 4353 | |
186 | # endif | |
187 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
188 | # define __NR_getrandom 6317 | |
189 | # endif | |
190 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
191 | # define __NR_getrandom 5313 | |
192 | # endif | |
f47781d8 MP |
193 | # else |
194 | # warning "__NR_getrandom unknown for your architecture" | |
195 | # define __NR_getrandom 0xffffffff | |
196 | # endif | |
197 | #endif | |
198 | ||
199 | #if !HAVE_DECL_GETRANDOM | |
200 | static inline int getrandom(void *buffer, size_t count, unsigned flags) { | |
201 | return syscall(__NR_getrandom, buffer, count, flags); | |
202 | } | |
203 | #endif | |
204 | ||
205 | #ifndef GRND_NONBLOCK | |
206 | #define GRND_NONBLOCK 0x0001 | |
207 | #endif | |
208 | ||
209 | #ifndef GRND_RANDOM | |
210 | #define GRND_RANDOM 0x0002 | |
211 | #endif | |
212 | ||
663996b3 MS |
213 | #ifndef BTRFS_IOCTL_MAGIC |
214 | #define BTRFS_IOCTL_MAGIC 0x94 | |
215 | #endif | |
216 | ||
217 | #ifndef BTRFS_PATH_NAME_MAX | |
218 | #define BTRFS_PATH_NAME_MAX 4087 | |
219 | #endif | |
220 | ||
14228c0d MB |
221 | #ifndef BTRFS_DEVICE_PATH_NAME_MAX |
222 | #define BTRFS_DEVICE_PATH_NAME_MAX 1024 | |
223 | #endif | |
224 | ||
225 | #ifndef BTRFS_FSID_SIZE | |
226 | #define BTRFS_FSID_SIZE 16 | |
227 | #endif | |
228 | ||
229 | #ifndef BTRFS_UUID_SIZE | |
230 | #define BTRFS_UUID_SIZE 16 | |
231 | #endif | |
232 | ||
e3bff60a MP |
233 | #ifndef BTRFS_SUBVOL_RDONLY |
234 | #define BTRFS_SUBVOL_RDONLY (1ULL << 1) | |
235 | #endif | |
236 | ||
237 | #ifndef BTRFS_SUBVOL_NAME_MAX | |
238 | #define BTRFS_SUBVOL_NAME_MAX 4039 | |
239 | #endif | |
240 | ||
241 | #ifndef BTRFS_INO_LOOKUP_PATH_MAX | |
242 | #define BTRFS_INO_LOOKUP_PATH_MAX 4080 | |
243 | #endif | |
244 | ||
245 | #ifndef BTRFS_SEARCH_ARGS_BUFSIZE | |
246 | #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) | |
247 | #endif | |
248 | ||
14228c0d | 249 | #ifndef HAVE_LINUX_BTRFS_H |
663996b3 MS |
250 | struct btrfs_ioctl_vol_args { |
251 | int64_t fd; | |
252 | char name[BTRFS_PATH_NAME_MAX + 1]; | |
253 | }; | |
254 | ||
e3bff60a MP |
255 | struct btrfs_qgroup_limit { |
256 | __u64 flags; | |
257 | __u64 max_rfer; | |
258 | __u64 max_excl; | |
259 | __u64 rsv_rfer; | |
260 | __u64 rsv_excl; | |
261 | }; | |
262 | ||
263 | struct btrfs_qgroup_inherit { | |
264 | __u64 flags; | |
265 | __u64 num_qgroups; | |
266 | __u64 num_ref_copies; | |
267 | __u64 num_excl_copies; | |
268 | struct btrfs_qgroup_limit lim; | |
269 | __u64 qgroups[0]; | |
270 | }; | |
271 | ||
272 | struct btrfs_ioctl_vol_args_v2 { | |
273 | __s64 fd; | |
274 | __u64 transid; | |
275 | __u64 flags; | |
276 | union { | |
277 | struct { | |
278 | __u64 size; | |
279 | struct btrfs_qgroup_inherit *qgroup_inherit; | |
280 | }; | |
281 | __u64 unused[4]; | |
282 | }; | |
283 | char name[BTRFS_SUBVOL_NAME_MAX + 1]; | |
284 | }; | |
285 | ||
14228c0d MB |
286 | struct btrfs_ioctl_dev_info_args { |
287 | uint64_t devid; /* in/out */ | |
288 | uint8_t uuid[BTRFS_UUID_SIZE]; /* in/out */ | |
289 | uint64_t bytes_used; /* out */ | |
290 | uint64_t total_bytes; /* out */ | |
291 | uint64_t unused[379]; /* pad to 4k */ | |
292 | char path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */ | |
293 | }; | |
294 | ||
295 | struct btrfs_ioctl_fs_info_args { | |
296 | uint64_t max_id; /* out */ | |
297 | uint64_t num_devices; /* out */ | |
298 | uint8_t fsid[BTRFS_FSID_SIZE]; /* out */ | |
299 | uint64_t reserved[124]; /* pad to 1k */ | |
300 | }; | |
e3bff60a MP |
301 | |
302 | struct btrfs_ioctl_ino_lookup_args { | |
303 | __u64 treeid; | |
304 | __u64 objectid; | |
305 | char name[BTRFS_INO_LOOKUP_PATH_MAX]; | |
306 | }; | |
307 | ||
308 | struct btrfs_ioctl_search_key { | |
309 | /* which root are we searching. 0 is the tree of tree roots */ | |
310 | __u64 tree_id; | |
311 | ||
312 | /* keys returned will be >= min and <= max */ | |
313 | __u64 min_objectid; | |
314 | __u64 max_objectid; | |
315 | ||
316 | /* keys returned will be >= min and <= max */ | |
317 | __u64 min_offset; | |
318 | __u64 max_offset; | |
319 | ||
320 | /* max and min transids to search for */ | |
321 | __u64 min_transid; | |
322 | __u64 max_transid; | |
323 | ||
324 | /* keys returned will be >= min and <= max */ | |
325 | __u32 min_type; | |
326 | __u32 max_type; | |
327 | ||
328 | /* | |
329 | * how many items did userland ask for, and how many are we | |
330 | * returning | |
331 | */ | |
332 | __u32 nr_items; | |
333 | ||
334 | /* align to 64 bits */ | |
335 | __u32 unused; | |
336 | ||
337 | /* some extra for later */ | |
338 | __u64 unused1; | |
339 | __u64 unused2; | |
340 | __u64 unused3; | |
341 | __u64 unused4; | |
342 | }; | |
343 | ||
344 | struct btrfs_ioctl_search_header { | |
345 | __u64 transid; | |
346 | __u64 objectid; | |
347 | __u64 offset; | |
348 | __u32 type; | |
349 | __u32 len; | |
350 | }; | |
351 | ||
352 | ||
353 | struct btrfs_ioctl_search_args { | |
354 | struct btrfs_ioctl_search_key key; | |
355 | char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; | |
356 | }; | |
357 | ||
358 | struct btrfs_ioctl_clone_range_args { | |
359 | __s64 src_fd; | |
360 | __u64 src_offset, src_length; | |
361 | __u64 dest_offset; | |
362 | }; | |
14228c0d MB |
363 | #endif |
364 | ||
663996b3 | 365 | #ifndef BTRFS_IOC_DEFRAG |
5eef597e MP |
366 | #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ |
367 | struct btrfs_ioctl_vol_args) | |
663996b3 MS |
368 | #endif |
369 | ||
e3bff60a MP |
370 | #ifndef BTRFS_IOC_CLONE |
371 | #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int) | |
372 | #endif | |
373 | ||
374 | #ifndef BTRFS_IOC_CLONE_RANGE | |
375 | #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \ | |
376 | struct btrfs_ioctl_clone_range_args) | |
377 | #endif | |
378 | ||
379 | #ifndef BTRFS_IOC_SUBVOL_CREATE | |
380 | #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ | |
381 | struct btrfs_ioctl_vol_args) | |
382 | #endif | |
383 | ||
384 | #ifndef BTRFS_IOC_SNAP_DESTROY | |
385 | #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ | |
386 | struct btrfs_ioctl_vol_args) | |
387 | #endif | |
388 | ||
389 | #ifndef BTRFS_IOC_TREE_SEARCH | |
390 | #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ | |
391 | struct btrfs_ioctl_search_args) | |
392 | #endif | |
393 | ||
394 | #ifndef BTRFS_IOC_INO_LOOKUP | |
395 | #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \ | |
396 | struct btrfs_ioctl_ino_lookup_args) | |
397 | #endif | |
398 | ||
399 | #ifndef BTRFS_IOC_SNAP_CREATE_V2 | |
400 | #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ | |
401 | struct btrfs_ioctl_vol_args_v2) | |
402 | #endif | |
403 | ||
404 | #ifndef BTRFS_IOC_SUBVOL_GETFLAGS | |
405 | #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64) | |
406 | #endif | |
407 | ||
408 | #ifndef BTRFS_IOC_SUBVOL_SETFLAGS | |
409 | #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) | |
410 | #endif | |
411 | ||
14228c0d MB |
412 | #ifndef BTRFS_IOC_DEV_INFO |
413 | #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \ | |
414 | struct btrfs_ioctl_dev_info_args) | |
415 | #endif | |
416 | ||
417 | #ifndef BTRFS_IOC_FS_INFO | |
418 | #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ | |
5eef597e MP |
419 | struct btrfs_ioctl_fs_info_args) |
420 | #endif | |
421 | ||
422 | #ifndef BTRFS_IOC_DEVICES_READY | |
423 | #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \ | |
424 | struct btrfs_ioctl_vol_args) | |
14228c0d MB |
425 | #endif |
426 | ||
e735f4d4 MP |
427 | #ifndef BTRFS_FIRST_FREE_OBJECTID |
428 | #define BTRFS_FIRST_FREE_OBJECTID 256 | |
429 | #endif | |
430 | ||
e3bff60a MP |
431 | #ifndef BTRFS_LAST_FREE_OBJECTID |
432 | #define BTRFS_LAST_FREE_OBJECTID -256ULL | |
433 | #endif | |
434 | ||
e735f4d4 MP |
435 | #ifndef BTRFS_ROOT_TREE_OBJECTID |
436 | #define BTRFS_ROOT_TREE_OBJECTID 1 | |
437 | #endif | |
438 | ||
439 | #ifndef BTRFS_QUOTA_TREE_OBJECTID | |
440 | #define BTRFS_QUOTA_TREE_OBJECTID 8ULL | |
441 | #endif | |
442 | ||
443 | #ifndef BTRFS_ROOT_ITEM_KEY | |
444 | #define BTRFS_ROOT_ITEM_KEY 132 | |
445 | #endif | |
446 | ||
447 | #ifndef BTRFS_QGROUP_STATUS_KEY | |
448 | #define BTRFS_QGROUP_STATUS_KEY 240 | |
449 | #endif | |
450 | ||
451 | #ifndef BTRFS_QGROUP_INFO_KEY | |
452 | #define BTRFS_QGROUP_INFO_KEY 242 | |
453 | #endif | |
454 | ||
455 | #ifndef BTRFS_QGROUP_LIMIT_KEY | |
456 | #define BTRFS_QGROUP_LIMIT_KEY 244 | |
457 | #endif | |
458 | ||
e3bff60a MP |
459 | #ifndef BTRFS_ROOT_BACKREF_KEY |
460 | #define BTRFS_ROOT_BACKREF_KEY 144 | |
461 | #endif | |
462 | ||
663996b3 MS |
463 | #ifndef BTRFS_SUPER_MAGIC |
464 | #define BTRFS_SUPER_MAGIC 0x9123683E | |
465 | #endif | |
466 | ||
467 | #ifndef MS_MOVE | |
468 | #define MS_MOVE 8192 | |
469 | #endif | |
470 | ||
471 | #ifndef MS_PRIVATE | |
472 | #define MS_PRIVATE (1 << 18) | |
473 | #endif | |
474 | ||
475 | #if !HAVE_DECL_GETTID | |
476 | static inline pid_t gettid(void) { | |
477 | return (pid_t) syscall(SYS_gettid); | |
478 | } | |
479 | #endif | |
480 | ||
481 | #ifndef SCM_SECURITY | |
482 | #define SCM_SECURITY 0x03 | |
483 | #endif | |
484 | ||
485 | #ifndef MS_STRICTATIME | |
486 | #define MS_STRICTATIME (1<<24) | |
487 | #endif | |
488 | ||
489 | #ifndef MS_REC | |
490 | #define MS_REC 16384 | |
491 | #endif | |
492 | ||
493 | #ifndef MS_SHARED | |
494 | #define MS_SHARED (1<<20) | |
495 | #endif | |
496 | ||
497 | #ifndef PR_SET_NO_NEW_PRIVS | |
498 | #define PR_SET_NO_NEW_PRIVS 38 | |
499 | #endif | |
500 | ||
501 | #ifndef PR_SET_CHILD_SUBREAPER | |
502 | #define PR_SET_CHILD_SUBREAPER 36 | |
503 | #endif | |
504 | ||
505 | #ifndef MAX_HANDLE_SZ | |
506 | #define MAX_HANDLE_SZ 128 | |
507 | #endif | |
508 | ||
60f067b4 JS |
509 | #ifndef __NR_name_to_handle_at |
510 | # if defined(__x86_64__) | |
663996b3 | 511 | # define __NR_name_to_handle_at 303 |
60f067b4 | 512 | # elif defined(__i386__) |
663996b3 | 513 | # define __NR_name_to_handle_at 341 |
60f067b4 | 514 | # elif defined(__arm__) |
663996b3 | 515 | # define __NR_name_to_handle_at 370 |
60f067b4 | 516 | # elif defined(__powerpc__) |
663996b3 | 517 | # define __NR_name_to_handle_at 345 |
60f067b4 JS |
518 | # else |
519 | # error "__NR_name_to_handle_at is not defined" | |
663996b3 MS |
520 | # endif |
521 | #endif | |
522 | ||
523 | #if !HAVE_DECL_NAME_TO_HANDLE_AT | |
524 | struct file_handle { | |
525 | unsigned int handle_bytes; | |
526 | int handle_type; | |
527 | unsigned char f_handle[0]; | |
528 | }; | |
529 | ||
530 | static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) { | |
531 | return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags); | |
532 | } | |
533 | #endif | |
534 | ||
535 | #ifndef HAVE_SECURE_GETENV | |
536 | # ifdef HAVE___SECURE_GETENV | |
537 | # define secure_getenv __secure_getenv | |
538 | # else | |
60f067b4 | 539 | # error "neither secure_getenv nor __secure_getenv are available" |
663996b3 MS |
540 | # endif |
541 | #endif | |
542 | ||
543 | #ifndef CIFS_MAGIC_NUMBER | |
60f067b4 | 544 | # define CIFS_MAGIC_NUMBER 0xFF534D42 |
663996b3 MS |
545 | #endif |
546 | ||
547 | #ifndef TFD_TIMER_CANCEL_ON_SET | |
60f067b4 | 548 | # define TFD_TIMER_CANCEL_ON_SET (1 << 1) |
663996b3 | 549 | #endif |
14228c0d MB |
550 | |
551 | #ifndef SO_REUSEPORT | |
60f067b4 | 552 | # define SO_REUSEPORT 15 |
14228c0d MB |
553 | #endif |
554 | ||
555 | #ifndef EVIOCREVOKE | |
60f067b4 | 556 | # define EVIOCREVOKE _IOW('E', 0x91, int) |
14228c0d MB |
557 | #endif |
558 | ||
559 | #ifndef DRM_IOCTL_SET_MASTER | |
60f067b4 | 560 | # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e) |
14228c0d MB |
561 | #endif |
562 | ||
563 | #ifndef DRM_IOCTL_DROP_MASTER | |
60f067b4 JS |
564 | # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f) |
565 | #endif | |
566 | ||
567 | #if defined(__i386__) || defined(__x86_64__) | |
568 | ||
569 | /* The precise definition of __O_TMPFILE is arch specific, so let's | |
570 | * just define this on x86 where we know the value. */ | |
571 | ||
572 | #ifndef __O_TMPFILE | |
573 | #define __O_TMPFILE 020000000 | |
574 | #endif | |
575 | ||
576 | /* a horrid kludge trying to make sure that this will fail on old kernels */ | |
577 | #ifndef O_TMPFILE | |
578 | #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) | |
579 | #endif | |
580 | ||
581 | #endif | |
582 | ||
583 | #ifndef __NR_setns | |
584 | # if defined(__x86_64__) | |
585 | # define __NR_setns 308 | |
586 | # elif defined(__i386__) | |
587 | # define __NR_setns 346 | |
588 | # else | |
589 | # error "__NR_setns is not defined" | |
590 | # endif | |
591 | #endif | |
592 | ||
593 | #if !HAVE_DECL_SETNS | |
594 | static inline int setns(int fd, int nstype) { | |
595 | return syscall(__NR_setns, fd, nstype); | |
596 | } | |
597 | #endif | |
598 | ||
599 | #if !HAVE_DECL_LO_FLAGS_PARTSCAN | |
600 | #define LO_FLAGS_PARTSCAN 8 | |
601 | #endif | |
602 | ||
603 | #ifndef LOOP_CTL_REMOVE | |
604 | #define LOOP_CTL_REMOVE 0x4C81 | |
605 | #endif | |
606 | ||
607 | #ifndef LOOP_CTL_GET_FREE | |
608 | #define LOOP_CTL_GET_FREE 0x4C82 | |
609 | #endif | |
610 | ||
e735f4d4 MP |
611 | #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE |
612 | #define IFLA_INET6_UNSPEC 0 | |
613 | #define IFLA_INET6_FLAGS 1 | |
614 | #define IFLA_INET6_CONF 2 | |
615 | #define IFLA_INET6_STATS 3 | |
616 | #define IFLA_INET6_MCAST 4 | |
617 | #define IFLA_INET6_CACHEINFO 5 | |
618 | #define IFLA_INET6_ICMP6STATS 6 | |
619 | #define IFLA_INET6_TOKEN 7 | |
620 | #define IFLA_INET6_ADDR_GEN_MODE 8 | |
621 | #define __IFLA_INET6_MAX 9 | |
622 | ||
623 | #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1) | |
624 | ||
625 | #define IN6_ADDR_GEN_MODE_EUI64 0 | |
626 | #define IN6_ADDR_GEN_MODE_NONE 1 | |
627 | #endif | |
628 | ||
5eef597e MP |
629 | #if !HAVE_DECL_IFLA_MACVLAN_FLAGS |
630 | #define IFLA_MACVLAN_UNSPEC 0 | |
631 | #define IFLA_MACVLAN_MODE 1 | |
632 | #define IFLA_MACVLAN_FLAGS 2 | |
633 | #define __IFLA_MACVLAN_MAX 3 | |
634 | ||
635 | #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1) | |
636 | #endif | |
637 | ||
e735f4d4 MP |
638 | #if !HAVE_DECL_IFLA_IPVLAN_MODE |
639 | #define IFLA_IPVLAN_UNSPEC 0 | |
640 | #define IFLA_IPVLAN_MODE 1 | |
641 | #define __IFLA_IPVLAN_MAX 2 | |
642 | ||
643 | #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1) | |
644 | ||
645 | #define IPVLAN_MODE_L2 0 | |
646 | #define IPVLAN_MODE_L3 1 | |
647 | #define IPVLAN_MAX 2 | |
648 | #endif | |
649 | ||
5eef597e MP |
650 | #if !HAVE_DECL_IFLA_VTI_REMOTE |
651 | #define IFLA_VTI_UNSPEC 0 | |
652 | #define IFLA_VTI_LINK 1 | |
653 | #define IFLA_VTI_IKEY 2 | |
654 | #define IFLA_VTI_OKEY 3 | |
655 | #define IFLA_VTI_LOCAL 4 | |
656 | #define IFLA_VTI_REMOTE 5 | |
657 | #define __IFLA_VTI_MAX 6 | |
658 | ||
659 | #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1) | |
660 | #endif | |
661 | ||
e842803a MB |
662 | #if !HAVE_DECL_IFLA_PHYS_PORT_ID |
663 | #undef IFLA_PROMISCUITY | |
664 | #define IFLA_PROMISCUITY 30 | |
665 | #define IFLA_NUM_TX_QUEUES 31 | |
666 | #define IFLA_NUM_RX_QUEUES 32 | |
667 | #define IFLA_CARRIER 33 | |
668 | #define IFLA_PHYS_PORT_ID 34 | |
669 | #define __IFLA_MAX 35 | |
670 | ||
671 | #define IFLA_MAX (__IFLA_MAX - 1) | |
672 | #endif | |
673 | ||
674 | #if !HAVE_DECL_IFLA_BOND_AD_INFO | |
675 | #define IFLA_BOND_UNSPEC 0 | |
676 | #define IFLA_BOND_MODE 1 | |
677 | #define IFLA_BOND_ACTIVE_SLAVE 2 | |
678 | #define IFLA_BOND_MIIMON 3 | |
679 | #define IFLA_BOND_UPDELAY 4 | |
680 | #define IFLA_BOND_DOWNDELAY 5 | |
681 | #define IFLA_BOND_USE_CARRIER 6 | |
682 | #define IFLA_BOND_ARP_INTERVAL 7 | |
683 | #define IFLA_BOND_ARP_IP_TARGET 8 | |
684 | #define IFLA_BOND_ARP_VALIDATE 9 | |
685 | #define IFLA_BOND_ARP_ALL_TARGETS 10 | |
686 | #define IFLA_BOND_PRIMARY 11 | |
687 | #define IFLA_BOND_PRIMARY_RESELECT 12 | |
688 | #define IFLA_BOND_FAIL_OVER_MAC 13 | |
689 | #define IFLA_BOND_XMIT_HASH_POLICY 14 | |
690 | #define IFLA_BOND_RESEND_IGMP 15 | |
691 | #define IFLA_BOND_NUM_PEER_NOTIF 16 | |
692 | #define IFLA_BOND_ALL_SLAVES_ACTIVE 17 | |
693 | #define IFLA_BOND_MIN_LINKS 18 | |
694 | #define IFLA_BOND_LP_INTERVAL 19 | |
695 | #define IFLA_BOND_PACKETS_PER_SLAVE 20 | |
696 | #define IFLA_BOND_AD_LACP_RATE 21 | |
697 | #define IFLA_BOND_AD_SELECT 22 | |
698 | #define IFLA_BOND_AD_INFO 23 | |
699 | #define __IFLA_BOND_MAX 24 | |
60f067b4 | 700 | |
f47781d8 | 701 | #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1) |
14228c0d | 702 | #endif |
e842803a MB |
703 | |
704 | #if !HAVE_DECL_IFLA_VLAN_PROTOCOL | |
705 | #define IFLA_VLAN_UNSPEC 0 | |
706 | #define IFLA_VLAN_ID 1 | |
707 | #define IFLA_VLAN_FLAGS 2 | |
708 | #define IFLA_VLAN_EGRESS_QOS 3 | |
709 | #define IFLA_VLAN_INGRESS_QOS 4 | |
710 | #define IFLA_VLAN_PROTOCOL 5 | |
711 | #define __IFLA_VLAN_MAX 6 | |
712 | ||
713 | #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1) | |
714 | #endif | |
715 | ||
716 | #if !HAVE_DECL_IFLA_VXLAN_LOCAL6 | |
717 | #define IFLA_VXLAN_UNSPEC 0 | |
718 | #define IFLA_VXLAN_ID 1 | |
719 | #define IFLA_VXLAN_GROUP 2 | |
720 | #define IFLA_VXLAN_LINK 3 | |
721 | #define IFLA_VXLAN_LOCAL 4 | |
722 | #define IFLA_VXLAN_TTL 5 | |
723 | #define IFLA_VXLAN_TOS 6 | |
724 | #define IFLA_VXLAN_LEARNING 7 | |
725 | #define IFLA_VXLAN_AGEING 8 | |
726 | #define IFLA_VXLAN_LIMIT 9 | |
727 | #define IFLA_VXLAN_PORT_RANGE 10 | |
728 | #define IFLA_VXLAN_PROXY 11 | |
729 | #define IFLA_VXLAN_RSC 12 | |
730 | #define IFLA_VXLAN_L2MISS 13 | |
731 | #define IFLA_VXLAN_L3MISS 14 | |
732 | #define IFLA_VXLAN_PORT 15 | |
733 | #define IFLA_VXLAN_GROUP6 16 | |
734 | #define IFLA_VXLAN_LOCAL6 17 | |
735 | #define __IFLA_VXLAN_MAX 18 | |
736 | ||
737 | #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) | |
738 | #endif | |
739 | ||
740 | #if !HAVE_DECL_IFLA_IPTUN_6RD_RELAY_PREFIXLEN | |
741 | #define IFLA_IPTUN_UNSPEC 0 | |
742 | #define IFLA_IPTUN_LINK 1 | |
743 | #define IFLA_IPTUN_LOCAL 2 | |
744 | #define IFLA_IPTUN_REMOTE 3 | |
745 | #define IFLA_IPTUN_TTL 4 | |
746 | #define IFLA_IPTUN_TOS 5 | |
747 | #define IFLA_IPTUN_ENCAP_LIMIT 6 | |
748 | #define IFLA_IPTUN_FLOWINFO 7 | |
749 | #define IFLA_IPTUN_FLAGS 8 | |
750 | #define IFLA_IPTUN_PROTO 9 | |
751 | #define IFLA_IPTUN_PMTUDISC 10 | |
752 | #define IFLA_IPTUN_6RD_PREFIX 11 | |
753 | #define IFLA_IPTUN_6RD_RELAY_PREFIX 12 | |
754 | #define IFLA_IPTUN_6RD_PREFIXLEN 13 | |
755 | #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14 | |
756 | #define __IFLA_IPTUN_MAX 15 | |
757 | ||
758 | #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1) | |
759 | #endif | |
760 | ||
761 | #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO | |
762 | #define IFLA_BRIDGE_FLAGS 0 | |
763 | #define IFLA_BRIDGE_MODE 1 | |
764 | #define IFLA_BRIDGE_VLAN_INFO 2 | |
765 | #define __IFLA_BRIDGE_MAX 3 | |
766 | ||
767 | #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) | |
768 | #endif | |
5eef597e | 769 | |
f47781d8 MP |
770 | #if !HAVE_DECL_IFLA_BRPORT_UNICAST_FLOOD |
771 | #define IFLA_BRPORT_UNSPEC 0 | |
772 | #define IFLA_BRPORT_STATE 1 | |
773 | #define IFLA_BRPORT_PRIORITY 2 | |
774 | #define IFLA_BRPORT_COST 3 | |
775 | #define IFLA_BRPORT_MODE 4 | |
776 | #define IFLA_BRPORT_GUARD 5 | |
777 | #define IFLA_BRPORT_PROTECT 6 | |
778 | #define IFLA_BRPORT_FAST_LEAVE 7 | |
779 | #define IFLA_BRPORT_LEARNING 8 | |
780 | #define IFLA_BRPORT_UNICAST_FLOOD 9 | |
781 | #define __IFLA_BRPORT_MAX 10 | |
782 | ||
783 | #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) | |
784 | #endif | |
785 | ||
e3bff60a MP |
786 | #if !HAVE_DECL_NDA_IFINDEX |
787 | #define NDA_UNSPEC 0 | |
788 | #define NDA_DST 1 | |
789 | #define NDA_LLADDR 2 | |
790 | #define NDA_CACHEINFO 3 | |
791 | #define NDA_PROBES 4 | |
792 | #define NDA_VLAN 5 | |
793 | #define NDA_PORT 6 | |
794 | #define NDA_VNI 7 | |
795 | #define NDA_IFINDEX 8 | |
796 | #define __NDA_MAX 9 | |
797 | ||
798 | #define NDA_MAX (__NDA_MAX - 1) | |
799 | #endif | |
800 | ||
5eef597e MP |
801 | #ifndef IPV6_UNICAST_IF |
802 | #define IPV6_UNICAST_IF 76 | |
803 | #endif | |
804 | ||
805 | #ifndef IFF_MULTI_QUEUE | |
806 | #define IFF_MULTI_QUEUE 0x100 | |
807 | #endif | |
808 | ||
809 | #ifndef IFF_LOWER_UP | |
810 | #define IFF_LOWER_UP 0x10000 | |
811 | #endif | |
812 | ||
813 | #ifndef IFF_DORMANT | |
814 | #define IFF_DORMANT 0x20000 | |
815 | #endif | |
816 | ||
817 | #ifndef BOND_XMIT_POLICY_ENCAP23 | |
818 | #define BOND_XMIT_POLICY_ENCAP23 3 | |
819 | #endif | |
820 | ||
821 | #ifndef BOND_XMIT_POLICY_ENCAP34 | |
822 | #define BOND_XMIT_POLICY_ENCAP34 4 | |
823 | #endif | |
824 | ||
825 | #ifndef NET_ADDR_RANDOM | |
826 | # define NET_ADDR_RANDOM 1 | |
827 | #endif | |
828 | ||
f47781d8 MP |
829 | #ifndef NET_NAME_UNKNOWN |
830 | # define NET_NAME_UNKNOWN 0 | |
831 | #endif | |
832 | ||
5eef597e MP |
833 | #ifndef NET_NAME_ENUM |
834 | # define NET_NAME_ENUM 1 | |
835 | #endif | |
836 | ||
837 | #ifndef NET_NAME_PREDICTABLE | |
838 | # define NET_NAME_PREDICTABLE 2 | |
839 | #endif | |
840 | ||
841 | #ifndef NET_NAME_USER | |
842 | # define NET_NAME_USER 3 | |
843 | #endif | |
844 | ||
845 | #ifndef NET_NAME_RENAMED | |
846 | # define NET_NAME_RENAMED 4 | |
847 | #endif | |
848 | ||
849 | #ifndef BPF_XOR | |
850 | # define BPF_XOR 0xa0 | |
851 | #endif | |
852 | ||
853 | /* Note that LOOPBACK_IFINDEX is currently not exported by the | |
854 | * kernel/glibc, but hardcoded internally by the kernel. However, as | |
855 | * it is exported to userspace indirectly via rtnetlink and the | |
856 | * ioctls, and made use of widely we define it here too, in a way that | |
857 | * is compatible with the kernel's internal definition. */ | |
858 | #ifndef LOOPBACK_IFINDEX | |
859 | #define LOOPBACK_IFINDEX 1 | |
860 | #endif | |
f47781d8 | 861 | |
e3bff60a MP |
862 | #if !HAVE_DECL_IFA_FLAGS |
863 | #define IFA_FLAGS 8 | |
864 | #endif | |
865 | ||
866 | #ifndef IFA_F_NOPREFIXROUTE | |
867 | #define IFA_F_NOPREFIXROUTE 0x200 | |
868 | #endif | |
869 | ||
f47781d8 MP |
870 | #ifndef MAX_AUDIT_MESSAGE_LENGTH |
871 | #define MAX_AUDIT_MESSAGE_LENGTH 8970 | |
872 | #endif | |
873 | ||
874 | #ifndef AUDIT_NLGRP_MAX | |
875 | #define AUDIT_NLGRP_READLOG 1 | |
876 | #endif | |
877 | ||
878 | #ifndef CAP_MAC_OVERRIDE | |
879 | #define CAP_MAC_OVERRIDE 32 | |
880 | #endif | |
881 | ||
882 | #ifndef CAP_MAC_ADMIN | |
883 | #define CAP_MAC_ADMIN 33 | |
884 | #endif | |
885 | ||
886 | #ifndef CAP_SYSLOG | |
887 | #define CAP_SYSLOG 34 | |
888 | #endif | |
889 | ||
890 | #ifndef CAP_WAKE_ALARM | |
891 | #define CAP_WAKE_ALARM 35 | |
892 | #endif | |
893 | ||
894 | #ifndef CAP_BLOCK_SUSPEND | |
895 | #define CAP_BLOCK_SUSPEND 36 | |
896 | #endif | |
897 | ||
898 | #ifndef CAP_AUDIT_READ | |
899 | #define CAP_AUDIT_READ 37 | |
900 | #endif | |
e735f4d4 MP |
901 | |
902 | static inline int raw_clone(unsigned long flags, void *child_stack) { | |
903 | #if defined(__s390__) || defined(__CRIS__) | |
904 | /* On s390 and cris the order of the first and second arguments | |
905 | * of the raw clone() system call is reversed. */ | |
906 | return (int) syscall(__NR_clone, child_stack, flags); | |
907 | #else | |
908 | return (int) syscall(__NR_clone, flags, child_stack); | |
909 | #endif | |
910 | } | |
911 | ||
912 | static inline pid_t raw_getpid(void) { | |
913 | return (pid_t) syscall(__NR_getpid); | |
914 | } | |
915 | ||
916 | #if !HAVE_DECL_RENAMEAT2 | |
917 | ||
918 | #ifndef __NR_renameat2 | |
919 | # if defined __x86_64__ | |
920 | # define __NR_renameat2 316 | |
921 | # elif defined __arm__ | |
922 | # define __NR_renameat2 382 | |
923 | # elif defined _MIPS_SIM | |
924 | # if _MIPS_SIM == _MIPS_SIM_ABI32 | |
925 | # define __NR_renameat2 4351 | |
926 | # endif | |
927 | # if _MIPS_SIM == _MIPS_SIM_NABI32 | |
928 | # define __NR_renameat2 6315 | |
929 | # endif | |
930 | # if _MIPS_SIM == _MIPS_SIM_ABI64 | |
931 | # define __NR_renameat2 5311 | |
932 | # endif | |
933 | # elif defined __i386__ | |
934 | # define __NR_renameat2 353 | |
935 | # else | |
936 | # warning "__NR_renameat2 unknown for your architecture" | |
937 | # define __NR_renameat2 0xffffffff | |
938 | # endif | |
939 | #endif | |
940 | ||
941 | static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) { | |
942 | return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags); | |
943 | } | |
944 | #endif | |
945 | ||
946 | #ifndef RENAME_NOREPLACE | |
947 | #define RENAME_NOREPLACE (1 << 0) | |
948 | #endif | |
949 | ||
950 | #if !HAVE_DECL_KCMP | |
951 | static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) { | |
952 | return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); | |
953 | } | |
954 | #endif | |
955 | ||
956 | #ifndef KCMP_FILE | |
957 | #define KCMP_FILE 0 | |
958 | #endif | |
e3bff60a MP |
959 | |
960 | #ifndef INPUT_PROP_POINTING_STICK | |
961 | #define INPUT_PROP_POINTING_STICK 0x05 | |
962 | #endif | |
963 | ||
964 | #ifndef INPUT_PROP_ACCELEROMETER | |
965 | #define INPUT_PROP_ACCELEROMETER 0x06 | |
966 | #endif |