]>
Commit | Line | Data |
---|---|---|
b0d623f7 | 1 | .\" |
6d2010ae | 2 | .\" Copyright (c) 2011 Apple Inc. All rights reserved. |
b0d623f7 A |
3 | .\" |
4 | .\" @APPLE_LICENSE_HEADER_START@ | |
5 | .\" | |
6 | .\" This file contains Original Code and/or Modifications of Original Code | |
7 | .\" as defined in and that are subject to the Apple Public Source License | |
8 | .\" Version 2.0 (the 'License'). You may not use this file except in | |
9 | .\" compliance with the License. Please obtain a copy of the License at | |
10 | .\" http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | .\" file. | |
12 | .\" | |
13 | .\" The Original Code and all software distributed under the License are | |
14 | .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | .\" Please see the License for the specific language governing rights and | |
19 | .\" limitations under the License. | |
20 | .\" | |
21 | .\" @APPLE_LICENSE_HEADER_END@ | |
22 | .\" | |
23 | .\" | |
9bccf70c A |
24 | .\" $NetBSD: fcntl.2,v 1.6 1995/02/27 12:32:29 cgd Exp $ |
25 | .\" | |
26 | .\" Copyright (c) 1983, 1993 | |
27 | .\" The Regents of the University of California. All rights reserved. | |
28 | .\" | |
29 | .\" Redistribution and use in source and binary forms, with or without | |
30 | .\" modification, are permitted provided that the following conditions | |
31 | .\" are met: | |
32 | .\" 1. Redistributions of source code must retain the above copyright | |
33 | .\" notice, this list of conditions and the following disclaimer. | |
34 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
35 | .\" notice, this list of conditions and the following disclaimer in the | |
36 | .\" documentation and/or other materials provided with the distribution. | |
37 | .\" 3. All advertising materials mentioning features or use of this software | |
38 | .\" must display the following acknowledgement: | |
39 | .\" This product includes software developed by the University of | |
40 | .\" California, Berkeley and its contributors. | |
41 | .\" 4. Neither the name of the University nor the names of its contributors | |
42 | .\" may be used to endorse or promote products derived from this software | |
43 | .\" without specific prior written permission. | |
44 | .\" | |
45 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
46 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
47 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
48 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
49 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
50 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
51 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
52 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
53 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
54 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
55 | .\" SUCH DAMAGE. | |
56 | .\" | |
57 | .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 | |
58 | .\" | |
0a7de745 | 59 | .Dd August 8, 2018 |
9bccf70c A |
60 | .Dt FCNTL 2 |
61 | .Os BSD 4.2 | |
62 | .Sh NAME | |
63 | .Nm fcntl | |
64 | .Nd file control | |
65 | .Sh SYNOPSIS | |
66 | .Fd #include <fcntl.h> | |
67 | .Ft int | |
2d21ac55 A |
68 | .Fo fcntl |
69 | .Fa "int fildes" | |
70 | .Fa "int cmd" | |
71 | .Fa "..." | |
72 | .Fc | |
9bccf70c | 73 | .Sh DESCRIPTION |
39037602 | 74 | .Fn fcntl |
9bccf70c A |
75 | provides for control over descriptors. |
76 | The argument | |
2d21ac55 | 77 | .Fa fildes |
9bccf70c A |
78 | is a descriptor to be operated on by |
79 | .Fa cmd | |
80 | as follows: | |
81 | .Bl -tag -width F_WRITEBOOTSTRAPX | |
82 | .It Dv F_DUPFD | |
83 | Return a new descriptor as follows: | |
84 | .Pp | |
85 | .Bl -bullet -compact -offset 4n | |
86 | .It | |
87 | Lowest numbered available descriptor greater than or equal to | |
88 | .Fa arg . | |
89 | .It | |
90 | Same object references as the original descriptor. | |
91 | .It | |
92 | New descriptor shares the same file offset if the object | |
93 | was a file. | |
94 | .It | |
95 | Same access mode (read, write or read/write). | |
96 | .It | |
97 | Same file status flags (i.e., both file descriptors | |
98 | share the same file status flags). | |
99 | .It | |
100 | The close-on-exec flag associated with the new file descriptor | |
6d2010ae | 101 | is cleared so that the descriptor remains open across an |
9bccf70c | 102 | .Xr execv 2 |
6d2010ae | 103 | system call. |
9bccf70c | 104 | .El |
6d2010ae A |
105 | .It Dv F_DUPFD_CLOEXEC |
106 | Like | |
107 | .Dv F_DUPFD , | |
108 | except that the close-on-exec flag associated with the new file descriptor | |
109 | is set. | |
9bccf70c | 110 | .It Dv F_GETFD |
6d2010ae A |
111 | Get the flags associated with the file descriptor |
112 | .Fa fildes , | |
113 | as described below | |
9bccf70c A |
114 | .Fa ( arg |
115 | is ignored). | |
116 | .It Dv F_SETFD | |
6d2010ae A |
117 | Set the file descriptor flags to |
118 | .Fa arg . | |
9bccf70c A |
119 | .It Dv F_GETFL |
120 | Get descriptor status flags, as described below | |
121 | .Fa ( arg | |
122 | is ignored). | |
123 | .It Dv F_SETFL | |
124 | Set descriptor status flags to | |
125 | .Fa arg . | |
126 | .It Dv F_GETOWN | |
127 | Get the process ID or process group | |
128 | currently receiving | |
129 | .Dv SIGIO | |
130 | and | |
131 | .Dv SIGURG | |
132 | signals; process groups are returned | |
133 | as negative values | |
134 | .Fa ( arg | |
135 | is ignored). | |
136 | .It Dv F_SETOWN | |
137 | Set the process or process group | |
138 | to receive | |
139 | .Dv SIGIO | |
140 | and | |
141 | .Dv SIGURG | |
142 | signals; | |
143 | process groups are specified by supplying | |
144 | .Fa arg | |
145 | as negative, otherwise | |
146 | .Fa arg | |
147 | is interpreted as a process ID. | |
2d21ac55 | 148 | .It Dv F_GETPATH |
cb323159 A |
149 | Get the path of the file descriptor |
150 | .It Dv F_GETPATH_NOFIRMLINK | |
151 | Get the non firmlinked path of the file descriptor | |
2d21ac55 A |
152 | .Fa Fildes . |
153 | The argument must be a buffer of size | |
154 | .Sy MAXPATHLEN | |
155 | or greater. | |
9bccf70c | 156 | .It Dv F_PREALLOCATE |
b0d623f7 | 157 | Preallocate file storage space. Note: upon success, |
a39ff7e2 A |
158 | the space that is allocated can be the size requested, |
159 | larger than the size requested, or (if the | |
160 | .Dv F_ALLOCATEALL | |
161 | flag is not provided) smaller than the space requested. | |
813fb2f6 A |
162 | .It Dv F_PUNCHHOLE |
163 | Deallocate a region and replace it with a hole. Subsequent reads of the | |
164 | affected region will return bytes of zeros that are usually not backed by | |
165 | physical blocks. This will not change the actual file size. Holes must be | |
166 | aligned to file system block boundaries. This will fail on | |
167 | file systems that do not support this interface. | |
9bccf70c | 168 | .It Dv F_SETSIZE |
f427ee49 A |
169 | Deprecated. |
170 | In previous releases, this would allow a process with root privileges to | |
171 | truncate a file without zeroing space. | |
172 | For security reasons, this operation is no longer supported and will | |
173 | instead truncate the file in the same manner as | |
174 | .Xr truncate 2 . | |
9bccf70c A |
175 | .It Dv F_RDADVISE |
176 | Issue an advisory read async with no copy to user. | |
177 | .It Dv F_RDAHEAD | |
178 | Turn read ahead off/on. | |
179 | A zero value in | |
180 | .Fa arg | |
181 | disables read ahead. | |
182 | A non-zero value in | |
183 | .Fa arg | |
184 | turns read ahead on. | |
9bccf70c A |
185 | .It Dv F_NOCACHE |
186 | Turns data caching off/on. A non-zero value in | |
187 | .Fa arg | |
188 | turns data caching off. | |
189 | A value of zero in | |
190 | .Fa arg | |
191 | turns data caching on. | |
192 | .It Dv F_LOG2PHYS | |
193 | Get disk device information. | |
5ba3f43e | 194 | Currently this only returns the |
9bccf70c | 195 | disk device address that corresponds |
5ba3f43e A |
196 | to the current file offset. Note that the system |
197 | may return -1 as the disk device address if the file is not | |
198 | backed by physical blocks. This is subject | |
39236c6e | 199 | to change. |
6d2010ae A |
200 | .It Dv F_LOG2PHYS_EXT |
201 | Variant of F_LOG2PHYS that uses the passed in | |
202 | file offset and length. | |
cb323159 A |
203 | .It Dv F_BARRIERFSYNC |
204 | Does the same thing as | |
205 | .Xr fsync 2 | |
206 | then issues a barrier command to the drive | |
207 | .Fa ( arg | |
208 | is ignored). | |
209 | The barrier applies to I/O that have been flushed with | |
210 | .Xr fsync 2 | |
211 | on the same device before. These operations are guaranteed to | |
212 | be persisted before any other I/O that would follow the barrier, | |
213 | although no assumption should be made on what has been persisted | |
214 | or not when this call returns. After the barrier has been issued, | |
215 | operations on other FDs that have been fsync'd before can still be | |
216 | re-ordered by the device, but not after the barrier. This is | |
217 | typically useful to guarantee valid state on disk when ordering is a | |
218 | concern but durability is not. A barrier can be used to order two phases of operations on | |
219 | a set of file descriptors and ensure that no file can possibly get persisted | |
220 | with the effect of the second phase without the effect of the first one. To do so, | |
221 | execute operations of phase one, then | |
222 | .Xr fsync 2 | |
223 | each FD and issue a single barrier. Finally execute operations of phase two. | |
224 | This is currently implemented on HFS and APFS. It requires hardware support, | |
225 | which Apple SSDs are guaranteed to provide. | |
91447636 A |
226 | .It Dv F_FULLFSYNC |
227 | Does the same thing as | |
228 | .Xr fsync 2 | |
229 | then asks the drive to | |
230 | flush all buffered data to | |
231 | the permanent storage device | |
232 | .Fa ( arg | |
233 | is ignored). | |
cb323159 A |
234 | As this drains the entire queue of the device and acts as a |
235 | barrier, data that had been fsync'd on the same device before | |
236 | is guaranteed to be persisted when this call returns. | |
2d21ac55 | 237 | This is currently implemented on HFS, MS-DOS (FAT), |
cb323159 | 238 | Universal Disk Format (UDF) and APFS file systems. |
2d21ac55 A |
239 | The operation may take quite a while to complete. |
240 | Certain FireWire drives have also been known | |
241 | to ignore the request to flush their buffered data. | |
6d2010ae A |
242 | .It Dv F_SETNOSIGPIPE |
243 | Determines whether a | |
244 | .Dv SIGPIPE | |
245 | signal will be generated when a write fails on a pipe or socket for | |
246 | which there is no reader. If | |
247 | .Fa arg | |
248 | is non-zero, | |
249 | .Dv SIGPIPE | |
250 | generation is disabled for descriptor | |
251 | .Fa fildes , | |
252 | while an | |
253 | .Fa arg | |
254 | of zero enables it (the default). | |
255 | .It Dv F_GETNOSIGPIPE | |
256 | Returns whether a | |
257 | .Dv SIGPIPE | |
258 | signal will be generated when a write fails on a pipe or socket | |
259 | for which there is no reader. The semantics of the return value | |
260 | match those of the | |
261 | .Fa arg | |
262 | of | |
263 | .Dv F_SETNOSIGPIPE . | |
264 | .El | |
265 | .Pp | |
266 | The flags for the | |
267 | .Dv F_GETFD | |
268 | and | |
269 | .Dv F_SETFD | |
270 | commands are as follows: | |
271 | .Bl -tag -width FD_CLOEXECX -offset indent | |
272 | .It Dv FD_CLOEXEC | |
273 | Close-on-exec; the given file descriptor will be automatically | |
274 | closed in the successor process image when one of the | |
275 | .Xr execv 2 | |
276 | or | |
277 | .Xr posix_spawn 2 | |
278 | family of system calls is invoked. | |
9bccf70c A |
279 | .El |
280 | .Pp | |
281 | The flags for the | |
282 | .Dv F_GETFL | |
283 | and | |
284 | .Dv F_SETFL | |
285 | commands are as follows: | |
286 | .Bl -tag -width O_NONBLOCKX -offset indent | |
287 | .It Dv O_NONBLOCK | |
288 | Non-blocking I/O; if no data is available to a | |
289 | .Xr read | |
290 | call, or if a | |
291 | .Xr write | |
292 | operation would block, | |
293 | the read or write call returns -1 with the error | |
294 | .Er EAGAIN . | |
295 | .It Dv O_APPEND | |
296 | Force each write to append at the end of file; | |
297 | corresponds to the | |
298 | .Dv O_APPEND | |
299 | flag of | |
300 | .Xr open 2 . | |
301 | .It Dv O_ASYNC | |
302 | Enable the | |
303 | .Dv SIGIO | |
304 | signal to be sent to the process group | |
305 | when I/O is possible, e.g., | |
306 | upon availability of data to be read. | |
307 | .El | |
308 | .Pp | |
309 | Several commands are available for doing advisory file locking; | |
310 | they all operate on the following structure: | |
311 | .ne 7v | |
312 | .Bd -literal | |
313 | struct flock { | |
314 | off_t l_start; /* starting offset */ | |
315 | off_t l_len; /* len = 0 means until end of file */ | |
316 | pid_t l_pid; /* lock owner */ | |
317 | short l_type; /* lock type: read/write, etc. */ | |
318 | short l_whence; /* type of l_start */ | |
319 | }; | |
320 | .Ed | |
321 | .Pp | |
322 | The commands available for advisory record locking are as follows: | |
323 | .Bl -tag -width F_SETLKWX | |
324 | .It Dv F_GETLK | |
325 | Get the first lock that blocks the lock description pointed to by the | |
326 | third argument, | |
327 | .Fa arg , | |
328 | taken as a pointer to a | |
329 | .Fa "struct flock" | |
330 | (see above). | |
331 | The information retrieved overwrites the information passed to | |
332 | .Nm fcntl | |
333 | in the | |
334 | .Fa flock | |
335 | structure. | |
336 | If no lock is found that would prevent this lock from being created, | |
337 | the structure is left unchanged by this function call except for the | |
338 | lock type which is set to | |
339 | .Dv F_UNLCK . | |
340 | .It Dv F_SETLK | |
341 | Set or clear a file segment lock according to the lock description | |
342 | pointed to by the third argument, | |
343 | .Fa arg , | |
344 | taken as a pointer to a | |
345 | .Fa "struct flock" | |
346 | (see above). | |
347 | .Dv F_SETLK | |
348 | is used to establish shared (or read) locks | |
349 | .Dv (F_RDLCK) | |
350 | or exclusive (or write) locks, | |
351 | .Dv (F_WRLCK) , | |
352 | as well as remove either type of lock | |
353 | .Dv (F_UNLCK) . | |
354 | If a shared or exclusive lock cannot be set, | |
355 | .Nm fcntl | |
356 | returns immediately with | |
b0d623f7 | 357 | .Er EAGAIN . |
9bccf70c A |
358 | .It Dv F_SETLKW |
359 | This command is the same as | |
360 | .Dv F_SETLK | |
361 | except that if a shared or exclusive lock is blocked by other locks, | |
362 | the process waits until the request can be satisfied. | |
363 | If a signal that is to be caught is received while | |
364 | .Nm fcntl | |
365 | is waiting for a region, the | |
366 | .Nm fcntl | |
367 | will be interrupted if the signal handler has not specified the | |
368 | .Dv SA_RESTART | |
369 | (see | |
370 | .Xr sigaction 2 ) . | |
371 | .El | |
372 | .Pp | |
373 | When a shared lock has been set on a segment of a file, | |
374 | other processes can set shared locks on that segment | |
375 | or a portion of it. | |
376 | A shared lock prevents any other process from setting an exclusive | |
377 | lock on any portion of the protected area. | |
378 | A request for a shared lock fails if the file descriptor was not | |
379 | opened with read access. | |
380 | .Pp | |
381 | An exclusive lock prevents any other process from setting a shared lock or | |
382 | an exclusive lock on any portion of the protected area. | |
383 | A request for an exclusive lock fails if the file was not | |
384 | opened with write access. | |
385 | .Pp | |
386 | The value of | |
387 | .Fa l_whence | |
388 | is | |
389 | .Dv SEEK_SET , | |
390 | .Dv SEEK_CUR , | |
391 | or | |
392 | .Dv SEEK_END | |
393 | to indicate that the relative offset, | |
394 | .Fa l_start | |
395 | bytes, will be measured from the start of the file, | |
396 | current position, or end of the file, respectively. | |
397 | The value of | |
398 | .Fa l_len | |
399 | is the number of consecutive bytes to be locked. | |
400 | If | |
401 | .Fa l_len | |
402 | is negative, the result is undefined. | |
403 | The | |
404 | .Fa l_pid | |
405 | field is only used with | |
406 | .Dv F_GETLK | |
407 | to return the process ID of the process holding a blocking lock. | |
408 | After a successful | |
409 | .Dv F_GETLK | |
410 | request, the value of | |
411 | .Fa l_whence | |
412 | is | |
413 | .Dv SEEK_SET . | |
414 | .Pp | |
415 | Locks may start and extend beyond the current end of a file, | |
416 | but may not start or extend before the beginning of the file. | |
417 | A lock is set to extend to the largest possible value of the | |
418 | file offset for that file if | |
419 | .Fa l_len | |
420 | is set to zero. If | |
421 | .Fa l_whence | |
422 | and | |
423 | .Fa l_start | |
424 | point to the beginning of the file, and | |
425 | .Fa l_len | |
426 | is zero, the entire file is locked. | |
427 | If an application wishes only to do entire file locking, the | |
428 | .Xr flock 2 | |
429 | system call is much more efficient. | |
430 | .Pp | |
431 | There is at most one type of lock set for each byte in the file. | |
432 | Before a successful return from an | |
433 | .Dv F_SETLK | |
434 | or an | |
435 | .Dv F_SETLKW | |
436 | request when the calling process has previously existing locks | |
437 | on bytes in the region specified by the request, | |
438 | the previous lock type for each byte in the specified | |
439 | region is replaced by the new lock type. | |
440 | As specified above under the descriptions | |
441 | of shared locks and exclusive locks, an | |
442 | .Dv F_SETLK | |
443 | or an | |
444 | .Dv F_SETLKW | |
445 | request fails or blocks respectively when another process has existing | |
446 | locks on bytes in the specified region and the type of any of those | |
447 | locks conflicts with the type specified in the request. | |
448 | .Pp | |
449 | This interface follows the completely stupid semantics of System V and | |
450 | .St -p1003.1-88 | |
451 | that require that all locks associated with a file for a given process are | |
452 | removed when \fIany\fP file descriptor for that file is closed by that process. | |
453 | This semantic means that applications must be aware of any files that | |
454 | a subroutine library may access. | |
455 | For example if an application for updating the password file locks the | |
456 | password file database while making the update, and then calls | |
457 | .Xr getpwname 3 | |
458 | to retrieve a record, | |
459 | the lock will be lost because | |
460 | .Xr getpwname 3 | |
461 | opens, reads, and closes the password database. | |
462 | The database close will release all locks that the process has | |
463 | associated with the database, even if the library routine never | |
464 | requested a lock on the database. | |
465 | Another minor semantic problem with this interface is that | |
466 | locks are not inherited by a child process created using the | |
467 | .Xr fork 2 | |
468 | function. | |
469 | The | |
470 | .Xr flock 2 | |
471 | interface has much more rational last close semantics and | |
472 | allows locks to be inherited by child processes. | |
473 | .Xr Flock 2 | |
474 | is recommended for applications that want to ensure the integrity | |
475 | of their locks when using library routines or wish to pass locks | |
476 | to their children. | |
477 | Note that | |
478 | .Xr flock 2 | |
479 | and | |
480 | .Xr fcntl 2 | |
481 | locks may be safely used concurrently. | |
482 | .Pp | |
483 | All locks associated with a file for a given process are | |
484 | removed when the process terminates. | |
485 | .Pp | |
486 | A potential for deadlock occurs if a process controlling a locked region | |
487 | is put to sleep by attempting to lock the locked region of another process. | |
488 | This implementation detects that sleeping until a locked region is unlocked | |
489 | would cause a deadlock and fails with an | |
490 | .Er EDEADLK | |
491 | error. | |
492 | .Pp | |
493 | The | |
494 | .Dv F_PREALLOCATE | |
495 | command operates on the following structure: | |
496 | .ne 7v | |
497 | .Bd -literal | |
498 | typedef struct fstore { | |
499 | u_int32_t fst_flags; /* IN: flags word */ | |
500 | int fst_posmode; /* IN: indicates offset field */ | |
501 | off_t fst_offset; /* IN: start of the region */ | |
502 | off_t fst_length; /* IN: size of the region */ | |
503 | off_t fst_bytesalloc; /* OUT: number of bytes allocated */ | |
504 | } fstore_t; | |
505 | .Ed | |
506 | .Pp | |
507 | The flags (fst_flags) for the | |
508 | .Dv F_PREALLOCATE | |
509 | command are as follows: | |
510 | .Bl -tag -width F_ALLOCATECONTIGX -offset indent | |
511 | .It Dv F_ALLOCATECONTIG | |
512 | Allocate contiguous space. | |
513 | .It Dv F_ALLOCATEALL | |
514 | Allocate all requested space or no space at all. | |
515 | .El | |
516 | .Pp | |
517 | The position modes (fst_posmode) for the | |
518 | .Dv F_PREALLOCATE | |
519 | command indicate how to use the offset field. | |
520 | The modes are as follows: | |
521 | .Bl -tag -width F_PEOFPOSMODEX -offset indent | |
522 | .It Dv F_PEOFPOSMODE | |
523 | Allocate from the physical end of file. | |
0a7de745 A |
524 | In this case, |
525 | .Fa fst_length | |
526 | indicates the number of newly allocated bytes desired. | |
9bccf70c A |
527 | .It Dv F_VOLPOSMODE |
528 | Allocate from the volume offset. | |
529 | .El | |
530 | .Pp | |
531 | The | |
813fb2f6 A |
532 | .Dv F_PUNCHHOLE |
533 | command operates on the following structure: | |
534 | .ne 7v | |
535 | .Bd -literal | |
536 | typedef struct fpunchhole { | |
537 | u_int32_t fp_flags; /* unused */ | |
538 | u_int32_t reserved; /* (to maintain 8-byte alignment) */ | |
539 | off_t fp_offset; /* IN: start of the region */ | |
540 | off_t fp_length; /* IN: size of the region */ | |
541 | } fpunchhole_t; | |
542 | .Ed | |
543 | .Pp | |
544 | The | |
9bccf70c A |
545 | .Dv F_RDADVISE |
546 | command operates on the following structure | |
547 | which holds information passed from the | |
548 | user to the system: | |
549 | .ne 7v | |
550 | .Bd -literal | |
551 | struct radvisory { | |
552 | off_t ra_offset; /* offset into the file */ | |
553 | int ra_count; /* size of the read */ | |
554 | }; | |
555 | .Ed | |
556 | .Pp | |
557 | The | |
558 | .Dv F_READBOOTSTRAP and F_WRITEBOOTSTRAP | |
559 | commands operate on the following structure. | |
560 | .ne 7v | |
561 | .Bd -literal | |
562 | typedef struct fbootstraptransfer { | |
563 | off_t fbt_offset; /* IN: offset to start read/write */ | |
564 | size_t fbt_length; /* IN: number of bytes to transfer */ | |
565 | void *fbt_buffer; /* IN: buffer to be read/written */ | |
566 | } fbootstraptransfer_t; | |
567 | .Ed | |
568 | .Pp | |
569 | The | |
570 | .Dv F_LOG2PHYS | |
6d2010ae | 571 | command operates on the following structure: |
9bccf70c A |
572 | .ne 7v |
573 | .Bd -literal | |
574 | struct log2phys { | |
6d2010ae A |
575 | u_int32_t l2p_flags; /* unused so far */ |
576 | off_t l2p_contigbytes; /* unused so far */ | |
577 | off_t l2p_devoffset; /* bytes into device */ | |
9bccf70c A |
578 | }; |
579 | .Ed | |
6d2010ae A |
580 | .Pp |
581 | The | |
582 | .Dv F_LOG2PHYS_EXT | |
583 | command operates on the same structure as F_LOG2PHYS but treats it as an in/out: | |
584 | .ne 7v | |
585 | .Bd -literal | |
586 | struct log2phys { | |
587 | u_int32_t l2p_flags; /* unused so far */ | |
588 | off_t l2p_contigbytes; /* IN: number of bytes to be queried; | |
589 | OUT: number of contiguous bytes allocated at this position */ | |
590 | off_t l2p_devoffset; /* IN: bytes into file; | |
591 | OUT: bytes into device */ | |
592 | }; | |
593 | .Ed | |
594 | .Pp | |
595 | If | |
596 | .Fa fildes | |
597 | is a socket, then the | |
598 | .Dv F_SETNOSIGPIPE | |
599 | and | |
600 | .Dv F_GETNOSIGPIPE | |
601 | commands are directly analogous, and fully interoperate with the | |
602 | .Dv SO_NOSIGPIPE | |
603 | option of | |
604 | .Xr setsockopt 2 | |
605 | and | |
606 | .Xr getsockopt 2 | |
607 | respectively. | |
9bccf70c A |
608 | .Sh RETURN VALUES |
609 | Upon successful completion, the value returned depends on | |
610 | .Fa cmd | |
611 | as follows: | |
612 | .Bl -tag -width F_GETOWNX -offset indent | |
613 | .It Dv F_DUPFD | |
614 | A new file descriptor. | |
615 | .It Dv F_GETFD | |
616 | Value of flag (only the low-order bit is defined). | |
617 | .It Dv F_GETFL | |
618 | Value of flags. | |
619 | .It Dv F_GETOWN | |
620 | Value of file descriptor owner. | |
621 | .It other | |
622 | Value other than -1. | |
623 | .El | |
624 | .Pp | |
625 | Otherwise, a value of -1 is returned and | |
626 | .Va errno | |
627 | is set to indicate the error. | |
628 | .Sh ERRORS | |
2d21ac55 A |
629 | The |
630 | .Fn fcntl | |
631 | system call will fail if: | |
9bccf70c | 632 | .Bl -tag -width Er |
2d21ac55 | 633 | .\" ========== |
b0d623f7 | 634 | .It Bq Er EAGAIN |
9bccf70c A |
635 | The argument |
636 | .Fa cmd | |
637 | is | |
638 | .Dv F_SETLK , | |
639 | the type of lock | |
640 | .Fa (l_type) | |
641 | is a shared lock | |
642 | .Dv (F_RDLCK) | |
643 | or exclusive lock | |
644 | .Dv (F_WRLCK) , | |
645 | and the segment of a file to be locked is already | |
646 | exclusive-locked by another process; | |
647 | or the type is an exclusive lock and some portion of the | |
648 | segment of a file to be locked is already shared-locked or | |
649 | exclusive-locked by another process. | |
b0d623f7 | 650 | .It Bq Er EACCESS |
9bccf70c A |
651 | The argument |
652 | .Fa cmd | |
653 | is either | |
654 | .Dv F_SETSIZE | |
655 | or | |
656 | .Dv F_WRITEBOOTSTRAP | |
657 | and the calling process does not have root privileges. | |
2d21ac55 | 658 | .\" ========== |
9bccf70c A |
659 | .It Bq Er EBADF |
660 | .Fa Fildes | |
661 | is not a valid open file descriptor. | |
662 | .Pp | |
663 | The argument | |
664 | .Fa cmd | |
665 | is | |
666 | .Dv F_SETLK | |
667 | or | |
668 | .Dv F_SETLKW , | |
669 | the type of lock | |
670 | .Fa (l_type) | |
671 | is a shared lock | |
672 | .Dv (F_RDLCK) , | |
673 | and | |
674 | .Fa fildes | |
675 | is not a valid file descriptor open for reading. | |
676 | .Pp | |
677 | The argument | |
678 | .Fa cmd | |
679 | is | |
680 | .Dv F_SETLK | |
681 | or | |
682 | .Dv F_SETLKW , | |
683 | the type of lock | |
684 | .Fa (l_type) | |
685 | is an exclusive lock | |
686 | .Dv (F_WRLCK) , | |
687 | and | |
688 | .Fa fildes | |
689 | is not a valid file descriptor open for writing. | |
690 | .Pp | |
691 | The argument | |
692 | .Fa cmd | |
693 | is | |
694 | .Dv F_PREALLOCATE | |
695 | and the calling process does not have | |
696 | file write permission. | |
697 | .Pp | |
698 | The argument | |
699 | .Fa cmd | |
700 | is | |
701 | .Dv F_LOG2PHYS | |
6d2010ae A |
702 | or |
703 | .Dv F_LOG2PHYS_EXT | |
9bccf70c A |
704 | and |
705 | .Fa fildes | |
706 | is not a valid file descriptor open for reading. | |
2d21ac55 | 707 | .\" ========== |
9bccf70c A |
708 | .It Bq Er EDEADLK |
709 | The argument | |
710 | .Fa cmd | |
711 | is | |
712 | .Dv F_SETLKW , | |
713 | and a deadlock condition was detected. | |
2d21ac55 | 714 | .\" ========== |
9bccf70c A |
715 | .It Bq Er EINTR |
716 | The argument | |
717 | .Fa cmd | |
718 | is | |
719 | .Dv F_SETLKW , | |
720 | and the function was interrupted by a signal. | |
2d21ac55 | 721 | .\" ========== |
9bccf70c A |
722 | .It Bq Er EINVAL |
723 | .Fa Cmd | |
724 | is | |
725 | .Dv F_DUPFD | |
726 | and | |
727 | .Fa arg | |
728 | is negative or greater than the maximum allowable number | |
729 | (see | |
730 | .Xr getdtablesize 2 ) . | |
731 | .Pp | |
732 | The argument | |
733 | .Fa cmd | |
734 | is | |
735 | .Dv F_GETLK , | |
736 | .Dv F_SETLK , | |
737 | or | |
738 | .Dv F_SETLKW | |
739 | and the data to which | |
740 | .Fa arg | |
741 | points is not valid, or | |
742 | .Fa fildes | |
743 | refers to a file that does not support locking. | |
744 | .Pp | |
745 | The argument | |
746 | .Fa cmd | |
747 | is | |
748 | .Dv F_PREALLOCATE | |
749 | and the | |
750 | .Fa fst_posmode | |
751 | is not a valid mode, | |
752 | or when | |
753 | .Dv F_PEOFPOSMODE | |
754 | is set and | |
755 | .Fa fst_offset | |
756 | is a non-zero value, | |
757 | or when | |
758 | .Dv F_VOLPOSMODE | |
759 | is set and | |
760 | .Fa fst_offset | |
761 | is a negative or zero value. | |
762 | .Pp | |
763 | The argument | |
764 | .Fa cmd | |
813fb2f6 A |
765 | is |
766 | .Dv F_PUNCHHOLE | |
767 | and | |
768 | either | |
769 | .Fa fp_offset | |
770 | or | |
771 | .Fa fp_length | |
772 | are negative, or both | |
773 | .Fa fp_offset | |
774 | and | |
775 | .Fa fp_length | |
776 | are not multiples of the file system block size. | |
777 | .Pp | |
778 | The argument | |
779 | .Fa cmd | |
9bccf70c A |
780 | is either |
781 | .Dv F_READBOOTSTRAP | |
782 | or | |
783 | .Dv F_WRITEBOOTSTRAP | |
784 | and the operation was attempted on a non-HFS disk type. | |
2d21ac55 A |
785 | .\" ========== |
786 | .It Bq Er EMFILE | |
787 | .Fa Cmd | |
788 | is | |
789 | .Dv F_DUPFD | |
790 | and the maximum allowed number of file descriptors are currently | |
791 | open. | |
792 | .\" ========== | |
9bccf70c A |
793 | .It Bq Er EMFILE |
794 | The argument | |
795 | .Fa cmd | |
796 | is | |
797 | .Dv F_DUPED | |
798 | and the maximum number of file descriptors permitted for the | |
799 | process are already in use, | |
800 | or no file descriptors greater than or equal to | |
801 | .Fa arg | |
802 | are available. | |
2d21ac55 | 803 | .\" ========== |
9bccf70c A |
804 | .It Bq Er ENOLCK |
805 | The argument | |
806 | .Fa cmd | |
807 | is | |
808 | .Dv F_SETLK | |
809 | or | |
810 | .Dv F_SETLKW , | |
811 | and satisfying the lock or unlock request would result in the | |
812 | number of locked regions in the system exceeding a system-imposed limit. | |
2d21ac55 | 813 | .\" ========== |
a39ff7e2 A |
814 | .It Bq Er ENOSPC |
815 | The argument | |
816 | .Fa cmd | |
817 | is | |
818 | .Dv F_PREALLOCATE | |
819 | and either there is no space available on the volume containing | |
820 | .Fa fildes | |
821 | or | |
822 | .Fa fst_flags | |
823 | contains | |
824 | .Dv F_ALLOCATEALL | |
825 | and there is not enough space available on the volume containing | |
826 | .Fa fildes | |
827 | to satisfy the entire request. | |
828 | .Pp | |
829 | The argument | |
830 | .Fa cmd | |
831 | is | |
832 | .Dv F_PUNCHHOLE | |
833 | and there is not enough space available on the volume containing | |
834 | .Fa fildes | |
835 | to satisfy the request. As an example, a filesystem that supports | |
836 | cloned files may return this error if punching a hole requires the | |
837 | creation of a clone and there is not enough space available to do so. | |
838 | .\" ========== | |
2d21ac55 A |
839 | .It Bq Er EOVERFLOW |
840 | A return value would overflow its representation. | |
841 | For example, | |
842 | .Fa cmd | |
843 | is F_GETLK, F_SETLK, or F_SETLKW | |
844 | and the smallest (or, if l_len is non-zero, the largest) offset | |
845 | of a byte in the requested segment | |
846 | will not fit in an object of type off_t. | |
847 | .\" ========== | |
a39ff7e2 A |
848 | .It Bq Er EPERM |
849 | The argument cmd is | |
850 | .Dv F_PUNCHHOLE | |
851 | and the calling process does not have file write permission. | |
852 | .\" ========== | |
9bccf70c A |
853 | .It Bq Er ESRCH |
854 | .Fa Cmd | |
855 | is | |
856 | .Dv F_SETOWN | |
857 | and | |
858 | the process ID given as argument is not in use. | |
859 | .El | |
860 | .Sh SEE ALSO | |
861 | .Xr close 2 , | |
862 | .Xr execve 2 , | |
863 | .Xr flock 2 , | |
864 | .Xr getdtablesize 2 , | |
865 | .Xr open 2 , | |
6d2010ae A |
866 | .Xr pipe 2 , |
867 | .Xr socket 2 , | |
868 | .Xr setsockopt 2 , | |
9bccf70c A |
869 | .Xr sigaction 3 |
870 | .Sh HISTORY | |
871 | The | |
872 | .Fn fcntl | |
873 | function call appeared in | |
874 | .Bx 4.2 . |