3.2.4.14.1 Client Requests Read Raw

SMB_COM_READ_RAW is a specialized read command intended to maximize the performance of reading large blocks of data from an open regular file, named pipe, or device. The command permits a server to send a large unformatted data (raw byte stream) message over the SMB transport without requiring the usual SMB response format. It also permits a server to send messages in excess of the maximum buffer size established during protocol negotiation and session setup. To accomplish this, the client and the server enter into a dialog. For the dialog to begin, the client MUST perform the following steps:

  • The client MUST compose the SMB_COM_READ_RAW request as described in section 2.2.4.22. This request advises the server of the total number of bytes that the client attempts to receive in response to the request. The request MUST be sent to the server as described in section 3.2.4.1, with the exception that SMB_COM_READ_RAW and message signing are mutually exclusive. Message signing MUST be disabled in order to perform a raw read.

  • After sending the SMB_COM_READ_RAW request, the client MUST NOT send any other request to the server until the Read Raw response has been completely received. In addition, the client MUST NOT have any outstanding requests pending on the server. Because the server sends a raw data message that does not include the typical SMB Header (section 2.2.3.1), the SMB Protocol cannot guarantee that the client can associate the server's raw data message with the correct corresponding SMB_COM_READ_RAW command request. Therefore, the client MUST guarantee that there are no other SMB requests from the client to the server for the duration of the SMB_COM_READ_RAW command's dialog processing. It might not be possible for the client to distinguish between the raw data and another message if the response to another operation is sent by the server while the client is waiting for the raw data.

  • The client MUST begin waiting for the unformatted data to arrive.

  • The server MUST send the unformatted data message to the client. Because the message contains unformatted raw bytes, the client MUST rely on the SMB transport to determine whether the message was received successfully and to determine the size of the message.

  • After the client has successfully received the unformatted data message, it MAY respond with another SMB_COM_READ_RAW SMB to continue reading raw bytes from the file. The server MUST then respond with another unformatted data message. This cycle MAY continue until the client has read all of the bytes that it requires, an end of file is reached, or an error occurs. To indicate that the end of the file has been reached on a regular file, the server MUST return fewer bytes than the client has requested in the MaxCountOfBytesToReturn field. A Raw Read from a named pipe or device MAY return fewer bytes than the client requested. This does not indicate an end of file on the pipe or device. If a file read error occurs on the server, the server MUST return a zero-length unformatted data message to the client.

    If the server returns fewer bytes than requested by the client in the MaxCountOfBytesToReturn field, the client MAY respond with an alternate file I/O SMB (such as another Read operation or an SMB_COM_SEEK to the current position) using the same FID to determine the error.

  • If the client experiences a transport layer error, all bytes of the message MUST be received and discarded. There is no mechanism to inform the server of the transport error. The client is responsible for taking appropriate action to recover from the transport layer error.

A sample dialog flow is:

Read Raw request/response message flow

Figure 7: Read Raw request/response message flow

The client MUST accept an unformatted data message of up to MaxCountOfBytesToReturn bytes in length. MaxCountOfBytesToReturn is often set to 65,535 to maximize the transfer size and improve efficiency.

SMB Protocol SMB_COM_READ_RAW is not supported over connectionless SMB transports. If SMB_COM_READ_RAW is supported by the server, the CAP_RAW_MODE flag MUST be set in the Capabilities field in the response to the SMB_COM_NEGOTIATE SMB. If the  Client.Connection.SelectedDialect is NT LAN Manager or later, and the response to the SMB_COM_NEGOTIATE SMB has CAP_LARGE_FILES set in the Capabilities field, an additional request format is allowed that accommodates very large files having 64 bit offsets (see the OffsetHigh field in the command description in section 2.2.4.22.1).<205>