Testing for fcntl locks before doing ftruncate()?
Jeremy Allison
jra at samba.org
Thu Jan 19 14:53:46 GMT 2006
On Thu, Jan 19, 2006 at 01:53:34PM +0100, Volker Lendecke wrote:
> Hi!
>
> A customer of mine is testing cross-platform access to files from Samba and
> Unix, in particular fcntl locking. One thing that happened that an
>
> echo hello > test.txt
>
> done from a windows command window wiped out the file contents that had been
> locked by fcntl locks on the unix side. This happened because in open.c:
>
> if (flags2&O_TRUNC) {
> /*
> * We are modifing the file after open - update the stat
> * struct..
> */
> if ((SMB_VFS_FTRUNCATE(fsp,fsp->fh->fd,0) == -1) ||
> (SMB_VFS_FSTAT(fsp,fsp->fh->fd,psbuf)==-1)) {
> unlock_share_entry_fsp(fsp);
> fd_close(conn,fsp);
> file_free(fsp);
> return NULL;
> }
> }
>
> we don't check for byte range locks. Similarly for the ftruncate in smbwrite.
>
> This is probably not what is expected. Shall we add some is_posix_locked()
> here?
Ok, took a quick look. We need a Samba4 torture test to check the effects
of an open with truncate on a file that is open and has read or write locks
on another fnum. We need to make sure we do the correct thing here - we should
treat a posix lock identically to an existing Windows lock here.
Jeremy.
More information about the samba-technical
mailing list