The ZwOpenFile routine opens an existing file, device, directory, or volume, and returns a handle for the file object.
NTSTATUS
ZwOpenFile(
OUT PHANDLE FileHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG ShareAccess,
IN ULONG OpenOptions
);
Declared in ntddk.h. Include ntddk.h.
ZwOpenFile either returns STATUS_SUCCESS or an appropriate error status. If it returns an error status, the caller can get more information about the error by checking status information returned in IoStatusBlock.
Driver routines that run in a process context other than that of the system process must set the OBJ_KERNEL_HANDLE attribute for the ObjectAttributes parameter of ZwOpenFile. This restricts the use of the handle returned by ZwOpenFile to processes running only in kernel mode. Otherwise, the handle can be accessed by the process in whose context the driver is running. Drivers can call InitializeObjectAttributes to set the OBJ_KERNEL_HANDLE attribute as follows.
InitializeObjectAttributes(&ObjectAttributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
ZwOpenFile provides a subset of the functionality provided by ZwCreateFile.
Callers of ZwOpenFile must be running at IRQL = PASSIVE_LEVEL.