Freigeben über


3.3.5.15 Receiving an SMB_COM_LOCK_BYTE_RANGE Request

Upon receipt of an SMB_COM_LOCK_BYTE_RANGE Request (section 2.2.4.20.1), 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 3.3.5.2.

  • 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.<264>

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.

If the server cannot immediately grant the lock, the server SHOULD<265> reattempt the lock request for a brief interval. 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 underlying object store returns STATUS_CANCELLED, the server MUST set SMB_Header.Status field of the response to STATUS_FILE_LOCK_CONFLICT (ERRDOS/ERRlock). For any other error, status returned MUST be copied into SMB_Header.Status field of the response. The server MUST set Server.Open.LastFailedLockOffset to LockOffsetInBytes field of the request.

If the lock is successful, the server MUST construct an  SMB_COM_LOCK_BYTE_RANGE Response (section 2.2.4.13.2) message. The response MUST be sent to the client as specified in section 3.3.4.1. 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). The server MUST set Server.Open.LastFailedLockOffset to -1.