DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 523C5Abq2801888
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 523C5Abq2801888
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=cYyGOcB/
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0323C385840E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1741003510;
	bh=81obPs7QlgZX7/8AcKQLxnRG6FYyQbyOq6rgQPlqL3s=;
	h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=cYyGOcB/GdDVDG8CVsD2EHJe78E5ZnK/pJDsiYqepvdRZ4/R86S09YE7IhnFp0e+V
	 WD6WJgxX3gDiLLbHEW7hrncLy9M2xMbp76kyI2vZF6TA+2MvQxaFWN5/yz+WyG/FCO
	 NVEphoyPyyEAtWHiHa/03d1sLtHr/BEoOuIx2GGA=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A1EB3858D21
Date: Mon, 3 Mar 2025 13:04:10 +0100
To: cygwin@cygwin.com
Subject: Re: Which Cygwin file locking API works over SMB?
Message-ID: <Z8WauqBHVPK6MhLn@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <CAAvCNcBrnDOcUcNOpYTDp3dsbjmf7bqhFDHTZkf4DqshE+FhOg@mail.gmail.com>
 <CAAvCNcCj2bU6V58bSLj26QtVOAMNo-VMBjmf-7eq3Ct9JzMWkg@mail.gmail.com>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <CAAvCNcCj2bU6V58bSLj26QtVOAMNo-VMBjmf-7eq3Ct9JzMWkg@mail.gmail.com>
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

On Mar  1 01:18, Dan Shelton via Cygwin wrote:
> On Fri, 28 Feb 2025 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

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
