Partager via


3.3.5.14 Receiving an SMB_COM_WRITE Request

Upon receipt of an SMB_COM_WRITE Request (section 2.2.4.12.1), the server MUST perform the following actions:

  • Verify the FID, which represents an open regular file. If the Open is not found in Server.Connection.FileOpenTable, the server MUST return an error response with a Status of STATUS_INVALID_HANDLE (ERRDOS/ERRbadfid).

  • Verify the UID as described in section 3.3.5.2, and ensure that the user has permission to write to the file. If the user does not have permission to write to the file, the server MUST send an error response with a status of STATUS_ACCESS_DENIED (ERRDOS/ERRnoaccess) and MUST increase Server.Statistics.sts0_permerrors by 1.

  • If the UID presented is different from the UID that opened the file, the server MUST send the error response with a Status of STATUS_INVALID_HANDLE (ERRDOS/ERRbaduid).

  • In the file identified by the FID, the server MUST perform a seek to the offset specified in the WriteOffsetInBytes field in the request.

  • The server MUST write CountOfBytesToWrite bytes sequentially from the Data field in the request to the file. Any failure that causes less than CountOfBytesToWrite bytes to be written SHOULD result in an error response to the client.<263>

  • If the EstimateOfRemainingBytesToBeWritten field is nonzero in the request, the server MAY use the value provided to perform implementation-specific optimizations, such as preallocating disk space or preparing additional buffers to receive the remaining data.

If FID represents a disk file, and the request specifies a byte range beyond the current end of file, the file MUST be extended. If Offset is beyond the end of file, the "gap" between the current end of file and Offset is filled with null padding bytes. If CountOfBytesToWrite is zero, the file is truncated or extended to the length specified by Offset.

In the event of an error, the server MUST send an error response message. Otherwise, the server MUST construct an SMB_COM_WRITE Response (section 2.2.4.12.2) message. The CountOfBytesWritten field MUST contain the number of bytes written to the file. This value SHOULD be equal to CountOfBytesToWrite. If the number of bytes actually written (CountOfBytesWritten) differs from the number of bytes requested to be written (CountOfBytesToWrite), and no error is indicated, the server has no resources available with which to satisfy the complete write.

The response MUST be sent to the client as specified in section 3.3.4.1.