]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/lockf.3
getent.1, intro.1, time.1, _exit.2, alloc_hugepages.2, arch_prctl.2, clock_getres...
[thirdparty/man-pages.git] / man3 / lockf.3
CommitLineData
e00c3a07 1.\" Copyright 1997 Nicolás Lichtmaier <nick@debian.org>
fea681da
MK
2.\" Created Thu Aug 7 00:44:00 ART 1997
3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
9.\"
10.\" The GNU General Public License's references to "object code"
11.\" and "executables" are to be interpreted as the output of any
12.\" document formatting or typesetting system, including
13.\" intermediate and printed output.
14.\"
15.\" This manual is distributed in the hope that it will be useful,
16.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.\" GNU General Public License for more details.
19.\"
faede11f
MK
20.\" You should have received a copy of the GNU General Public
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
6a8d8745 23.\" %%%LICENSE_END
faede11f 24.\"
fea681da
MK
25.\" Added section stuff, aeb, 2002-04-22.
26.\" Corrected include file, drepper, 2003-06-15.
27.\"
97986708 28.TH LOCKF 3 2016-03-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
29.SH NAME
30lockf \- apply, test or remove a POSIX lock on an open file
31.SH SYNOPSIS
32.B #include <unistd.h>
68e4db0a 33.PP
ab95e95e 34.BI "int lockf(int " fd ", int " cmd ", off_t " len );
68e4db0a 35.PP
cc4615cc
MK
36.in -4n
37Feature Test Macro Requirements for glibc (see
38.BR feature_test_macros (7)):
39.in
68e4db0a 40.PP
cc4615cc 41.BR lockf ():
c29dc444
MK
42.ad l
43.RS 4
6e0869f7 44_XOPEN_SOURCE\ >=\ 500
cf7fa0a1 45.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
6e0869f7
MK
46 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
47 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
c29dc444
MK
48.RE
49.ad
fea681da
MK
50.SH DESCRIPTION
51Apply, test or remove a POSIX lock on a section of an open file.
52The file is specified by
53.IR fd ,
54a file descriptor open for writing, the action by
55.IR cmd ,
56and the section consists of byte positions
c65433e6 57.IR pos .. pos + len \-1
21cb07dc
MK
58if
59.I len
60is positive, and
c65433e6 61.IR pos \- len .. pos \-1
21cb07dc
MK
62if
63.I len
64is negative, where
fea681da
MK
65.I pos
66is the current file position, and if
67.I len
68is zero, the section extends from the current file position to
69infinity, encompassing the present and future end-of-file positions.
70In all cases, the section may extend past current end-of-file.
dd3568a1 71.PP
73e15b46
MK
72On Linux,
73.BR lockf ()
74is just an interface on top of
75.BR fcntl (2)
76locking.
77Many other systems implement
78.BR lockf ()
f287e294 79in this way, but note that POSIX.1 leaves the relationship between
e511ffb6 80.BR lockf ()
fea681da 81and
fb186734 82.BR fcntl (2)
73e15b46
MK
83locks unspecified.
84A portable application should probably avoid mixing calls
85to these interfaces.
dd3568a1 86.PP
fea681da
MK
87Valid operations are given below:
88.TP
89.B F_LOCK
90Set an exclusive lock on the specified section of the file.
91If (part of) this section is already locked, the call
92blocks until the previous lock is released.
93If this section overlaps an earlier locked section,
94both are merged.
95File locks are released as soon as the process holding the locks
c13182ef
MK
96closes some file descriptor for the file.
97A child process does not inherit these locks.
fea681da
MK
98.TP
99.B F_TLOCK
100Same as
101.B F_LOCK
102but the call never blocks and returns an error instead if the file is
103already locked.
104.TP
105.B F_ULOCK
106Unlock the indicated section of the file.
107This may cause a locked section to be split into two locked sections.
108.TP
109.B F_TEST
110Test the lock: return 0 if the specified section
111is unlocked or locked by this process; return \-1, set
112.I errno
113to
0daa9e92 114.B EAGAIN
0febdb5c
MK
115.RB ( EACCES
116on some other systems),
fea681da 117if another process holds a lock.
47297adb 118.SH RETURN VALUE
c13182ef
MK
119On success, zero is returned.
120On error, \-1 is returned, and
fea681da
MK
121.I errno
122is set appropriately.
123.SH ERRORS
124.TP
0febdb5c 125.BR EACCES " or " EAGAIN
fea681da
MK
126The file is locked and
127.B F_TLOCK
128or
129.B F_TEST
130was specified, or the operation is prohibited because the file has
131been memory-mapped by another process.
132.TP
133.B EBADF
134.I fd
c28d4af6
MK
135is not an open file descriptor; or
136.I cmd
137is
138.B F_LOCK
139or
140.BR F_TLOCK
141and
142.I fd
143is not a writable file descriptor.
fea681da
MK
144.TP
145.B EDEADLK
146The command was
02ff975d 147.B F_LOCK
fea681da
MK
148and this lock operation would cause a deadlock.
149.TP
150.B EINVAL
151An invalid operation was specified in
de76dacf 152.IR cmd .
fea681da
MK
153.TP
154.B ENOLCK
155Too many segment locks open, lock table is full.
3d004cf0 156.SH ATTRIBUTES
8931aeb5
MK
157For an explanation of the terms used in this section, see
158.BR attributes (7).
159.TS
160allbox;
161lb lb lb
162l l l.
163Interface Attribute Value
164T{
3d004cf0 165.BR lockf ()
8931aeb5
MK
166T} Thread safety MT-Safe
167.TE
47297adb 168.SH CONFORMING TO
f287e294 169POSIX.1-2001, POSIX.1-2008, SVr4.
47297adb 170.SH SEE ALSO
fea681da
MK
171.BR fcntl (2),
172.BR flock (2)
847e0d88 173.PP
fea681da
MK
174.I locks.txt
175and
f6beb9d7 176.I mandatory-locking.txt
173fe7e7 177in the Linux kernel source directory
4eaa04c5 178.IR Documentation/filesystems
173fe7e7
DP
179(on older kernels, these files are directly under the
180.I Documentation
73e15b46
MK
181directory, and
182.I mandatory-locking.txt
183is called
173fe7e7 184.IR mandatory.txt )