CIFS File Locking

Locking is a mechanism that allows a client process to prevent read/write access to regions of a file by other processes. A client request defines a region by specifying its Length and Offset values within a file. The locked regions are associated with the file handle FID and can be anywhere in the logical file. Only processes using the FID value specified in the locking request have access to the locked bytes.

Locking a region will fail entirely if any subregions or overlapping regions are already locked. The Timeout field defines the maximum amount of time the server will wait for the region(s) specified to become unlocked.

A Timeout value of 0 indicates that the server should not wait, and should report failure if any region specified is locked. A Timeout value of -1 indicates that the server should wait as long as it takes for each region specified to become unlocked so that it may be again locked by this protocol. Any other value of Timeout specifies the maximum number of milliseconds to wait for all lock region(s) specified to become available.

File Locking Type

If LockType has the LOCKING_ANDX_SHARED_LOCK flag set, the lock is specified as a shared lock. Closing a file with locks still in force causes the locks to be released in no defined order. If the one and only member of the Locks vector has the LOCKING_ANDX_CANCEL_LOCK flag set in the LockType field, the client is requesting the server to cancel a previously requested, but not yet responded to, lock. If LockType has the LOCKING_ANDX_CHANGE_LOCKTYPE flag set, the client is requesting that the server change the lock type from a shared lock to an exclusive lock or vice versa. If the server cannot do this, it must reject this request.

If LockType has the LOCKING_ANDX_LARGE_FILES flag set and if the negotiated protocol is NTLM 0.12 or later, then the Locks and Unlocks vectors are in the Large File LOCKING_ANDX_RANGE format. This allows specification of 64-bit offsets for very large files.

See Also

Royalty-Free CIFS Technical Reference License Agreement