Applies or removes an advisory lock on an open file.
Arguments
eax |
143 |
ebx |
File descriptor. |
ecx |
Operation to apply. It should be one of the following predefined values:
LOCK_SH |
A shared lock. |
LOCK_EX |
An exclusive lock. |
LOCK_UN |
Remove an existing lock. |
LOCK_MAND |
A `mandatory' flock. This exists to emulate Windows Share Modes. It can be combined with LOCK_READ or to allow other processes read and write access respectively. |
|
|
Return values
If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:
-EINTR |
While waiting to acquire a lock, the call was interrupted by delivery of a signal caught by a handler. |
-EBADF |
ebx is not a valid, open, file descriptor. |
-EINVAL |
ecx specifies invalid operation value. |
-EWOULDBLOCK |
The file is locked and the LOCK_NB flag was selected. |
-ENOLCK |
The kernel ran out of memory for allocating lock records. |
|
Remarks
A single file may not simultaneously have both shared and exclusive locks.
Duplicate file descriptors (created by, for example, sys_fork or sys_dup) refer to the same lock, and this lock may be modified or released using any of these descriptors. Furthermore, the lock is released either by an explicit LOCK_UN operation on any of these duplicate descriptors, or when all such descriptors have been closed.
sys_flock does not lock files over NFS. Use sys_fcntl instead: that does work over NFS, given a sufficiently recent version of Linux and a server which supports locking.
sys_flock places advisory locks only; given suitable permissions on a file, a process is free to ignore the use of this sytem call and perform I/O on the file.
Converting a lock (shared to exclusive, or vice versa) is not guaranteed to be atomic: the existing lock is first removed, and then a new lock is established. Between these two steps, a pending lock request by another process may be granted, with the result that the conversion either blocks, or fails if LOCK_NB was specified.
Compatibility
n/a |