NTSTATUS
ZwReadFile(
IN HANDLE FileHandle,
IN HANDLE Event, /*
optional */
IN PIO_APC_ROUTINE ApcRoutine, /*
optional */
IN PVOID ApcContext, /*
optional */
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID Buffer,
IN ULONG Length,
IN PLARGE_INTEGER ByteOffset, /*
optional */
IN PULONG Key /* optional */
);
Data can be read from an opened file with ZwReadFile.
If the call to ZwCreateFile set either of the CreateOptions flags FILE_SYNCHRONOUS_IO_ALERT or FILE_SYNCHRONOUS_IO_NONALERT, the I/O Manager maintains the current file position. If so, the caller of ZwReadFile can specify that the current file position offset be used instead of an explicit ByteOffset value in either of the following ways:
ZwReadFile updates the current file position by adding the number of bytes read when it completes the read operation, if it is using the current file position maintained by the I/O Manager.
Even when the I/O Manager is maintaining the current file position, the caller
can reset this position by passing an explicit ByteOffset value to ZwReadFile.
Doing this automatically changes the current file position to that ByteOffset,
performs the read, and then updates the position according to the number of
bytes actually read. This technique gives the caller atomic seek-and-read
service.
ZwReadFile either returns STATUS_SUCCESS or an appropriate error status. The number of bytes actually read from the file is returned in the Information member of the IoStatusBlock.
Callers of ZwReadFile must have already called ZwCreateFile with the DesiredAccess flag FILE_READ_DATA set, either explicitly or by setting this flag with GENERIC_READ.
If the preceding call to ZwCreateFile set the CreateOptions flag FILE_NO_INTERMEDIATE_BUFFERING, certain restrictions on the parameters to ZwReadFile are enforced. See ZwCreateFile for specifics.
ZwReadFile begins reading from the given ByteOffset or the current file position into the given Buffer. It terminates the read operation under one of the following conditions:
If the caller opened the file with the DesiredAccess SYNCHRONIZE flag set, the caller can wait on this routine’s setting the given FileHandle to the Signaled state.
Callers of ZwReadFile must be running at IRQL PASSIVE_LEVEL.
KeInitializeEvent, ZwCreateFile, ZwQueryInformationFile, ZwSetInformationFile, ZwWriteFile