⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Module flock

Module flock 

Source
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§

FileLock
A POSIX byte-range lock (used by fcntl F_SETLK / F_GETLK).
FlockEntry
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).