0001
0002
0003
0004
0005
0006
0007 #ifndef __RESOLVEAT_H__
0008 #define __RESOLVEAT_H__
0009
0010 #define _GNU_SOURCE
0011 #include <stdint.h>
0012 #include <stdbool.h>
0013 #include <errno.h>
0014 #include <linux/types.h>
0015 #include "../kselftest.h"
0016
0017 #define ARRAY_LEN(X) (sizeof (X) / sizeof (*(X)))
0018 #define BUILD_BUG_ON(e) ((void)(sizeof(struct { int:(-!!(e)); })))
0019
0020 #ifndef SYS_openat2
0021 #ifndef __NR_openat2
0022 #define __NR_openat2 437
0023 #endif
0024 #define SYS_openat2 __NR_openat2
0025 #endif
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 struct open_how {
0040 __u64 flags;
0041 __u64 mode;
0042 __u64 resolve;
0043 };
0044
0045 #define OPEN_HOW_SIZE_VER0 24
0046 #define OPEN_HOW_SIZE_LATEST OPEN_HOW_SIZE_VER0
0047
0048 bool needs_openat2(const struct open_how *how);
0049
0050 #ifndef RESOLVE_IN_ROOT
0051
0052 #define RESOLVE_NO_XDEV 0x01
0053
0054 #define RESOLVE_NO_MAGICLINKS 0x02
0055
0056 #define RESOLVE_NO_SYMLINKS 0x04
0057
0058 #define RESOLVE_BENEATH 0x08
0059
0060
0061 #define RESOLVE_IN_ROOT 0x10
0062
0063
0064 #endif
0065
0066 #define E_func(func, ...) \
0067 do { \
0068 errno = 0; \
0069 if (func(__VA_ARGS__) < 0) \
0070 ksft_exit_fail_msg("%s:%d %s failed - errno:%d\n", \
0071 __FILE__, __LINE__, #func, errno); \
0072 } while (0)
0073
0074 #define E_asprintf(...) E_func(asprintf, __VA_ARGS__)
0075 #define E_chmod(...) E_func(chmod, __VA_ARGS__)
0076 #define E_dup2(...) E_func(dup2, __VA_ARGS__)
0077 #define E_fchdir(...) E_func(fchdir, __VA_ARGS__)
0078 #define E_fstatat(...) E_func(fstatat, __VA_ARGS__)
0079 #define E_kill(...) E_func(kill, __VA_ARGS__)
0080 #define E_mkdirat(...) E_func(mkdirat, __VA_ARGS__)
0081 #define E_mount(...) E_func(mount, __VA_ARGS__)
0082 #define E_prctl(...) E_func(prctl, __VA_ARGS__)
0083 #define E_readlink(...) E_func(readlink, __VA_ARGS__)
0084 #define E_setresuid(...) E_func(setresuid, __VA_ARGS__)
0085 #define E_symlinkat(...) E_func(symlinkat, __VA_ARGS__)
0086 #define E_touchat(...) E_func(touchat, __VA_ARGS__)
0087 #define E_unshare(...) E_func(unshare, __VA_ARGS__)
0088
0089 #define E_assert(expr, msg, ...) \
0090 do { \
0091 if (!(expr)) \
0092 ksft_exit_fail_msg("ASSERT(%s:%d) failed (%s): " msg "\n", \
0093 __FILE__, __LINE__, #expr, ##__VA_ARGS__); \
0094 } while (0)
0095
0096 int raw_openat2(int dfd, const char *path, void *how, size_t size);
0097 int sys_openat2(int dfd, const char *path, struct open_how *how);
0098 int sys_openat(int dfd, const char *path, struct open_how *how);
0099 int sys_renameat2(int olddirfd, const char *oldpath,
0100 int newdirfd, const char *newpath, unsigned int flags);
0101
0102 int touchat(int dfd, const char *path);
0103 char *fdreadlink(int fd);
0104 bool fdequal(int fd, int dfd, const char *path);
0105
0106 extern bool openat2_supported;
0107
0108 #endif