WRITE_AND_UNLOCK: Write Bytes and Unlock Range

This request is used to first write the specified bytes and then unlock them. The locked portion of a file is "safe" to write behind because no other process can access the locked bytes until this process unlocks the bytes. Thus the client can buffer the locked bytes locally while they are being updated, then when the unlock request is received submit this protocol to both write and then unlock bytes. Whether or not this SMB is supported (along with SMB_COM_READ_AND_LOCK) is returned in bit0 of the flags field of the negotiate response.

Client Request
================================
Description
===================================
UCHAR WordCount; Count of parameter words = 5
USHORT Fid; File handle
USHORT Count; Number of bytes to be written
ULONG Offset; Offset in file to begin write
USHORT Remaining; Bytes remaining to satisfy request
USHORT ByteCount; Count of data bytes
UCHAR BufferFormat; 0x01 -- Data block
USHORT DataLength; Length of data

count specifies the number of bytes to be written. offset is the offset in the file of the first byte to be written. Since offset is 16 bits, this request is inappropriate for general use in a very large file. remaining is advisory: if the value is not zero, then it is taken as an estimate of the number of bytes that will be written -including those written by this request. This additional information may be used by the server to optimize cache behavior. A value of 0 for count is an error.

If the request specifies a byte range beyond the current end of file, the file will be extended. Any bytes between the previous end of file and the requested offset are initialized to 0.

Server Response
==================================
Description
=================================
UCHAR WordCount; Count of parameter words = 1
USHORT Count; Count of bytes actually written
USHORT ByteCount; Count of data bytes = 0

count in the response indicates the actual number of bytes written, and for successful writes will always equal the count in the request message. If the number of bytes written differs from the number requested and no error is indicated, then the server has no resources available with which to satisfy the complete write.

If a Write sends a message of length greater than the maxbuffersize for the TID specified, the server may abort the connection to the client. If an error occurs on the write, the bytes remain locked.