NXFileRangeUnlock

Releases advisory range locks on a file.

Library:LibC
Classification:NKS
Service:File and Directory I/O

Syntax

  #include <nks/fsio.h> 
  
  int NXFileRangeUnlock (
     NXHandle_t      fileHandle,
     unsigned long   flags,
     NXOffset_t      offset,
     NXOffset_t      length);
  

Parameters

fileHandle

(IN) Specifies a file handle (or descriptor), which refers to a system-maintained state description for a file.

flags

(IN) Specifies a qualifier for the unlock operation. Use the following flag:

Flag

Value

Description

NX_RANGE_LOCK_SHARED

0x00000001

Releases a previously held shared lock.

NX_RANGE_LOCK_EXCL

0x00000002

Releases a previously held exclusive lock.

offset

(IN) Specifies the starting offset of the file unlock operation.

length

(IN) Specifies in bytes the length of the file lock, forward from the offset if positive, and backward from the offset if negative.

Return Values

If successful, returns 0 (which is assured if fileHandle is -1). Otherwise, returns one of the following:

Decimal

Hex

Constant

Description

4

0x04

NX_EBADF

fileHandle does not refer to a valid description of a file

9

0x09

NX_EINVAL

The flags parameter or the length parameter is invalid.

105

0x69

NX_ENOCONTEXT

The calling thread has no NKS context.

Remarks

NXFileRangeUnlock releases previously acquired byte range locks (with NXFileRangeLock) on the file specified by fileHandle.

If the lock type does not match the lock type of the range being unlocked, the call will fail.Sub-range unlocking is not permitted. That is, the values specified in the parameters offset and length must match the values specified in an earlier lock acquire call. Also, lock ownership is tied to the file handle with which the lock was acquired and not to the file. Specifically, this means that if the same file is opened twice by a virtual machine, and a byte range lock is acquired using one handle, and the other file handle is closed, byte range locks acquired with the open file handle are not automatically released. This also means that locks acquired via one file handle cannot be released via another file handle, even if both file handles correspond to the same file.

For locking and unlocking purposes, a byte range lock's owner is fully described by <virtual machine, file handle, offset, length>.Closing a file handle, which has established byte range locks, results in the locks acquired using that file handle to be released automatically.

NOTE:Locks acquired on the same file via a different file handle are not disturbed.

To prevent unexpected results, only locks acquired via NXFileRangeLock should be released using this function. Use NXFileRangeUnlockEx to release locks acquired via NXFileRangeLockEx.

See Also