~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/openat2/helpers.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Author: Aleksa Sarai <cyphar@cyphar.com>
  4  * Copyright (C) 2018-2019 SUSE LLC.
  5  */
  6 
  7 #ifndef __RESOLVEAT_H__
  8 #define __RESOLVEAT_H__
  9 
 10 #define _GNU_SOURCE
 11 #include <stdint.h>
 12 #include <stdbool.h>
 13 #include <errno.h>
 14 #include <linux/types.h>
 15 #include "../kselftest.h"
 16 
 17 #define ARRAY_LEN(X) (sizeof (X) / sizeof (*(X)))
 18 #define BUILD_BUG_ON(e) ((void)(sizeof(struct { int:(-!!(e)); })))
 19 
 20 #ifndef SYS_openat2
 21 #ifndef __NR_openat2
 22 #define __NR_openat2 437
 23 #endif /* __NR_openat2 */
 24 #define SYS_openat2 __NR_openat2
 25 #endif /* SYS_openat2 */
 26 
 27 /*
 28  * Arguments for how openat2(2) should open the target path. If @resolve is
 29  * zero, then openat2(2) operates very similarly to openat(2).
 30  *
 31  * However, unlike openat(2), unknown bits in @flags result in -EINVAL rather
 32  * than being silently ignored. @mode must be zero unless one of {O_CREAT,
 33  * O_TMPFILE} are set.
 34  *
 35  * @flags: O_* flags.
 36  * @mode: O_CREAT/O_TMPFILE file mode.
 37  * @resolve: RESOLVE_* flags.
 38  */
 39 struct open_how {
 40         __u64 flags;
 41         __u64 mode;
 42         __u64 resolve;
 43 };
 44 
 45 #define OPEN_HOW_SIZE_VER0      24 /* sizeof first published struct */
 46 #define OPEN_HOW_SIZE_LATEST    OPEN_HOW_SIZE_VER0
 47 
 48 bool needs_openat2(const struct open_how *how);
 49 
 50 #ifndef RESOLVE_IN_ROOT
 51 /* how->resolve flags for openat2(2). */
 52 #define RESOLVE_NO_XDEV         0x01 /* Block mount-point crossings
 53                                         (includes bind-mounts). */
 54 #define RESOLVE_NO_MAGICLINKS   0x02 /* Block traversal through procfs-style
 55                                         "magic-links". */
 56 #define RESOLVE_NO_SYMLINKS     0x04 /* Block traversal through all symlinks
 57                                         (implies OEXT_NO_MAGICLINKS) */
 58 #define RESOLVE_BENEATH         0x08 /* Block "lexical" trickery like
 59                                         "..", symlinks, and absolute
 60                                         paths which escape the dirfd. */
 61 #define RESOLVE_IN_ROOT         0x10 /* Make all jumps to "/" and ".."
 62                                         be scoped inside the dirfd
 63                                         (similar to chroot(2)). */
 64 #endif /* RESOLVE_IN_ROOT */
 65 
 66 #define E_func(func, ...)                                                     \
 67         do {                                                                  \
 68                 errno = 0;                                                    \
 69                 if (func(__VA_ARGS__) < 0)                                    \
 70                         ksft_exit_fail_msg("%s:%d %s failed - errno:%d\n",    \
 71                                            __FILE__, __LINE__, #func, errno); \
 72         } while (0)
 73 
 74 #define E_asprintf(...)         E_func(asprintf,        __VA_ARGS__)
 75 #define E_chmod(...)            E_func(chmod,           __VA_ARGS__)
 76 #define E_dup2(...)             E_func(dup2,            __VA_ARGS__)
 77 #define E_fchdir(...)           E_func(fchdir,          __VA_ARGS__)
 78 #define E_fstatat(...)          E_func(fstatat,         __VA_ARGS__)
 79 #define E_kill(...)             E_func(kill,            __VA_ARGS__)
 80 #define E_mkdirat(...)          E_func(mkdirat,         __VA_ARGS__)
 81 #define E_mount(...)            E_func(mount,           __VA_ARGS__)
 82 #define E_prctl(...)            E_func(prctl,           __VA_ARGS__)
 83 #define E_readlink(...)         E_func(readlink,        __VA_ARGS__)
 84 #define E_setresuid(...)        E_func(setresuid,       __VA_ARGS__)
 85 #define E_symlinkat(...)        E_func(symlinkat,       __VA_ARGS__)
 86 #define E_touchat(...)          E_func(touchat,         __VA_ARGS__)
 87 #define E_unshare(...)          E_func(unshare,         __VA_ARGS__)
 88 
 89 #define E_assert(expr, msg, ...)                                        \
 90         do {                                                            \
 91                 if (!(expr))                                            \
 92                         ksft_exit_fail_msg("ASSERT(%s:%d) failed (%s): " msg "\n", \
 93                                            __FILE__, __LINE__, #expr, ##__VA_ARGS__); \
 94         } while (0)
 95 
 96 int raw_openat2(int dfd, const char *path, void *how, size_t size);
 97 int sys_openat2(int dfd, const char *path, struct open_how *how);
 98 int sys_openat(int dfd, const char *path, struct open_how *how);
 99 int sys_renameat2(int olddirfd, const char *oldpath,
100                   int newdirfd, const char *newpath, unsigned int flags);
101 
102 int touchat(int dfd, const char *path);
103 char *fdreadlink(int fd);
104 bool fdequal(int fd, int dfd, const char *path);
105 
106 extern bool openat2_supported;
107 
108 #endif /* __RESOLVEAT_H__ */
109 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php