WRITE_ANDX: Write Bytes to file or resource

Client Request
===============================
Description
====================================
UCHAR WordCount; Count of parameter words = 12 or 14
UCHAR AndXCommand; Secondary (X) command; 0xFF = none
UCHAR AndXReserved; Reserved (must be 0)
USHORT AndXOffset; Offset to next command WordCount
USHORT Fid; File handle
ULONG Offset; Offset in file to begin write
ULONG Reserved; Must be 0
USHORT WriteMode; Write mode bits:
0 - write through
USHORT Remaining; Bytes remaining to satisfy request
USHORT Reserved;
USHORT DataLength; Number of data bytes in buffer (>=0)
USHORT DataOffset; Offset to data bytes
ULONG OffsetHigh; Upper 32 bits of offset (only present if WordCount = 14)
USHORT ByteCount; Count of data bytes
UCHAR Pad[]; Pad to SHORT or LONG
UCHAR Data[DataLength]; Data to write

Server Response
===============================
Description
====================================
UCHAR WordCount; Count of parameter words = 6
UCHAR AndXCommand; Secondary (X) command; 0xFF = none
UCHAR AndXReserved; Reserved (must be 0)
USHORT AndXOffset; Offset to next command WordCount
USHORT Count; Number of bytes written
USHORT Remaining; Reserved
ULONG Reserved;
USHORT ByteCount; Count of data bytes = 0

A ByteCount of 0 does not truncate the file. Rather a zero length write merely transfers zero bytes of information to the file. A request such as SMB_COM_WRITE must be used to truncate the file.

If WriteMode has bit0 set in the request and Fid refers to a disk file, the response is not sent from the server until the data is on stable storage.

If the negotiated dialect is NT LM 0.12 or later, the 14 word format of this SMB may be used to access portions of files requiring offsets expressed as 64 bits. Otherwise, the OffsetHigh field must be omitted from the request.

The following are the valid AndXCommand values for this SMB:

SMB_COM_READ SMB_COM_READ_ANDX
SMB_COM_LOCK_AND_READ SMB_COM_WRITE_ANDX
SMB_COM_CLOSE

Errors

ERRDOS/ERRnoaccess
ERRDOS/ERRbadfid
ERRDOS/ERRlock
ERRDOS/ERRbadaccess
ERRSRV/ERRinvid
ERRSRV/ERRbaduid