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