OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / man3 / lockf.3
1 .\" Copyright 1997 Nicolás Lichtmaier <nick@debian.org>
2 .\" Created Thu Aug  7 00:44:00 ART 1997
3 .\"
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" Added section stuff, aeb, 2002-04-22.
20 .\" Corrected include file, drepper, 2003-06-15.
21 .\"
22 .TH LOCKF 3 2009-07-25 "GNU" "Linux Programmer's Manual"
23 .SH NAME
24 lockf \- apply, test or remove a POSIX lock on an open file
25 .SH SYNOPSIS
26 .B #include <unistd.h>
27 .sp
28 .BI "int lockf(int " fd ", int " cmd ", off_t " len );
29 .sp
30 .in -4n
31 Feature Test Macro Requirements for glibc (see
32 .BR feature_test_macros (7)):
33 .in
34 .sp
35 .BR lockf ():
36 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
37 .SH DESCRIPTION
38 Apply, test or remove a POSIX lock on a section of an open file.
39 The file is specified by
40 .IR fd ,
41 a file descriptor open for writing, the action by
42 .IR cmd ,
43 and the section consists of byte positions
44 .IR pos .. pos + len \-1
45 if
46 .I len
47 is positive, and
48 .IR pos \- len .. pos \-1
49 if
50 .I len
51 is negative, where
52 .I pos
53 is the current file position, and if
54 .I len
55 is zero, the section extends from the current file position to
56 infinity, encompassing the present and future end-of-file positions.
57 In all cases, the section may extend past current end-of-file.
58 .LP
59 On Linux,
60 .BR lockf ()
61 is just an interface on top of
62 .BR fcntl (2)
63 locking.
64 Many other systems implement
65 .BR lockf ()
66 in this way, but note that POSIX.1-2001 leaves the relationship between
67 .BR lockf ()
68 and
69 .BR fcntl (2)
70 locks unspecified.
71 A portable application should probably avoid mixing calls
72 to these interfaces.
73 .LP
74 Valid operations are given below:
75 .TP
76 .B F_LOCK
77 Set an exclusive lock on the specified section of the file.
78 If (part of) this section is already locked, the call
79 blocks until the previous lock is released.
80 If this section overlaps an earlier locked section,
81 both are merged.
82 File locks are released as soon as the process holding the locks
83 closes some file descriptor for the file.
84 A child process does not inherit these locks.
85 .TP
86 .B F_TLOCK
87 Same as
88 .B F_LOCK
89 but the call never blocks and returns an error instead if the file is
90 already locked.
91 .TP
92 .B F_ULOCK
93 Unlock the indicated section of the file.
94 This may cause a locked section to be split into two locked sections.
95 .TP
96 .B F_TEST
97 Test the lock: return 0 if the specified section
98 is unlocked or locked by this process; return \-1, set
99 .I errno
100 to
101 .B EAGAIN
102 .RB ( EACCES
103 on some other systems),
104 if another process holds a lock.
105 .SH "RETURN VALUE"
106 On success, zero is returned.
107 On error, \-1 is returned, and
108 .I errno
109 is set appropriately.
110 .SH ERRORS
111 .TP
112 .BR EACCES " or " EAGAIN
113 The file is locked and
114 .B F_TLOCK
115 or
116 .B F_TEST
117 was specified, or the operation is prohibited because the file has
118 been memory-mapped by another process.
119 .TP
120 .B EBADF
121 .I fd
122 is not an open file descriptor.
123 .TP
124 .B EDEADLK
125 The command was
126 .B T_LOCK
127 and this lock operation would cause a deadlock.
128 .TP
129 .B EINVAL
130 An invalid operation was specified in
131 .IR fd .
132 .TP
133 .B ENOLCK
134 Too many segment locks open, lock table is full.
135 .SH "CONFORMING TO"
136 SVr4, POSIX.1-2001.
137 .SH "SEE ALSO"
138 .BR fcntl (2),
139 .BR flock (2)
140 .br
141 There are also
142 .I locks.txt
143 and
144 .I mandatory-locking.txt
145 in the kernel source directory
146 .IR Documentation/filesystems .
147 (On older kernels, these files are directly under the
148 .I Documentation/
149 directory, and
150 .I mandatory-locking.txt
151 is called
152 .IR mandatory.txt .)