fcntl cooperation with server side processes

Jeremy Allison jra at samba.org
Tue Jul 20 21:46:34 GMT 2004

On Tue, Jul 20, 2004 at 05:35:14PM -0400, Chris Green wrote:
> Good day,
> This is a repost/recap of a question and asked on
> samba at lists.samba.org.  I'm using Samba 2.2.8a [1] on Slackware 9.1
> with 2000/XP clients.  I'm using the Linux 2.4.25 kernel.
> I want to have a "drop box" that I have NT/2000 clients writing to
> share and then have a unix process read and delete the file.
> My problem is that samba isn't doing a lock that I can see from the
> Linux side. My usage pattern is:
> 1) Copy cygwin.tar (250M) to share using Windows Explorer on W2K.
> 2) from the server's command line while the file is still copying, run
>    ./lockview cygwin.tar
> http://cmg.dok.org/code/lockview.c.  This code uses fcntl(fd,F_GETLK,
> &flockstruct) to see what kind of locks are on the file.
>  output/Testing# ~/lockview cygwin.tar
>    this file has no lock!
> If I use ``strict locking = yes'', and I have a process use fcntl to
> perform a fcntl(fd, F_SETLK, {F_WRLCK, ....}), I get a message on the
> windows side instantly saying
>     ``Cannot copy cygwin: The process cannot access the file because
>       another process has locked a portion of the file''
> If I don't use strict locking, rather than aborting the copy, it appears
> to unlink when the copy is complete.      
> As far as I've been able to trace it with debug level = 10, it seems
> that there is no lock associated with file creation.  I'm not able to
> dig out what the values of share mode means. My lock fails even if I
> turn oplocks = off.    

Share modes are not file locks. Don't confuse the two. Share modes have
no meaning to POSIX apps and they ignore them.

If you want to coordinate between Windows and Linux apps make sure
the Windows apps don't ask for oplocks (or the Linux kernel you're using
is oplock aware) and use LockFileEx on the Windows side which Samba will
map into fcntl locks on the Linux side.

If Windows explorer doesn't set file locks when copying using LockFileEx
(and I don't think it does) then no, the POSIX apps won't see them.


More information about the samba-technical mailing list