The NtQueryDirectoryFile routine returns various kinds of information about files in the directory specified by a given file handle.
__kernel_entry NTSYSCALLAPI NTSTATUS NtQueryDirectoryFile( HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, PUNICODE_STRING FileName, BOOLEAN RestartScan );
A handle returned by NtCreateFile or NtOpenFile for the file object that represents the directory for which information is being requested. The file object must have been opened for asynchronous I/O if the caller specifies a non-NULL value for Event or ApcRoutine.
An optional handle for a caller-created event. If this parameter is supplied, the caller will be put into a wait state until the requested operation is completed and the given event is set to the Signaled state. This parameter is optional and can be NULL. It must be NULL if the caller will wait for the FileHandle to be set to the Signaled state.
An address of an optional, caller-supplied APC routine to be called when the requested operation completes. This parameter is optional and can be NULL. If there is an I/O completion object associated with the file object, this parameter must be NULL.
An optional pointer to a caller-determined context area if the caller supplies an APC or if an I/O completion object is associated with the file object. When the operation completes, this context is passed to the APC, if one was specified, or is included as part of the completion message that the I/O Manager posts to the associated I/O completion object.
This parameter is optional and can be NULL. It must be NULL if ApcRoutine is NULL and there is no I/O completion object associated with the file object.
A pointer to an IO_STATUS_BLOCK structure that receives the final completion status and information about the operation. For successful calls that return data, the number of bytes written to the FileInformation buffer is returned in the structure's Information member.
A pointer to a buffer that receives the desired information about the file. The structure of the information returned in the buffer is defined by the FileInformationClass parameter.
The size, in bytes, of the buffer pointed to by FileInformation. The caller should set this parameter according to the given FileInformationClass.
The type of information to be returned about files in the directory. One of the following.
|FileBothDirectoryInformation||Return a FILE_BOTH_DIR_INFORMATION structure for each file.|
|FileDirectoryInformation||Return a FILE_DIRECTORY_INFORMATION structure for each file.|
|FileFullDirectoryInformation||Return a FILE_FULL_DIR_INFORMATION structure for each file.|
|FileIdBothDirectoryInformation||Return a FILE_ID_BOTH_DIR_INFORMATION structure for each file.|
|FileIdFullDirectoryInformation||Return a FILE_ID_FULL_DIR_INFORMATION structure for each file.|
|FileNamesInformation||Return a FILE_NAMES_INFORMATION structure for each file.|
|FileObjectIdInformation||Return a FILE_OBJECTID_INFORMATION structure for each file. This information class is valid only for NTFS volumes on Windows 2000 and later versions of Windows.|
|FileReparsePointInformation||Return a single FILE_REPARSE_POINT_INFORMATION structure for the directory.|
Set to TRUE if only a single entry should be returned, FALSE otherwise. If this parameter is TRUE, NtQueryDirectoryFile returns only the first entry that is found.
An optional pointer to a caller-allocated Unicode string containing the name of a file (or multiple files, if wildcards are used) within the directory specified by FileHandle. This parameter is optional and can be NULL.
If FileName is not NULL, only files whose names match the FileName string are included in the directory scan. If FileName is NULL, all files are included.
The FileName is used as a search expression and is captured on the very first call to NtQueryDirectoryFile for a given handle. Subsequent calls to NtQueryDirectoryFile will use the search expression set in the first call. The FileName parameter passed to subsequent calls will be ignored.
Set to TRUE if the scan is to start at the first entry in the directory. Set to FALSE if resuming the scan from a previous call.
When the NtQueryDirectoryFile routine is called for a particular handle, the RestartScan parameter is treated as if it were set to TRUE, regardless of its value. On subsequent NtQueryDirectoryFile calls, the value of the RestartScan parameter is honored.
The NtQueryDirectoryFileroutine returns STATUS_SUCCESS or an appropriate error status. Note that the set of error status values that can be returned is file-system-specific. NtQueryDirectoryFilealso returns the number of bytes actually written to the given FileInformation buffer in the Information member of IoStatusBlock.
The NtQueryDirectoryFile routine returns information about files that are contained in the directory represented by FileHandle.
If provided, the value of the FileName parameter determines the entries that are included in the directory scan for all subsequent calls to NtQueryDirectoryFile for a given FileHandle.
If there is at least one matching entry, NtQueryDirectoryFile creates a FILE_XXX_INFORMATION structure for each entry and stores them in the buffer.
Assuming that at least one matching directory entry is found, the number of entries for which information is returned is the smallest of the following:
One entry, if ReturnSingleEntry is TRUE and FileName is NULL.
The number of entries that match the FileName string, if FileName is not NULL. (Note that if the string contains no wildcards, there can be at most one matching entry.)
The number of entries whose information fits into the specified buffer.
The number of entries contained in the directory.
On each call, NtQueryDirectoryFile returns as many FILE_XXX_INFORMATION structures (one per directory entry) as can be contained entirely in the buffer pointed to by FileInformation. On the first call, NtQueryDirectoryFile returns STATUS_SUCCESS only if the output buffer contains at least one complete structure. On subsequent calls, if the output buffer contains no structures, NtQueryDirectoryFile returns STATUS_SUCCESS but sets IoStatusBlock->Information = 0 to notify the caller of this condition. In this case, the caller should allocate a larger buffer and call NtQueryDirectoryFile again. No information about any remaining entries is reported. Thus, except in the cases listed above where only one entry is returned, NtQueryDirectoryFile must be called at least twice to enumerate the contents of an entire directory.
When calling NtQueryDirectoryFile, you may see changes made to the directory that occur in parallel with NtQueryDirectoryFile calls. This behavior is dependent on the implementation of the underlying file system.
The final call to NtQueryDirectoryFile returns an empty output buffer and reports an appropriate status value such as STATUS_NO_MORE_FILES.
If NtQueryDirectoryFile is called multiple times on the same directory and some other operation changes the contents of that directory, any changes may or may not be seen, depending on the timing of the operations.
NtQueryDirectoryFilereturns zero in any member of a FILE_XXX_INFORMATION structure that is not supported by the file system.
Callers of NtQueryDirectoryFile must be running at IRQL = PASSIVE_LEVEL and with special kernel APCs enabled.
For information about other file information query routines, see File Objects.
|Windows version||Available starting with Windows XP.|
|Header||ntifs.h (include Ntifs.h)|
|IRQL||PASSIVE_LEVEL (see Remarks section)|
|DDI compliance rules||PowerIrpDDis, HwStorPortProhibitedDDIs|