ZwOpenFile routine
The ZwOpenFile routine opens an existing file, directory, device, or volume.
Syntax
NTSTATUS ZwOpenFile( _Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions );
Parameters
- FileHandle [out]
-
Pointer to a HANDLE variable that receives a handle to the file.
- DesiredAccess [in]
-
Specifies an ACCESS_MASK value that determines the requested access to the object. For more information, see the DesiredAccess parameter of ZwCreateFile.
- ObjectAttributes [in]
-
Pointer to an OBJECT_ATTRIBUTES structure that specifies the object name and other attributes. Use InitializeObjectAttributes to initialize this structure. If the caller is not running in a system thread context, it must set the OBJ_KERNEL_HANDLE attribute when it calls InitializeObjectAttributes.
- IoStatusBlock [out]
-
Pointer to an IO_STATUS_BLOCK structure that receives the final completion status and information about the requested operation.
- ShareAccess [in]
-
Specifies the type of share access for the file. For more information, see the ShareAccess parameter of ZwCreateFile.
- OpenOptions [in]
-
Specifies the options to apply when opening the file. For more information, see the CreateOptions parameter of ZwCreateFile.
Return value
ZwOpenFile returns STATUS_SUCCESS or the appropriate NTSTATUS error code. In the latter case, the caller can find more information about the cause of the failure by checking the IoStatusBlock parameter.
Remarks
ZwOpenFile supplies a handle that the caller can use to manipulate a file's data, or the file object's state and attributes. ZwOpenFile provides a subset of the functionality provided by ZwCreateFile. For more information, see Using Files in a Driver.
Once the handle pointed to by FileHandle is no longer in use, the driver must call ZwClose to close it.
If the caller is not running in a system thread context, it must ensure that any handles it creates are private handles. Otherwise, the handle can be accessed by the process in whose context the driver is running. For more information, see Object Handles.
Callers of ZwOpenFile must be running at IRQL = PASSIVE_LEVEL and with special kernel APCs enabled.
Note If the call to this function occurs in user mode, you should use the name "NtOpenFile" instead of "ZwOpenFile".
Requirements
|
Version | Available starting with Windows 2000. |
|---|---|
|
Header |
|
|
Library |
|
|
IRQL | PASSIVE_LEVEL (see Remarks section) |
|
DDI compliance rules | PowerIrpDDis, HwStorPortProhibitedDDIs |
See also
Send comments about this topic to Microsoft
Build date: 5/2/2013