#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
);
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
);
View code on GitHub
This function is documented in Windows Driver Kit here and here.
HANDLE
to File Object opened with FILE_READ_DATA
access.
Optional HANDLE
to Event Object, which is signaled when lock is created (typically used with ReturnImmediately
parameter set to TRUE
).
APC routine executed when lock is granted.
Optional parameter for ApcRoutine
.
IO result of call.
Offset (in bytes) to begin of file region to lock.
Length of region to lock, in bytes.
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.
If TRUE
, function returns immediately. Caller is informed about lock creation by LockGrantedEvent
or by executing ApcRoutine
.
If set, all read and write operation are denied for other processes. If not, only write operation is denied.