LibreOffice File Locking on Shared Network Drives
When multiple users collaborate on documents across network shares, LibreOffice relies on a combination of application-level lock files and operating system network protocols to prevent conflicting simultaneous edits. This article details the native locking mechanisms used by LibreOffice, the supported network file protocols—including SMB/CIFS, NFS, and WebDAV—and how these systems interact to protect document integrity.
Application-Level Lock Files
LibreOffice primarily prevents simultaneous write access by generating hidden lock files directly in the same directory as the target document.
- File Format: When
document.odtis opened for editing, LibreOffice creates a temporary hidden file named.~lock.document.odt#. - Metadata Stored: The lock file contains the username of the editor, the computer hostname, the date and timestamp of access, and the LibreOffice install path.
- Conflict Prevention: If a second user attempts to open the same file, LibreOffice scans the directory, detects the active lock file, and informs the user that the document is locked for editing by the specific user. The second user is given options to open the document as read-only, open a copy, or receive a notification when the original file is closed.
Network-Level File Locking Protocols
In addition to internal lock files, LibreOffice depends on the underlying network protocol of the shared storage environment to enforce file access controls and maintain write safety.
1. SMB / CIFS (Server Message Block)
SMB is the standard protocol for Windows file shares and Samba-configured Linux servers. * Byte-Range Locking: LibreOffice uses standard OS-level byte-range locks to ensure that no two processes write to the same sector of a file at once. * Opportunistic Locking (Oplocks): SMB uses oplocks to allow clients to cache data locally. When a second user requests access, the server revokes the lock, forcing cache synchronization before read-only access is granted.
2. NFS (Network File System)
Used commonly in Linux and Unix-based enterprise storage systems. *
POSIX fcntl() and flock():
LibreOffice relies on POSIX file locking calls via the operating system
kernel. * NFSv3 vs. NFSv4: On NFSv3, locking is handled
by the Network Lock Manager (NLM) daemon. NFSv4 integrates stateful,
lease-based file locking directly into the core protocol, providing more
reliable detection and release of abandoned locks.
3. WebDAV (Web Distributed Authoring and Versioning)
When LibreOffice accesses remote shares via its built-in remote files
service over HTTP/HTTPS, it utilizes WebDAV locking. * RFC 4918
Locking: LibreOffice issues HTTP LOCK and
UNLOCK requests to the WebDAV server. * Exclusive
Write Locks: A successful LOCK request issues an
XML-based lock token to the active editor. Any subsequent
PUT or LOCK requests from other clients
without this token are rejected with an HTTP 423 (Locked) status
code.
Critical Settings and Considerations
- Write Permissions: File locking requires write
permissions in the directory where the document resides. If users have
read-only access to the folder, LibreOffice cannot create the
.~lock.*#file, defaulting the document to read-only mode automatically. - Stale Locks: If LibreOffice crashes or network
connectivity drops abruptly, lock files may remain on the shared drive.
Removing the orphaned
.~lock.filename.ext#file restores full read/write capabilities to other users. - Disabling File Locking: While not recommended for
shared environments, file locking can be controlled via the environment
variable
SAL_ENABLE_FILE_LOCKING=1(enabled by default) to force or bypass OS-level system locking calls.