Export (0) Print
Expand All
Expand Minimize

3.2.4.7 Application Requests Writing to a File or Named Pipe

The application provides:

  • A handle to the Open identifying a file or named pipe.

  • The offset, in bytes, from where data should be written.

  • The number of bytes to write.

  • A buffer containing the bytes to be written.

  • WriteThrough, a Boolean flag indicating whether the data has to be written to persistent store on the server before a response is sent (optional).

  • UnbufferedWrite, a Boolean flag indicating whether the write data is not to be buffered on the server (optional).

If the handle is invalid, or if no Open referenced by the handle is found, the client MUST return an implementation-specific error code. If the handle is valid and Open is found, the client MUST proceed as follows.

If Open.Connection is NULL, and Open.Durable is TRUE, the client SHOULD attempt to reconnect to this open as specified in section 3.2.4.4. If the reconnect succeeds, the write MUST be retried. If it fails, the error code MUST be returned to the application.

If Open.Connection is NULL and Open.Durable is FALSE, the client MUST fail the write operation.

If Open.Connection is not NULL, the client initializes an SMB2 WRITE Request, following the syntax specified in section 2.2.21. The SMB2 header MUST be initialized as follows:

  • The Command field is set to SMB2 WRITE.

  • The SessionId field is set to Open.TreeConnect.Session.SessionId.

  • The TreeId field is set to Open.TreeConnect.TreeConnectId.

The SMB2 WRITE Request MUST be initialized as follows:

  • The Length field is set to the number of bytes the application requested to write.

  • The Offset field is set to the offset within the file, in bytes, at which the application requested the write to start.

  • The FileId field is set to Open.FileId.

  • The DataOffset field is set to the offset from the beginning of the SMB2 header to the data being written. This value SHOULD be 0x70, which is the default offset for write requests.

  • If Connection.Dialect is not "2.002", and application-supplied WriteThrough is TRUE, the SMB2_WRITEFLAG_WRITE_THROUGH bit in the Flags field MUST be set.

  • If Connection.Dialect is "3.002", and application-supplied UnbufferedWrite is TRUE, the SMB2_WRITEFLAG_WRITE_UNBUFFERED bit in the Flags field MUST be set.

If the number of bytes to write exceeds the Connection.MaxWriteSize, the client MUST split the write into separate write operations no larger than the Connection.MaxWriteSize. The client MAY<114> send these separate writes in any order.

If the Connection is not established in RDMA mode or if the size of the operation is less than or equal to an implementation-specific threshold <115>, then

  • The data being written is copied into the request at DataOffset bytes from the beginning of the SMB2 header.

  • The client MUST fill the bytes, if any, between the beginning of the Buffer field and the beginning of the data (at DataOffset) with zeros.<116>

Otherwise, the interface in [MS-SMBD] section 3.1.4.3 Register Buffer MUST be used to register the buffer on the Connection with read permissions, which will supply the data to be written. The returned list of SMB_DIRECT_BUFFER_DESCRIPTOR_V1 structures MUST be stored in Request.BufferDescriptorList. The following fields of the request MUST be initialized as follows:

  • If Connection.Dialect is "3.000", the Channel field of the request MUST be set to SMB2_CHANNEL_RDMA_V1. If Connection.Dialect is "3.002", the Channel field of the request SHOULD be set to SMB2_CHANNEL_RDMA_V1_INVALIDATE.

  • The returned list of SMB_DIRECT_BUFFER_DESCRIPTOR_1 structures MUST be appended to the SMB2 header.

  • The WriteChannelInfoOffset MUST be set to the offset of the appended list from the beginning of the SMB2 header.

  • The WriteChannelInfoLength MUST be set to the length of the appended list.

  • The Length and DataOffset fields MUST be set to 0.

  • The RemainingBytes field MUST be set to the number of bytes of data being written.

If a client requests writing to a file, Connection.Dialect is not "2.002", and if Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set to ( 1 + (Length – 1) / 65536 ).

The MessageId field in the SMB2 header is set as specified in section 3.2.4.1.3, and the request is sent to the server.

 
Show:
© 2014 Microsoft