Print this page
3665 Implement O_CLOEXEC as an open() flag
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/fcntl.h
+++ new/usr/src/uts/common/sys/fcntl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 /*
30 30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 31 * The Regents of the University of California
32 32 * All Rights Reserved
33 33 *
34 34 * University Acknowledgment- Portions of this document are derived from
35 35 * software developed by the University of California, Berkeley, and its
36 36 * contributors.
37 37 */
38 38
39 +/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
40 +
39 41 #ifndef _SYS_FCNTL_H
40 42 #define _SYS_FCNTL_H
41 43
42 44 #include <sys/feature_tests.h>
43 45
44 46 #include <sys/types.h>
45 47
46 48 #ifdef __cplusplus
47 49 extern "C" {
48 50 #endif
49 51
50 52 /*
51 53 * Flag values accessible to open(2) and fcntl(2)
52 54 * The first five can only be set (exclusively) by open(2).
53 55 */
54 56 #define O_RDONLY 0
55 57 #define O_WRONLY 1
56 58 #define O_RDWR 2
57 59 #define O_SEARCH 0x200000
58 60 #define O_EXEC 0x400000
59 61 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)
60 62 #define O_NDELAY 0x04 /* non-blocking I/O */
61 63 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) */
62 64 #define O_APPEND 0x08 /* append (writes guaranteed at the end) */
63 65 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
64 66 (_POSIX_C_SOURCE > 2) || defined(_XOPEN_SOURCE)
65 67 #define O_SYNC 0x10 /* synchronized file update option */
66 68 #define O_DSYNC 0x40 /* synchronized data update option */
67 69 #define O_RSYNC 0x8000 /* synchronized file update option */
68 70 /* defines read/write file integrity */
69 71 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
70 72 #define O_NONBLOCK 0x80 /* non-blocking I/O (POSIX) */
71 73 #ifdef _LARGEFILE_SOURCE
72 74 #define O_LARGEFILE 0x2000
73 75 #endif
74 76
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
75 77 /*
76 78 * Flag values accessible only to open(2).
77 79 */
78 80 #define O_CREAT 0x100 /* open with file create (uses third arg) */
79 81 #define O_TRUNC 0x200 /* open with truncation */
80 82 #define O_EXCL 0x400 /* exclusive open */
81 83 #define O_NOCTTY 0x800 /* don't allocate controlling tty (POSIX) */
82 84 #define O_XATTR 0x4000 /* extended attribute */
83 85 #define O_NOFOLLOW 0x20000 /* don't follow symlinks */
84 86 #define O_NOLINKS 0x40000 /* don't allow multiple hard links */
87 +#define O_CLOEXEC 0x800000 /* set the close-on-exec flag */
85 88
86 89 /*
87 90 * fcntl(2) requests
88 91 *
89 92 * N.B.: values are not necessarily assigned sequentially below.
90 93 */
91 94 #define F_DUPFD 0 /* Duplicate fildes */
92 95 #define F_GETFD 1 /* Get fildes flags */
93 96 #define F_SETFD 2 /* Set fildes flags */
94 97 #define F_GETFL 3 /* Get file flags */
95 98 #define F_GETXFL 45 /* Get file flags including open-only flags */
96 99 #define F_SETFL 4 /* Set file flags */
97 100
98 101 /*
99 102 * Applications that read /dev/mem must be built like the kernel. A
100 103 * new symbol "_KMEMUSER" is defined for this purpose.
101 104 */
102 105 #if defined(_KERNEL) || defined(_KMEMUSER)
103 106 #define F_O_GETLK 5 /* SVR3 Get file lock (need for rfs, across */
104 107 /* the wire compatibility */
105 108 /* clustering: lock id contains both per-node sysid and node id */
106 109 #define SYSIDMASK 0x0000ffff
107 110 #define GETSYSID(id) (id & SYSIDMASK)
108 111 #define NODEIDMASK 0xffff0000
109 112 #define BITS_IN_SYSID 16
110 113 #define GETNLMID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \
111 114 BITS_IN_SYSID))
112 115
113 116 /* Clustering: Macro used for PXFS locks */
114 117 #define GETPXFSID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \
115 118 BITS_IN_SYSID))
116 119 #endif /* defined(_KERNEL) */
117 120
118 121 #define F_CHKFL 8 /* Unused */
119 122 #define F_DUP2FD 9 /* Duplicate fildes at third arg */
120 123
121 124 #define F_ISSTREAM 13 /* Is the file desc. a stream ? */
122 125 #define F_PRIV 15 /* Turn on private access to file */
123 126 #define F_NPRIV 16 /* Turn off private access to file */
124 127 #define F_QUOTACTL 17 /* UFS quota call */
125 128 #define F_BLOCKS 18 /* Get number of BLKSIZE blocks allocated */
126 129 #define F_BLKSIZE 19 /* Get optimal I/O block size */
127 130 /*
128 131 * Numbers 20-22 have been removed and should not be reused.
129 132 */
130 133 #define F_GETOWN 23 /* Get owner (socket emulation) */
131 134 #define F_SETOWN 24 /* Set owner (socket emulation) */
132 135 #define F_REVOKE 25 /* Object reuse revoke access to file desc. */
133 136
134 137 #define F_HASREMOTELOCKS 26 /* Does vp have NFS locks; private to lock */
135 138 /* manager */
136 139
137 140 /*
138 141 * Commands that refer to flock structures. The argument types differ between
139 142 * the large and small file environments; therefore, the #defined values must
140 143 * as well.
141 144 * The NBMAND forms are private and should not be used.
142 145 */
143 146
144 147 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
145 148 /* "Native" application compilation environment */
146 149 #define F_SETLK 6 /* Set file lock */
147 150 #define F_SETLKW 7 /* Set file lock and wait */
148 151 #define F_ALLOCSP 10 /* Allocate file space */
149 152 #define F_FREESP 11 /* Free file space */
150 153 #define F_GETLK 14 /* Get file lock */
151 154 #define F_SETLK_NBMAND 42 /* private */
152 155 #else
153 156 /* ILP32 large file application compilation environment version */
154 157 #define F_SETLK 34 /* Set file lock */
155 158 #define F_SETLKW 35 /* Set file lock and wait */
156 159 #define F_ALLOCSP 28 /* Alllocate file space */
157 160 #define F_FREESP 27 /* Free file space */
158 161 #define F_GETLK 33 /* Get file lock */
159 162 #define F_SETLK_NBMAND 44 /* private */
160 163 #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */
161 164
162 165 #if defined(_LARGEFILE64_SOURCE)
163 166
164 167 #if !defined(_LP64) || defined(_KERNEL)
165 168 /*
166 169 * transitional large file interface version
167 170 * These are only valid in a 32 bit application compiled with large files
168 171 * option, for source compatibility, the 64-bit versions are mapped back
169 172 * to the native versions.
170 173 */
171 174 #define F_SETLK64 34 /* Set file lock */
172 175 #define F_SETLKW64 35 /* Set file lock and wait */
173 176 #define F_ALLOCSP64 28 /* Allocate file space */
174 177 #define F_FREESP64 27 /* Free file space */
175 178 #define F_GETLK64 33 /* Get file lock */
176 179 #define F_SETLK64_NBMAND 44 /* private */
177 180 #else
178 181 #define F_SETLK64 6 /* Set file lock */
179 182 #define F_SETLKW64 7 /* Set file lock and wait */
180 183 #define F_ALLOCSP64 10 /* Allocate file space */
181 184 #define F_FREESP64 11 /* Free file space */
182 185 #define F_GETLK64 14 /* Get file lock */
183 186 #define F_SETLK64_NBMAND 42 /* private */
184 187 #endif /* !_LP64 || _KERNEL */
185 188
186 189 #endif /* _LARGEFILE64_SOURCE */
187 190
188 191 #define F_SHARE 40 /* Set a file share reservation */
189 192 #define F_UNSHARE 41 /* Remove a file share reservation */
190 193 #define F_SHARE_NBMAND 43 /* private */
191 194
192 195 #define F_BADFD 46 /* Create Poison FD */
193 196
194 197 /*
195 198 * File segment locking set data type - information passed to system by user.
196 199 */
197 200
198 201 /* regular version, for both small and large file compilation environment */
199 202 typedef struct flock {
200 203 short l_type;
201 204 short l_whence;
202 205 off_t l_start;
203 206 off_t l_len; /* len == 0 means until end of file */
204 207 int l_sysid;
205 208 pid_t l_pid;
206 209 long l_pad[4]; /* reserve area */
207 210 } flock_t;
208 211
209 212 #if defined(_SYSCALL32)
210 213
211 214 /* Kernel's view of ILP32 flock structure */
212 215
213 216 typedef struct flock32 {
214 217 int16_t l_type;
215 218 int16_t l_whence;
216 219 off32_t l_start;
217 220 off32_t l_len; /* len == 0 means until end of file */
218 221 int32_t l_sysid;
219 222 pid32_t l_pid;
220 223 int32_t l_pad[4]; /* reserve area */
221 224 } flock32_t;
222 225
223 226 #endif /* _SYSCALL32 */
224 227
225 228 /* transitional large file interface version */
226 229
227 230 #if defined(_LARGEFILE64_SOURCE)
228 231
229 232 typedef struct flock64 {
230 233 short l_type;
231 234 short l_whence;
232 235 off64_t l_start;
233 236 off64_t l_len; /* len == 0 means until end of file */
234 237 int l_sysid;
235 238 pid_t l_pid;
236 239 long l_pad[4]; /* reserve area */
237 240 } flock64_t;
238 241
239 242 #if defined(_SYSCALL32)
240 243
241 244 /* Kernel's view of ILP32 flock64 */
242 245
243 246 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
244 247 #pragma pack(4)
245 248 #endif
246 249
247 250 typedef struct flock64_32 {
248 251 int16_t l_type;
249 252 int16_t l_whence;
250 253 off64_t l_start;
251 254 off64_t l_len; /* len == 0 means until end of file */
252 255 int32_t l_sysid;
253 256 pid32_t l_pid;
254 257 int32_t l_pad[4]; /* reserve area */
255 258 } flock64_32_t;
256 259
257 260 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
258 261 #pragma pack()
259 262 #endif
260 263
261 264 /* Kernel's view of LP64 flock64 */
262 265
263 266 typedef struct flock64_64 {
264 267 int16_t l_type;
265 268 int16_t l_whence;
266 269 off64_t l_start;
267 270 off64_t l_len; /* len == 0 means until end of file */
268 271 int32_t l_sysid;
269 272 pid32_t l_pid;
270 273 int64_t l_pad[4]; /* reserve area */
271 274 } flock64_64_t;
272 275
273 276 #endif /* _SYSCALL32 */
274 277
275 278 #endif /* _LARGEFILE64_SOURCE */
276 279
277 280 #if defined(_KERNEL) || defined(_KMEMUSER)
278 281 /* SVr3 flock type; needed for rfs across the wire compatibility */
279 282 typedef struct o_flock {
280 283 int16_t l_type;
281 284 int16_t l_whence;
282 285 int32_t l_start;
283 286 int32_t l_len; /* len == 0 means until end of file */
284 287 int16_t l_sysid;
285 288 int16_t l_pid;
286 289 } o_flock_t;
287 290 #endif /* defined(_KERNEL) */
288 291
289 292 /*
290 293 * File segment locking types.
291 294 */
292 295 #define F_RDLCK 01 /* Read lock */
293 296 #define F_WRLCK 02 /* Write lock */
294 297 #define F_UNLCK 03 /* Remove lock(s) */
295 298 #define F_UNLKSYS 04 /* remove remote locks for a given system */
296 299
297 300 /*
298 301 * POSIX constants
299 302 */
300 303
301 304 /* Mask for file access modes */
302 305 #define O_ACCMODE (O_SEARCH | O_EXEC | 0x3)
303 306 #define FD_CLOEXEC 1 /* close on exec flag */
304 307
305 308 /*
306 309 * DIRECTIO
307 310 */
308 311 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
309 312 #define DIRECTIO_OFF (0)
310 313 #define DIRECTIO_ON (1)
311 314
312 315 /*
313 316 * File share reservation type
314 317 */
315 318 typedef struct fshare {
316 319 short f_access;
317 320 short f_deny;
318 321 int f_id;
319 322 } fshare_t;
320 323
321 324 /*
322 325 * f_access values
323 326 */
324 327 #define F_RDACC 0x1 /* Read-only share access */
325 328 #define F_WRACC 0x2 /* Write-only share access */
326 329 #define F_RWACC 0x3 /* Read-Write share access */
327 330 #define F_RMACC 0x4 /* private flag: Delete share access */
328 331 #define F_MDACC 0x20 /* private flag: Metadata share access */
329 332
330 333 /*
331 334 * f_deny values
332 335 */
333 336 #define F_NODNY 0x0 /* Don't deny others access */
334 337 #define F_RDDNY 0x1 /* Deny others read share access */
335 338 #define F_WRDNY 0x2 /* Deny others write share access */
336 339 #define F_RWDNY 0x3 /* Deny others read or write share access */
337 340 #define F_RMDNY 0x4 /* private flag: Deny delete share access */
338 341 #define F_COMPAT 0x8 /* Set share to old DOS compatibility mode */
339 342 #define F_MANDDNY 0x10 /* private flag: mandatory enforcement */
340 343 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
341 344
342 345 /*
343 346 * Special flags for functions such as openat(), fstatat()....
344 347 */
345 348 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
346 349 defined(__EXTENSIONS__)
347 350 /* || defined(_XPG7) */
348 351 #define AT_FDCWD 0xffd19553
349 352 #define AT_SYMLINK_NOFOLLOW 0x1000
350 353 #define AT_SYMLINK_FOLLOW 0x2000 /* only for linkat() */
351 354 #define AT_REMOVEDIR 0x1
352 355 #define _AT_TRIGGER 0x2
353 356 #define AT_EACCESS 0x4 /* use EUID/EGID for access */
354 357 #endif
355 358
356 359 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
357 360 /* advice for posix_fadvise */
358 361 #define POSIX_FADV_NORMAL 0
359 362 #define POSIX_FADV_RANDOM 1
360 363 #define POSIX_FADV_SEQUENTIAL 2
361 364 #define POSIX_FADV_WILLNEED 3
362 365 #define POSIX_FADV_DONTNEED 4
363 366 #define POSIX_FADV_NOREUSE 5
364 367 #endif
365 368
366 369 #ifdef __cplusplus
367 370 }
368 371 #endif
369 372
370 373 #endif /* _SYS_FCNTL_H */
↓ open down ↓ |
276 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX