1openat2(2) System Calls Manual openat2(2)
2
3
4
6 openat2 - open and possibly create a file (extended)
7
9 Standard C library (libc, -lc)
10
12 #include <fcntl.h> /* Definition of O_* and S_* constants */
13 #include <linux/openat2.h> /* Definition of RESOLVE_* constants */
14 #include <sys/syscall.h> /* Definition of SYS_* constants */
15 #include <unistd.h>
16
17 long syscall(SYS_openat2, int dirfd, const char *pathname,
18 struct open_how *how, size_t size);
19
20 Note: glibc provides no wrapper for openat2(), necessitating the use of
21 syscall(2).
22
24 The openat2() system call is an extension of openat(2) and provides a
25 superset of its functionality.
26
27 The openat2() system call opens the file specified by pathname. If the
28 specified file does not exist, it may optionally (if O_CREAT is speci‐
29 fied in how.flags) be created.
30
31 As with openat(2), if pathname is a relative pathname, then it is in‐
32 terpreted relative to the directory referred to by the file descriptor
33 dirfd (or the current working directory of the calling process, if
34 dirfd is the special value AT_FDCWD). If pathname is an absolute path‐
35 name, then dirfd is ignored (unless how.resolve contains RE‐
36 SOLVE_IN_ROOT, in which case pathname is resolved relative to dirfd).
37
38 Rather than taking a single flags argument, an extensible structure
39 (how) is passed to allow for future extensions. The size argument must
40 be specified as sizeof(struct open_how).
41
42 The open_how structure
43 The how argument specifies how pathname should be opened, and acts as a
44 superset of the flags and mode arguments to openat(2). This argument
45 is a pointer to an open_how structure, described in open_how(2type).
46
47 Any future extensions to openat2() will be implemented as new fields
48 appended to the open_how structure, with a zero value in a new field
49 resulting in the kernel behaving as though that extension field was not
50 present. Therefore, the caller must zero-fill this structure on ini‐
51 tialization. (See the "Extensibility" section of the NOTES for more
52 detail on why this is necessary.)
53
54 The fields of the open_how structure are as follows:
55
56 flags This field specifies the file creation and file status flags to
57 use when opening the file. All of the O_* flags defined for
58 openat(2) are valid openat2() flag values.
59
60 Whereas openat(2) ignores unknown bits in its flags argument,
61 openat2() returns an error if unknown or conflicting flags are
62 specified in how.flags.
63
64 mode This field specifies the mode for the new file, with