1
2
3
4
5
6
7#ifndef __RESOLVEAT_H__
8#define __RESOLVEAT_H__
9
10#define _GNU_SOURCE
11#include <stdint.h>
12#include <errno.h>
13#include <linux/types.h>
14#include "../kselftest.h"
15
16#define ARRAY_LEN(X) (sizeof (X) / sizeof (*(X)))
17#define BUILD_BUG_ON(e) ((void)(sizeof(struct { int:(-!!(e)); })))
18
19#ifndef SYS_openat2
20#ifndef __NR_openat2
21#define __NR_openat2 437
22#endif
23#define SYS_openat2 __NR_openat2
24#endif
25
26
27
28
29
30
31
32
33
34
35
36
37
38struct open_how {
39 __u64 flags;
40 __u64 mode;
41 __u64 resolve;
42};
43
44#define OPEN_HOW_SIZE_VER0 24
45#define OPEN_HOW_SIZE_LATEST OPEN_HOW_SIZE_VER0
46
47bool needs_openat2(const struct open_how *how);
48
49#ifndef RESOLVE_IN_ROOT
50
51#define RESOLVE_NO_XDEV 0x01
52
53#define RESOLVE_NO_MAGICLINKS 0x02
54
55#define RESOLVE_NO_SYMLINKS 0x04
56
57#define RESOLVE_BENEATH 0x08
58
59
60#define RESOLVE_IN_ROOT 0x10
61
62
63#endif
64
65#define E_func(func, ...) \
66 do { \
67 if (func(__VA_ARGS__) < 0) \
68 ksft_exit_fail_msg("%s:%d %s failed\n", \
69 __FILE__, __LINE__, #func);\
70 } while (0)
71
72#define E_asprintf(...) E_func(asprintf, __VA_ARGS__)
73#define E_chmod(...) E_func(chmod, __VA_ARGS__)
74#define E_dup2(...) E_func(dup2, __VA_ARGS__)
75#define E_fchdir(...) E_func(fchdir, __VA_ARGS__)
76#define E_fstatat(...) E_func(fstatat, __VA_ARGS__)
77#define E_kill(...) E_func(kill, __VA_ARGS__)
78#define E_mkdirat(...) E_func(mkdirat, __VA_ARGS__)
79#define E_mount(...) E_func(mount, __VA_ARGS__)
80#define E_prctl(...) E_func(prctl, __VA_ARGS__)
81#define E_readlink(...) E_func(readlink, __VA_ARGS__)
82#define E_setresuid(...) E_func(setresuid, __VA_ARGS__)
83#define E_symlinkat(...) E_func(symlinkat, __VA_ARGS__)
84#define E_touchat(...) E_func(touchat, __VA_ARGS__)
85#define E_unshare(...) E_func(unshare, __VA_ARGS__)
86
87#define E_assert(expr, msg, ...) \
88 do { \
89 if (!(expr)) \
90 ksft_exit_fail_msg("ASSERT(%s:%d) failed (%s): " msg "\n", \
91 __FILE__, __LINE__, #expr, ##__VA_ARGS__); \
92 } while (0)
93
94int raw_openat2(int dfd, const char *path, void *how, size_t size);
95int sys_openat2(int dfd, const char *path, struct open_how *how);
96int sys_openat(int dfd, const char *path, struct open_how *how);
97int sys_renameat2(int olddirfd, const char *oldpath,
98 int newdirfd, const char *newpath, unsigned int flags);
99
100int touchat(int dfd, const char *path);
101char *fdreadlink(int fd);
102bool fdequal(int fd, int dfd, const char *path);
103
104extern bool openat2_supported;
105
106#endif
107