blob: e5e47bdba5eb3c6a0e6a42b71ee3d1bb7b10e033 [file] [log] [blame]
Adam Barth57eacf52020-11-04 00:38:09 +00001#ifndef SYSROOT_FCNTL_H_
2#define SYSROOT_FCNTL_H_
Doug Horn1427b6a2018-12-11 13:19:16 -08003
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <features.h>
9
10#define __NEED_off_t
11#define __NEED_pid_t
12#define __NEED_mode_t
13
14#ifdef _GNU_SOURCE
15#define __NEED_size_t
16#define __NEED_ssize_t
17#define __NEED_struct_iovec
18#endif
19
20#include <bits/alltypes.h>
21
22struct flock {
Adam Barth57eacf52020-11-04 00:38:09 +000023 short l_type;
24 short l_whence;
25 off_t l_start;
26 off_t l_len;
27 pid_t l_pid;
Doug Horn1427b6a2018-12-11 13:19:16 -080028};
29
30int creat(const char*, mode_t);
31int fcntl(int, int, ...);
32int open(const char*, int, ...);
33int openat(int, const char*, int, ...);
34int posix_fadvise(int, off_t, off_t, int);
35int posix_fallocate(int, off_t, off_t);
36
37#define O_SEARCH O_PATH
38#define O_EXEC O_PATH
39
40// clang-format off
41#define O_ACCMODE (03 | O_SEARCH)
42#define O_RDONLY 00
43#define O_WRONLY 01
44#define O_RDWR 02
45
46// Flags which align with ZXIO_FS_*
47// system/ulib/fdio/unistd.c asserts that these flags are aligned
48// with the ZXIO_FS_* versions.
49#define O_CREAT 0x00010000
50#define O_EXCL 0x00020000
51#define O_TRUNC 0x00040000
52#define O_DIRECTORY 0x00080000
53#define O_APPEND 0x00100000
54#define O_PATH 0x00400000
55#ifdef _ALL_SOURCE
56#define O_NOREMOTE 0x00200000
57#define O_ADMIN 0x00000004
Doug Horn1427b6a2018-12-11 13:19:16 -080058#endif
59
60// Flags which do not align with ZXIO_FS_*
61#define O_NONBLOCK 0x00000010
62#define O_DSYNC 0x00000020
63#define O_SYNC (0x00000040 | O_DSYNC)
64#define O_RSYNC O_SYNC
65#define O_NOFOLLOW 0x00000080
66#define O_CLOEXEC 0x00000100
67#define O_NOCTTY 0x00000200
68#define O_ASYNC 0x00000400
69#define O_DIRECT 0x00000800
70#define O_LARGEFILE 0x00001000
71#define O_NOATIME 0x00002000
72#define O_TMPFILE 0x00004000
73
74// clang-format on
75
76#define O_NDELAY O_NONBLOCK
77
78#define F_DUPFD 0
79#define F_GETFD 1
80#define F_SETFD 2
81#define F_GETFL 3
82#define F_SETFL 4
83
84#define F_GETLK 5
85#define F_SETLK 6
86#define F_SETLKW 7
87
88#define F_SETOWN 8
89#define F_GETOWN 9
90#define F_SETSIG 10
91#define F_GETSIG 11
92
93#define F_SETOWN_EX 15
94#define F_GETOWN_EX 16
95
96#define F_GETOWNER_UIDS 17
97
98#define F_OFD_GETLK 36
99#define F_OFD_SETLK 37
100#define F_OFD_SETLKW 38
101
102#define F_DUPFD_CLOEXEC 1030
103
104#define F_RDLCK 0
105#define F_WRLCK 1
106#define F_UNLCK 2
107
108#define FD_CLOEXEC 1
109
110#define AT_FDCWD (-100)
111#define AT_SYMLINK_NOFOLLOW 0x100
112#define AT_REMOVEDIR 0x200
113#define AT_SYMLINK_FOLLOW 0x400
114#define AT_EACCESS 0x200
115
116#define POSIX_FADV_NORMAL 0
117#define POSIX_FADV_RANDOM 1
118#define POSIX_FADV_SEQUENTIAL 2
119#define POSIX_FADV_WILLNEED 3
120#define POSIX_FADV_DONTNEED 4
121#define POSIX_FADV_NOREUSE 5
122
123#undef SEEK_SET
124#undef SEEK_CUR
125#undef SEEK_END
126#define SEEK_SET 0
127#define SEEK_CUR 1
128#define SEEK_END 2
129
130#ifndef S_IRUSR
131#define S_ISUID 04000
132#define S_ISGID 02000
133#define S_ISVTX 01000
134#define S_IRUSR 0400
135#define S_IWUSR 0200
136#define S_IXUSR 0100
137#define S_IRWXU 0700
138#define S_IRGRP 0040
139#define S_IWGRP 0020
140#define S_IXGRP 0010
141#define S_IRWXG 0070
142#define S_IROTH 0004
143#define S_IWOTH 0002
144#define S_IXOTH 0001
145#define S_IRWXO 0007
146#endif
147
148#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
149#define AT_NO_AUTOMOUNT 0x800
150#define AT_EMPTY_PATH 0x1000
151
152#define FAPPEND O_APPEND
153#define FFSYNC O_FSYNC
154#define FASYNC O_ASYNC
155#define FNONBLOCK O_NONBLOCK
156#define FNDELAY O_NDELAY
157
158#define F_OK 0
159#define R_OK 4
160#define W_OK 2
161#define X_OK 1
162#define F_ULOCK 0
163#define F_LOCK 1
164#define F_TLOCK 2
165#define F_TEST 3
166
167#define F_SETLEASE 1024
168#define F_GETLEASE 1025
169#define F_NOTIFY 1026
170#define F_CANCELLK 1029
171#define F_SETPIPE_SZ 1031
172#define F_GETPIPE_SZ 1032
173#define F_ADD_SEALS 1033
174#define F_GET_SEALS 1034
175
176#define F_SEAL_SEAL 0x0001
177#define F_SEAL_SHRINK 0x0002
178#define F_SEAL_GROW 0x0004
179#define F_SEAL_WRITE 0x0008
180
181#define DN_ACCESS 0x00000001
182#define DN_MODIFY 0x00000002
183#define DN_CREATE 0x00000004
184#define DN_DELETE 0x00000008
185#define DN_RENAME 0x00000010
186#define DN_ATTRIB 0x00000020
187#define DN_MULTISHOT 0x80000000
188
189int lockf(int, int, off_t);
190#endif
191
192#if defined(_GNU_SOURCE)
193#define F_OWNER_TID 0
194#define F_OWNER_PID 1
195#define F_OWNER_PGRP 2
196#define F_OWNER_GID 2
197struct f_owner_ex {
Adam Barth57eacf52020-11-04 00:38:09 +0000198 int type;
199 pid_t pid;
Doug Horn1427b6a2018-12-11 13:19:16 -0800200};
201#define FALLOC_FL_KEEP_SIZE 1
202#define FALLOC_FL_PUNCH_HOLE 2
203#define SYNC_FILE_RANGE_WAIT_BEFORE 1
204#define SYNC_FILE_RANGE_WRITE 2
205#define SYNC_FILE_RANGE_WAIT_AFTER 4
206#define SPLICE_F_MOVE 1
207#define SPLICE_F_NONBLOCK 2
208#define SPLICE_F_MORE 4
209#define SPLICE_F_GIFT 8
210int fallocate(int, int, off_t, off_t);
211#define fallocate64 fallocate
212ssize_t readahead(int, off_t, size_t);
213int sync_file_range(int, off_t, off_t, unsigned);
214ssize_t vmsplice(int, const struct iovec*, size_t, unsigned);
215ssize_t splice(int, off_t*, int, off_t*, size_t, unsigned);
216ssize_t tee(int, int, size_t, unsigned);
217#define loff_t off_t
218#endif
219
220#ifdef __cplusplus
221}
222#endif
Adam Barth57eacf52020-11-04 00:38:09 +0000223
224#endif // SYSROOT_FCNTL_H_