Which Cygwin file locking API works over SMB?
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Mar 3 12:04:10 GMT 2025
On Mar 1 01:18, Dan Shelton via Cygwin wrote:
> On 2025年2月28日 at 20:34, Dan Shelton <dan.f.shelton@gmail.com> wrote:
> >
> > Hello!
> >
> > Which Cygwin/POSIX file locking API work over SMB? We need file
> > locking across multiple SMB clients
>> Coworker just said that Cygwin does not support file locking over
> remote (SMB, NFS, ...) filesystems. Is that true?
Cygwin doesn't care if the filesystem is local or remote, because
the datastructures are held in the internal NT namespace as long
as at least one process still holds the handles to it. However,
that also means POSIX and BSD advisory locks are machine-local.
What might work over SMB is the Windows mandatory lock type. You can
use it from Cygwin by calling fcntl (fd, F_LCK_MANDATORY, 1) and use the
flock functions afterwards.
Opportunistic Locks in Windows may be an option, too, but theoretically
user sapce is not supposed to use them over the network.
Alternatively, just use a dotlock file in parallel to the data file.
This method is used a lot by POSIX apps, see, for instance, mutt,
which even handles files on NFS shares separately.
Corinna
More information about the Cygwin
mailing list