SMB2 Write truncate

Jeremy Allison jra at samba.org
Tue Jan 14 00:08:36 UTC 2020


On Mon, Jan 13, 2020 at 10:47:26PM +0000, David Mulder via samba-technical wrote:
> Based on the behavior of tests in source4/torture/basic/delaywrite.c, it seems
> sending a write request in smb1, with a buffer size of 0, would truncate the file
> (at least that's what the comments say in the test). There doesn't seem to be any
> reason for the offset size in these tests (some are less than the current size of
> the file, others are much greater than the current size, which doesn't make much sense).

Yes, that's what I recall. Offset size less than the file should
truncate. Offset size greater should expand. Here's the code in
the server for SMB1write:

        /*
         * X/Open SMB protocol says that if smb_vwv1 is
         * zero then the file size should be extended or
         * truncated to the size given in smb_vwv[2-3].
         */

        if(numtowrite == 0) {
                /*
                 * This is actually an allocate call, and set EOF. JRA.
                 */
                nwritten = vfs_allocate_file_space(fsp, (off_t)startpos);
                if (nwritten < 0) {
                        reply_nterror(req, NT_STATUS_DISK_FULL);
                        goto out;
                }
                nwritten = vfs_set_filelen(fsp, (off_t)startpos);
                if (nwritten < 0) {
                        reply_nterror(req, NT_STATUS_DISK_FULL);
                        goto out;
                }
	} else ...

> 
> I'm working on converting these tests to SMB2, but the behavior isn't the same.
> An SMB2 write responds with NT_STATUS_INVALID_PARAMETER when you set the buffer size to 0.
> I can't find in the MS-SMB2 spec how to correctly truncate a file. Anyone know how to do this?

That sounds correct - SMB2 tidied up all these
horrible size effects.

To truncate in SMB2 you can call setinfo on a handle
with SMB_FILE_END_OF_FILE_INFORMATION.



More information about the samba-technical mailing list