zLockByteRange

Locks a byte range for the specified open file object.

Service:File System Services (64-Bit)
Version:OES 2

Syntax

#include <zPublics.h>

STATUS zLockByteRange(
   Key_t   key,
   Xid_t   xid,
   NINT    mode,
   QUAD    startingOffset,
   QUAD    length,
   NINT    msecTimeout);

Parameters

key

(IN) Specifies the file (as returned by zOpen or zCreate) whose byte range is being locked.

xid

(IN) Specifies the transaction to which the lock is bound. If the requested action is not part of a transaction, pass zNILXID; the lock is then bound to the task specified by the key.

mode

(IN) Specifies the mode of the lock: either zLOCK_SHARED (read lock) or zLOCK_EXCLUSIVE (write lock).

startingOffset

(IN) Specifies the logical byte offset in the file where the lock begins.

length

(IN) Specifies the number of bytes to lock in the file. To lock all the bytes in a file, set startingOffset to 0 and length to zMAX_FILE_SIZE (0xffffffffffffffff: a 64 bit -1).

msecTimeout

(IN) Specifies the number of milliseconds that you are willing to wait to receive the lock. Otherwise, it immediately returns an error if the lock cannot be obtained.

Return Values

zOK

The operation completed successfully.

zERR_LOCK_WAITING

Did not get the lock in the specified amount of time.

non-0

An error occurred (see Section 4.1, Return Values for a description).

Remarks

zLockByteRange locks the number of bytes specified by length, starting at the startingOffset of the file identified by key. A lock bound to a transaction can only be unlocked by either ending or aborting the transaction. When the transaction holding the lock ends on a nested transaction, its parent inherits all the locks of the child. To prevent dirty reads of data and preserve reread semantics, locks are finally released when the root transaction commits.

See Also

zRead, zUnlockByteRange, zWrite