IoGetDeviceDirectory function

Returns a handle to a directory on disk, in which drivers can store files. The files in that directory apply to a specific device instance.

Syntax

NTSTATUS IoGetDeviceDirectory(
  PDEVICE_OBJECT        PhysicalDeviceObject,
  DEVICE_DIRECTORY_TYPE DirectoryType,
  ULONG                 Flags,
  PVOID                 Reserved,
  PHANDLE               DeviceDirectoryHandle
);

Parameters

PhysicalDeviceObject

[In] A pointer to the physical device object being queried in the device stack of a particular device instance. Must not be NULL.

DirectoryType

[In] A _DEVICE_DIRECTORY_TYPE-type value that indicates the type of requested directory.

Flags

[In] Must be 0.

Reserved

[In] Reserved. Must be NULL.

DeviceDirectoryHandle

[Out] A pointer to a variable that receives a HANDLE to the requested device directory. The caller must not pass NULL.

Return Value

Returns an appropriate NTSTATUS value. Possible values include:

Error code Description
STATUS_SUCCESS The call successfully opened a handle to the requested device directory.
STATUS_INVALID_PARAMETER An input value to this function is invalid. For example, PhysicalDeviceObject or DeviceDirectoryHandle is NULL; Flags is not 0; Reserved is not NULL.

Remarks

If IoGetDeviceDirectory is called before the required disks and volumes have been started, the function does not open a handle and returns an error.

Drivers typically use ZwOpenFile and ZwCreateFile to access/create files. One of the parameters for those functions is an OBJECT_ATTRIBUTES structure, which contains the object name and a root directory. If the root directory is NULL, then the object name must be a fully qualified path. However, if you provide a handle for the root directory, then the object name must be relative to the object (in the case of files, the directory), that the handle represents.

After the IoGetDeviceDirectory call succeeds, use the received HANDLE as a root directory in the OBJECT_ATTRIBUTES that you are passing to a ZwOpenFile and ZwCreateFile.

The driver must call ZwClose to close the received handle when access is no longer required.

Callers of IoGetDeviceDirectory must be running at IRQL = PASSIVE_LEVEL in the context of a system thread.

Requirements

   
Header wdm.h
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL PASSIVE_LEVEL

See Also

ZwOpenFile

ZwCreateFile

ZwClose

_DEVICE_DIRECTORY_TYPE

OBJECT_ATTRIBUTES

InitializeObjectAttributes