2004-11-03 13:51:07 +00:00
|
|
|
|
.\" Copyright 1997 Nicol<6F>s Lichtmaier <nick@debian.org>
|
|
|
|
|
.\" Created Thu Aug 7 00:44:00 ART 1997
|
|
|
|
|
.\"
|
|
|
|
|
.\" This is free documentation; you can redistribute it and/or
|
|
|
|
|
.\" modify it under the terms of the GNU General Public License as
|
|
|
|
|
.\" published by the Free Software Foundation; either version 2 of
|
|
|
|
|
.\" the License, or (at your option) any later version.
|
|
|
|
|
.\"
|
|
|
|
|
.\" The GNU General Public License's references to "object code"
|
|
|
|
|
.\" and "executables" are to be interpreted as the output of any
|
|
|
|
|
.\" document formatting or typesetting system, including
|
|
|
|
|
.\" intermediate and printed output.
|
|
|
|
|
.\"
|
|
|
|
|
.\" This manual is distributed in the hope that it will be useful,
|
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
|
.\"
|
|
|
|
|
.\" Added section stuff, aeb, 2002-04-22.
|
|
|
|
|
.\" Corrected include file, drepper, 2003-06-15.
|
|
|
|
|
.\"
|
2012-07-07 05:16:34 +00:00
|
|
|
|
.TH LOCKF 3 2012-07-07 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.SH NAME
|
|
|
|
|
lockf \- apply, test or remove a POSIX lock on an open file
|
|
|
|
|
.SH SYNOPSIS
|
|
|
|
|
.B #include <unistd.h>
|
|
|
|
|
.sp
|
2006-01-14 17:14:10 +00:00
|
|
|
|
.BI "int lockf(int " fd ", int " cmd ", off_t " len );
|
2007-07-08 12:11:40 +00:00
|
|
|
|
.sp
|
|
|
|
|
.in -4n
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
|
.in
|
|
|
|
|
.sp
|
|
|
|
|
.BR lockf ():
|
2010-09-18 09:14:55 +00:00
|
|
|
|
.ad l
|
|
|
|
|
.RS 4
|
|
|
|
|
_BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
|
|
|
|
|
_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
|
|
|
|
|
.RE
|
|
|
|
|
.ad
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.SH DESCRIPTION
|
|
|
|
|
Apply, test or remove a POSIX lock on a section of an open file.
|
|
|
|
|
The file is specified by
|
|
|
|
|
.IR fd ,
|
|
|
|
|
a file descriptor open for writing, the action by
|
|
|
|
|
.IR cmd ,
|
|
|
|
|
and the section consists of byte positions
|
2005-07-06 08:00:30 +00:00
|
|
|
|
.IR pos .. pos + len \-1
|
2005-07-06 07:53:36 +00:00
|
|
|
|
if
|
|
|
|
|
.I len
|
|
|
|
|
is positive, and
|
2005-07-06 08:00:30 +00:00
|
|
|
|
.IR pos \- len .. pos \-1
|
2005-07-06 07:53:36 +00:00
|
|
|
|
if
|
|
|
|
|
.I len
|
|
|
|
|
is negative, where
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.I pos
|
|
|
|
|
is the current file position, and if
|
|
|
|
|
.I len
|
|
|
|
|
is zero, the section extends from the current file position to
|
|
|
|
|
infinity, encompassing the present and future end-of-file positions.
|
|
|
|
|
In all cases, the section may extend past current end-of-file.
|
|
|
|
|
.LP
|
2009-07-25 05:57:14 +00:00
|
|
|
|
On Linux,
|
|
|
|
|
.BR lockf ()
|
|
|
|
|
is just an interface on top of
|
|
|
|
|
.BR fcntl (2)
|
|
|
|
|
locking.
|
|
|
|
|
Many other systems implement
|
|
|
|
|
.BR lockf ()
|
|
|
|
|
in this way, but note that POSIX.1-2001 leaves the relationship between
|
2005-10-19 06:54:38 +00:00
|
|
|
|
.BR lockf ()
|
2004-11-03 13:51:07 +00:00
|
|
|
|
and
|
2007-05-12 00:30:29 +00:00
|
|
|
|
.BR fcntl (2)
|
2009-07-25 05:57:14 +00:00
|
|
|
|
locks unspecified.
|
|
|
|
|
A portable application should probably avoid mixing calls
|
|
|
|
|
to these interfaces.
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.LP
|
|
|
|
|
Valid operations are given below:
|
|
|
|
|
.TP
|
|
|
|
|
.B F_LOCK
|
|
|
|
|
Set an exclusive lock on the specified section of the file.
|
|
|
|
|
If (part of) this section is already locked, the call
|
|
|
|
|
blocks until the previous lock is released.
|
|
|
|
|
If this section overlaps an earlier locked section,
|
|
|
|
|
both are merged.
|
|
|
|
|
File locks are released as soon as the process holding the locks
|
2007-04-12 22:42:49 +00:00
|
|
|
|
closes some file descriptor for the file.
|
|
|
|
|
A child process does not inherit these locks.
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.TP
|
|
|
|
|
.B F_TLOCK
|
|
|
|
|
Same as
|
|
|
|
|
.B F_LOCK
|
|
|
|
|
but the call never blocks and returns an error instead if the file is
|
|
|
|
|
already locked.
|
|
|
|
|
.TP
|
|
|
|
|
.B F_ULOCK
|
|
|
|
|
Unlock the indicated section of the file.
|
|
|
|
|
This may cause a locked section to be split into two locked sections.
|
|
|
|
|
.TP
|
|
|
|
|
.B F_TEST
|
|
|
|
|
Test the lock: return 0 if the specified section
|
|
|
|
|
is unlocked or locked by this process; return \-1, set
|
|
|
|
|
.I errno
|
|
|
|
|
to
|
2007-09-20 16:26:31 +00:00
|
|
|
|
.B EAGAIN
|
2006-02-10 20:27:59 +00:00
|
|
|
|
.RB ( EACCES
|
|
|
|
|
on some other systems),
|
2004-11-03 13:51:07 +00:00
|
|
|
|
if another process holds a lock.
|
|
|
|
|
.SH "RETURN VALUE"
|
2007-04-12 22:42:49 +00:00
|
|
|
|
On success, zero is returned.
|
|
|
|
|
On error, \-1 is returned, and
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.I errno
|
|
|
|
|
is set appropriately.
|
|
|
|
|
.SH ERRORS
|
|
|
|
|
.TP
|
2006-02-10 20:27:59 +00:00
|
|
|
|
.BR EACCES " or " EAGAIN
|
2004-11-03 13:51:07 +00:00
|
|
|
|
The file is locked and
|
|
|
|
|
.B F_TLOCK
|
|
|
|
|
or
|
|
|
|
|
.B F_TEST
|
|
|
|
|
was specified, or the operation is prohibited because the file has
|
|
|
|
|
been memory-mapped by another process.
|
|
|
|
|
.TP
|
|
|
|
|
.B EBADF
|
|
|
|
|
.I fd
|
2011-09-11 15:19:38 +00:00
|
|
|
|
is not an open file descriptor; or
|
|
|
|
|
.I cmd
|
|
|
|
|
is
|
|
|
|
|
.B F_LOCK
|
|
|
|
|
or
|
|
|
|
|
.BR F_TLOCK
|
|
|
|
|
and
|
|
|
|
|
.I fd
|
|
|
|
|
is not a writable file descriptor.
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.TP
|
|
|
|
|
.B EDEADLK
|
|
|
|
|
The command was
|
2012-07-07 05:16:34 +00:00
|
|
|
|
.B F_LOCK
|
2004-11-03 13:51:07 +00:00
|
|
|
|
and this lock operation would cause a deadlock.
|
|
|
|
|
.TP
|
|
|
|
|
.B EINVAL
|
|
|
|
|
An invalid operation was specified in
|
|
|
|
|
.IR fd .
|
|
|
|
|
.TP
|
|
|
|
|
.B ENOLCK
|
|
|
|
|
Too many segment locks open, lock table is full.
|
|
|
|
|
.SH "CONFORMING TO"
|
2008-07-15 13:39:17 +00:00
|
|
|
|
SVr4, POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
|
.BR fcntl (2),
|
|
|
|
|
.BR flock (2)
|
arch_prctl.2, fcntl.2, flock.2, get_robust_list.2, getpriority.2, ioprio_set.2, migrate_pages.2, mmap.2, mremap.2, msync.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, socket.2, subpage_prot.2, unshare.2, btree.3, dbopen.3, dl_iterate_phdr.3, dlopen.3, getnameinfo.3, hash.3, lockf.3, netlink.3, recno.3, rpc.3, xdr.3, cciss.4, console_ioctl.4, hpsa.4, initrd.4, msr.4, rtc.4, st.4, hosts.5, services.5, tzfile.5, aio.7, arp.7, capabilities.7, cpuset.7, feature_test_macros.7, futex.7, inotify.7, ip.7, ipv6.7, iso_8859-16.7, iso_8859-2.7, koi8-r.7, math_error.7, netlink.7, packet.7, pthreads.7, raw.7, spufs.7, udplite.7, uri.7, x25.7: Global fix: Various consistency fixes for SEE ALSO
Coauthored-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-09-24 07:53:22 +00:00
|
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
|
.I locks.txt
|
|
|
|
|
and
|
2009-03-29 18:27:50 +00:00
|
|
|
|
.I mandatory-locking.txt
|
arch_prctl.2, fcntl.2, flock.2, get_robust_list.2, getpriority.2, ioprio_set.2, migrate_pages.2, mmap.2, mremap.2, msync.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, socket.2, subpage_prot.2, unshare.2, btree.3, dbopen.3, dl_iterate_phdr.3, dlopen.3, getnameinfo.3, hash.3, lockf.3, netlink.3, recno.3, rpc.3, xdr.3, cciss.4, console_ioctl.4, hpsa.4, initrd.4, msr.4, rtc.4, st.4, hosts.5, services.5, tzfile.5, aio.7, arp.7, capabilities.7, cpuset.7, feature_test_macros.7, futex.7, inotify.7, ip.7, ipv6.7, iso_8859-16.7, iso_8859-2.7, koi8-r.7, math_error.7, netlink.7, packet.7, pthreads.7, raw.7, spufs.7, udplite.7, uri.7, x25.7: Global fix: Various consistency fixes for SEE ALSO
Coauthored-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-09-24 07:53:22 +00:00
|
|
|
|
in the Linux kernel source directory
|
2012-10-15 09:13:31 +00:00
|
|
|
|
.IR Documentation/filesystems
|
arch_prctl.2, fcntl.2, flock.2, get_robust_list.2, getpriority.2, ioprio_set.2, migrate_pages.2, mmap.2, mremap.2, msync.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, socket.2, subpage_prot.2, unshare.2, btree.3, dbopen.3, dl_iterate_phdr.3, dlopen.3, getnameinfo.3, hash.3, lockf.3, netlink.3, recno.3, rpc.3, xdr.3, cciss.4, console_ioctl.4, hpsa.4, initrd.4, msr.4, rtc.4, st.4, hosts.5, services.5, tzfile.5, aio.7, arp.7, capabilities.7, cpuset.7, feature_test_macros.7, futex.7, inotify.7, ip.7, ipv6.7, iso_8859-16.7, iso_8859-2.7, koi8-r.7, math_error.7, netlink.7, packet.7, pthreads.7, raw.7, spufs.7, udplite.7, uri.7, x25.7: Global fix: Various consistency fixes for SEE ALSO
Coauthored-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-09-24 07:53:22 +00:00
|
|
|
|
(on older kernels, these files are directly under the
|
|
|
|
|
.I Documentation
|
2009-07-25 05:57:14 +00:00
|
|
|
|
directory, and
|
|
|
|
|
.I mandatory-locking.txt
|
|
|
|
|
is called
|
arch_prctl.2, fcntl.2, flock.2, get_robust_list.2, getpriority.2, ioprio_set.2, migrate_pages.2, mmap.2, mremap.2, msync.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, socket.2, subpage_prot.2, unshare.2, btree.3, dbopen.3, dl_iterate_phdr.3, dlopen.3, getnameinfo.3, hash.3, lockf.3, netlink.3, recno.3, rpc.3, xdr.3, cciss.4, console_ioctl.4, hpsa.4, initrd.4, msr.4, rtc.4, st.4, hosts.5, services.5, tzfile.5, aio.7, arp.7, capabilities.7, cpuset.7, feature_test_macros.7, futex.7, inotify.7, ip.7, ipv6.7, iso_8859-16.7, iso_8859-2.7, koi8-r.7, math_error.7, netlink.7, packet.7, pthreads.7, raw.7, spufs.7, udplite.7, uri.7, x25.7: Global fix: Various consistency fixes for SEE ALSO
Coauthored-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-09-24 07:53:22 +00:00
|
|
|
|
.IR mandatory.txt )
|