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