Receiving an SMB_COM_WRITE_AND_UNLOCK Request

The SMB_COM_WRITE_AND_UNLOCK (section command combines the behavior of SMB_COM_WRITE (section with that of SMB_COM_UNLOCK_BYTE_RANGE (section SMB_COM_WRITE_AND_UNLOCK (section is intended to be paired with SMB_COM_LOCK_AND_READ (section to perform record updates to a file.

The FID provided in the command request MUST indicate a file held open by the client with, at minimum, write access. The server MUST first perform the write operation and then release the lock. The bytes to be written are passed in the Data field of the request, and MUST be written starting at the file position indicated by the WriteOffsetInBytes field. Once the data has been successfully written, the server MUST attempt to unlock the byte range specified by WriteOffsetInBytes (offset) and CountOfBytesToWrite (length).<273>

It is possible that the actual number of bytes available in the request, as indicated by the DataLength field, is less than CountOfBytesToWrite. If this occurs, the server MUST write DataLength bytes from the Data field to the file indicated by the FID starting at the position indicated by WriteOffsetInBytes. When the byte range is unlocked, however, the full range as specified by WriteOffsetInBytes and CountOfBytesToWrite MUST be unlocked.

In the event of an error, the server MUST send an error response message. If the write and unlock are successful, the server MUST construct an SMB_COM_WRITE_AND_UNLOCK response message as specified in section The response MUST be sent to the client as specified in section The server MUST remove the matching entry from the Server.Open.Locks list.