Receiving an SMB_COM_LOCK_BYTE_RANGE Request

Upon receipt of an SMB_COM_LOCK_BYTE_RANGE Request (section, the server MUST verify the FID and the UID and MUST verify that the user has, at minimum, read permission on the file.

  • The FID is verified by performing a looking up in the Server.Connection.FileOpenTable to find the corresponding Open. If the Open is not found, the FID is not valid and the server MUST return an error response to the client with a Status of STATUS_INVALID_HANDLE (ERRDOS/ERRbadfid).

  • The UID is validated as described in section

  • If the user does not have permission to perform a byte range lock, the server MUST return an error response to the client with a Status of STATUS_ACCESS_DENIED (ERRDOS/ERRnoaccess) and MUST increase Server.Statistics.sts0_permerrors by 1.

  • If the UID that is 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).

The server MUST then attempt to obtain a byte-range exclusive lock from the underlying object store on a contiguous range of bytes in the file specified by the FID in the request starting at LockOffsetInBytes and extending for CountOfBytesToLock bytes.<263>

This command is used to explicitly lock a contiguous range of bytes in an open regular file. Locks prevent attempts to lock, read, or write the locked portion of the file by other clients or PIDs from the same client.

  • Adjacent locks cannot be combined.

  • Locks MUST NOT overlap.

  • Offsets beyond the current end of file can be locked. Such locks MUST NOT cause allocation of additional file space.

  • Locks can be unlocked only by the PID that obtained the lock.

See [FSBO] section 3 for details of byte range lock semantics.

In the event of an error, including failure to grant the lock on the byte range, the server MUST send an error response message. If the server cannot immediately grant the lock, the server SHOULD<264> reattempt the lock request for a brief interval, returning an error response with a Status of STATUS_FILE_LOCK_CONFLICT (ERRDOS/ERRlock) to the client if the lock cannot be granted.

If the lock is successful, the server MUST construct an  SMB_COM_LOCK_BYTE_RANGE Response (section message. The response MUST be sent to the client as specified in section An entry for the newly-granted byte-range lock MUST be added to Server.Open.Locks. The type of the lock MUST be exclusive, and the entry MUST be formatted with a 32-bit offset (LOCKING_ANDX_RANGE32).