Hi all !
Does anyone know how to get a directory listing using NtQueryDirectoryFile()
?
Thank you
Hi all !
Does anyone know how to get a directory listing using NtQueryDirectoryFile()
?
Thank you
HTH: Found this old code snippet (circa 1998)…
WCHAR Buffer[8192];
UNICODE_STRING DirectoryName;
OBJECT_ATTRIBUTES DirectoryAttributes;
NTSTATUS Status;
HANDLE DirectoryHandle;
IO_STATUS_BLOCK Iosb;
PFILE_BOTH_DIR_INFORMATION DirInformation;
RtlInitUnicodeString(&DirectoryName, L"\??\C:\Windows")
InitializeObjectAttributes(&DirectoryAttributes,
&DirectoryName,
OBJ_CASE_INSENSITIVE,
0, // absolute
open, no relative directory handle
0); // no
security descriptor necessary
Status = ZwCreateFile(&DirectoryHandle,
(FILE_LIST_DIRECTORY | SYNCHRONIZE),
&DirectoryAttributes,
&Iosb,
0,
0,
FILE_SHARE_VALID_FLAGS, // FULL sharing
FILE_OPEN, // MUST
already exist
(FILE_SYNCHRONOUS_IO_NONALERT |
FILE_DIRECTORY_FILE), // MUST be a directory
0,
0);
if (!NT_SUCCESS(Status)) {
printf(“Unable to open %.*S, error = 0x%x\n”,
DirectoryName.Length / sizeof(WCHAR),
DirectoryName.Buffer, Status);
return Status;
}
//
// We pass NO NAME which is the same as *.*
//
Status = ZwQueryDirectoryFile(DirectoryHandle,
NULL,
0,
// No APC routine
0,
// No APC context
&Iosb,
Buffer,
sizeof(Buffer),
FileBothDirectoryInformation,
TRUE,
NULL,
FALSE);
if (!NT_SUCCESS(Status)) {
printf(“Unable to query directory contents, error 0x%x\n”,
Status);
return Status;
}
DirInformation = (PFILE_BOTH_DIR_INFORMATION)Buffer;
// Loop over all files
for (;
{
//
// Dump the full name of the file. We could dump the other
information
// here as well, but we’ll keep the example shorter instead.
//
printf(" %.*S\n", DirInformation->FileNameLength /
sizeof(WCHAR),
&DirInformation->FileName[0]);
//
// If there is no offset in the entry, the buffer has been
exhausted.
//
if (DirInformation->NextEntryOffset == 0) {
// Re-fill buffer
Status = ZwQueryDirectoryFile(DirectoryHandle,
NULL,
0,
// No APC routine
0,
// No APC context
&Iosb,
Buffer,
sizeof(Buffer),
FileBothDirectoryInformation,
FALSE,
NULL,
FALSE);
if (!NT_SUCCESS(Status)) {
if (Status == STATUS_NO_MORE_FILES) break;
printf(“Unable to query directory contents,
error 0x%x\n”, Status);
return Status;
}
DirInformation = (PFILE_BOTH_DIR_INFORMATION)Buffer;
continue;
}
//
// Advance to the next entry.
//
DirInformation =
(PFILE_BOTH_DIR_INFORMATION)(((PUCHAR)DirInformation) +
DirInformation->NextEntryOffset);
}
NtClose(DirectoryHandle);
-----Original Message-----
From: Marcos Velasco - UOL [mailto:xxxxx@uol.com.br]
Sent: Wednesday, October 13, 2004 5:47 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] NtQueryDirectoryFile…
Hi all !
Does anyone know how to get a directory listing using NtQueryDirectoryFile()
?
Thank you
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
You are currently subscribed to ntfsd as: xxxxx@livevault.com To unsubscribe
send a blank email to xxxxx@lists.osr.com