220.127.116.11 Application Requests Locking of an Array of Byte Ranges
The application provides:
A handle to the Open identifying a file or named pipe.
An array of byte ranges to lock. For each range, the application provides:
A starting offset, in bytes.
A length, in bytes.
Whether the range is to be locked exclusively, or shared.
Whether the lock request is to wait until the lock can be acquired to return, or whether it is to fail immediately if the range is locked by another Open.
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 18.104.22.168. If the reconnect succeeds, the lock 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 lock operation.
The Command field is set to SMB2 LOCK.
The MessageId field is set as specified in section 22.214.171.124.3.
The SessionId field is set to Open.TreeConnect.Session.SessionId.
The TreeId field is set to Open.TreeConnect.TreeConnectId.
The SMB2 LOCK Request MUST be initialized as follows:
The FileId field is set to Open.FileId.
The LockCount field is set to the number of byte ranges being locked.
For each range being locked, the client creates an SMB2_LOCK_ELEMENT structure and places it in the Locks array of the request, setting the following values:
The offset is set to the offset of the range being locked.
The length is set to the length of the range to be locked.
If the lock is to be acquired shared, the client sets the SMB2_LOCKFLAG_SHARED_LOCK bit in the Flags field.
If the lock is to be acquired exclusively, the client sets the SMB2_LOCKFLAG_EXCLUSIVE_LOCK bit in the Flags field.
If the lock is to fail immediately if the range is already locked, the client sets the SMB2_LOCKFLAG_FAIL_IMMEDIATELY bit in the Flags field. If the Locks array has more than one element, the client MUST set SMB2_LOCKFLAG_FAIL_IMMEDIATELY.
If any of the Booleans Open.ResilientHandle, Open.IsPersistent, or Connection.SupportsMultiChannel is TRUE, the client MUST do the following:
Scan through Open.OperationBuckets and find an entry with its Free field set to TRUE. If no such element could be found, an implementation-specific error MUST be returned to the application.
Set the Free element of the chosen entry to FALSE.
The fields of the SMB2 lock request MUST be set as follows:
LockSquenceIndex is set to the index value of the chosen entry.
LockSequenceNumber is set to the SequenceNumber of the chosen entry.
Otherwise the client MUST set LockSequenceIndex and LockSequenceNumber to 0.
The request MUST be sent to the server.