xref: /aosp_15_r20/external/ltp/include/lapi/fcntl.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2014 Cyril Hrubis <[email protected]>
4  * Copyright (c) Linux Test Project, 2014-2023
5  */
6 
7 #ifndef LAPI_FCNTL_H__
8 #define LAPI_FCNTL_H__
9 
10 #include "config.h"
11 #include <fcntl.h>
12 #include <sys/socket.h>
13 
14 /* NOTE: #define _GNU_SOURCE if you need O_DIRECT in tests */
15 
16 #ifndef O_CLOEXEC
17 # define O_CLOEXEC 02000000
18 #endif
19 
20 #ifndef SOCK_CLOEXEC
21 # define SOCK_CLOEXEC O_CLOEXEC
22 #endif
23 
24 #ifndef SOCK_NONBLOCK
25 # define SOCK_NONBLOCK O_NONBLOCK
26 #endif
27 
28 #ifndef O_TMPFILE
29 # define O_TMPFILE (020000000 | O_DIRECTORY)
30 #endif
31 
32 #ifndef F_DUPFD_CLOEXEC
33 # define F_DUPFD_CLOEXEC 1030
34 #endif
35 
36 #ifndef F_SETPIPE_SZ
37 # define F_SETPIPE_SZ 1031
38 #endif
39 
40 #ifndef F_GETPIPE_SZ
41 # define F_GETPIPE_SZ 1032
42 #endif
43 
44 /*
45  * Set/Get seals
46  */
47 #ifndef F_ADD_SEALS
48 # define F_ADD_SEALS     (1033)
49 #endif
50 
51 #ifndef F_GET_SEALS
52 # define F_GET_SEALS     (1034)
53 #endif
54 
55 #ifndef F_SEAL_SEAL
56 # define F_SEAL_SEAL     0x0001  /* prevent further seals from being set */
57 #endif
58 
59 #ifndef F_SEAL_SHRINK
60 # define F_SEAL_SHRINK   0x0002  /* prevent file from shrinking */
61 #endif
62 #ifndef F_SEAL_GROW
63 # define F_SEAL_GROW     0x0004  /* prevent file from growing */
64 #endif
65 #ifndef F_SEAL_WRITE
66 # define F_SEAL_WRITE    0x0008  /* prevent writes */
67 #endif
68 
69 #ifndef F_OWNER_PGRP
70 # define F_OWNER_PGRP 2
71 #endif
72 
73 #ifndef F_OFD_GETLK
74 # define F_OFD_GETLK	36
75 #endif
76 
77 #ifndef F_OFD_SETLK
78 # define F_OFD_SETLK	37
79 #endif
80 
81 #ifndef F_OFD_SETLKW
82 # define F_OFD_SETLKW	38
83 #endif
84 
85 #ifndef AT_FDCWD
86 # define AT_FDCWD -100
87 #endif
88 
89 #ifndef AT_SYMLINK_NOFOLLOW
90 # define AT_SYMLINK_NOFOLLOW	0x100
91 #endif
92 
93 #ifndef AT_REMOVEDIR
94 # define AT_REMOVEDIR		0x200
95 #endif
96 
97 #ifndef AT_HANDLE_FID
98 # define AT_HANDLE_FID		AT_REMOVEDIR
99 #endif
100 
101 #ifndef AT_SYMLINK_FOLLOW
102 # define AT_SYMLINK_FOLLOW	0x400
103 #endif
104 
105 #ifndef AT_NO_AUTOMOUNT
106 # define AT_NO_AUTOMOUNT	0x800
107 #endif
108 
109 #ifndef AT_EMPTY_PATH
110 # define AT_EMPTY_PATH		0x1000
111 #endif
112 
113 #ifndef AT_STATX_SYNC_AS_STAT
114 # define AT_STATX_SYNC_AS_STAT	0x0000
115 #endif
116 
117 #ifndef AT_STATX_FORCE_SYNC
118 # define AT_STATX_FORCE_SYNC	0x2000
119 #endif
120 
121 #ifndef AT_STATX_DONT_SYNC
122 # define AT_STATX_DONT_SYNC	0x4000
123 #endif
124 
125 #ifndef AT_STATX_SYNC_TYPE
126 # define AT_STATX_SYNC_TYPE	0x6000
127 #endif
128 
129 #ifndef O_NOATIME
130 # define O_NOATIME 01000000
131 #endif
132 
133 #ifndef O_PATH
134 # ifdef __sparc__
135 #  define O_PATH 0x1000000
136 # else
137 #  define O_PATH 010000000
138 # endif
139 #endif
140 
141 #ifndef FALLOC_FL_KEEP_SIZE
142 # define FALLOC_FL_KEEP_SIZE 1
143 #endif
144 
145 #ifndef RENAME_NOREPLACE
146 # define RENAME_NOREPLACE	(1 << 0)
147 #endif
148 
149 #ifndef RENAME_EXCHANGE
150 # define RENAME_EXCHANGE		(1 << 1)
151 #endif
152 
153 #ifndef RENAME_WHITEOUT
154 # define RENAME_WHITEOUT		(1 << 2)
155 #endif
156 
157 /* splice, vmsplice, tee */
158 
159 #ifndef SPLICE_F_NONBLOCK
160 # define SPLICE_F_NONBLOCK 2
161 #endif
162 
163 #ifndef MAX_HANDLE_SZ
164 # define MAX_HANDLE_SZ	128
165 #endif
166 
167 #define TST_OPEN_NEEDS_MODE(oflag) \
168 	(((oflag) & O_CREAT) != 0 || ((oflag) & O_TMPFILE) == O_TMPFILE)
169 
170 #ifndef HAVE_STRUCT_FILE_HANDLE
171 struct file_handle {
172 	unsigned int handle_bytes;
173 	int handle_type;
174 	/* File identifier.  */
175 	unsigned char f_handle[0];
176 };
177 #endif /* HAVE_STRUCT_FILE_HANDLE */
178 
179 #endif /* LAPI_FCNTL_H__ */
180