3.3.5.23 Receiving an SMB_COM_WRITE_AND_UNLOCK Request

The SMB_COM_WRITE_AND_UNLOCK (section 2.2.4.21) command combines the behavior of SMB_COM_WRITE (section 2.2.4.12) with that of SMB_COM_UNLOCK_BYTE_RANGE (section 2.2.4.14). SMB_COM_WRITE_AND_UNLOCK (section 2.2.4.21) is intended to be paired with SMB_COM_LOCK_AND_READ (section 2.2.4.20) 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).<274>

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 2.2.4.21.2. The response MUST be sent to the client as specified in section 3.3.4.1 The server MUST remove the matching entry from the Server.Open.Locks list.