Expand description
POSIX File Locking (flock/fcntl)
Implements both whole-file locking (flock semantics) and byte-range locking (fcntl/POSIX semantics). Per-inode lock tables track ownership by PID, with deadlock detection for blocking lock requests.
flock(): whole-file advisory locks (LOCK_SH, LOCK_EX, LOCK_UN)fcntl_setlk(): byte-range locks (F_SETLK semantics, non-blocking)fcntl_setlkw(): byte-range locks (F_SETLKW semantics, blocking with deadlock detection)fcntl_getlk(): query conflicting locks (F_GETLK)cleanup_process_locks(): release all locks held by a process on exit
Structs§
- File
Lock - A POSIX byte-range lock (used by fcntl F_SETLK / F_GETLK).
- Flock
Entry - A whole-file advisory lock entry (flock semantics).
Constants§
- F_RDLCK
- Read (shared) lock
- F_UNLCK
- Unlock
- F_WRLCK
- Write (exclusive) lock
- LOCK_EX
- Exclusive (write) lock
- LOCK_NB
- Non-blocking flag (OR with LOCK_SH or LOCK_EX)
- LOCK_SH
- Shared (read) lock
- LOCK_UN
- Unlock
Functions§
- cleanup_
process_ locks - Remove all locks (flock and range) held by the specified PID.
- fcntl_
getlk - Query for a conflicting lock (F_GETLK semantics).
- fcntl_
setlk - Set a byte-range lock (F_SETLK semantics – non-blocking).
- fcntl_
setlkw - Set a byte-range lock with blocking (F_SETLKW semantics).
- flock
- Apply a whole-file advisory lock (flock semantics).