NtLockFile - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTIOAPI_H

NTSYSCALLAPI
NTSTATUS
NTAPI
NtLockFile(
    _In_ HANDLE FileHandle,
    _In_opt_ HANDLE Event,
    _In_opt_ PIO_APC_ROUTINE ApcRoutine,
    _In_opt_ PVOID ApcContext,
    _Out_ PIO_STATUS_BLOCK IoStatusBlock,
    _In_ PLARGE_INTEGER ByteOffset,
    _In_ PLARGE_INTEGER Length,
    _In_ ULONG Key,
    _In_ BOOLEAN FailImmediately,
    _In_ BOOLEAN ExclusiveLock
    );

#endif

View code on GitHub
#ifndef _NTZWAPI_H

NTSYSCALLAPI
NTSTATUS
NTAPI
ZwLockFile(
    _In_ HANDLE FileHandle,
    _In_opt_ HANDLE Event,
    _In_opt_ PIO_APC_ROUTINE ApcRoutine,
    _In_opt_ PVOID ApcContext,
    _Out_ PIO_STATUS_BLOCK IoStatusBlock,
    _In_ PLARGE_INTEGER ByteOffset,
    _In_ PLARGE_INTEGER Length,
    _In_ ULONG Key,
    _In_ BOOLEAN FailImmediately,
    _In_ BOOLEAN ExclusiveLock
    );

#endif

View code on GitHub

This function is documented in Windows Driver Kit here and here.


FileHandle

HANDLE to File Object opened with FILE_READ_DATA access.

LockGrantedEvent

Optional HANDLE to Event Object, which is signaled when lock is created (typically used with ReturnImmediately parameter set to TRUE).

ApcRoutine

APC routine executed when lock is granted.

ApcContext

Optional parameter for ApcRoutine.

IoStatusBlock

IO result of call.

ByteOffset

Offset (in bytes) to begin of file region to lock.

Length

Length of region to lock, in bytes.

Key

Pointer to user's defined 4-bytes key associated with this lock. It can be used in multi-thread process to allow reading or writing data only for one specified thread, with known Key value.

ReturnImmediately

If TRUE, function returns immediately. Caller is informed about lock creation by LockGrantedEvent or by executing ApcRoutine.

ExclusiveLock

If set, all read and write operation are denied for other processes. If not, only write operation is denied.

Documented by

See also