WRITE: Write Bytes

The write message is sent to write bytes into the resource indicated by fid in the SMB header.

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
UCHAR Data[ Count ]; The data to write

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 32 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.

When fid represents a disk file and 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. When a write specifies a length of zero, the file is truncated (or extended) to the length specified by the offset.

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.