Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to directly query the file system device driver for listing out the files in a directory?

I'm currently using FindFirstFile, FindNextFile API to recursively iterate through directories for searching files based on a given criteria. I noticed that "dir /s" command gives better performance than my program. I'm tried checking out the events in process monitor and it looks like cmd.exe/dir command is directly querying the disk device driver. Is there any way I can achieve some thing similar with DeviceIOControl() ?. I'm very new to device drivers though not new to programming. Attaching procmon output for reference:

alt text

Regards,

like image 630
ivymike Avatar asked Aug 30 '10 19:08

ivymike


4 Answers

Use FindFirstFile and FindNextFile. That's the API, using DeviceIOControl directly is either a mess or not possible (don't know exactly).

Have you tried FindFirstFileEx and it's FIND_FIRST_EX_LARGE_FETCH flag and FindExInfoBasic info level?

like image 182
Michael Avatar answered Nov 15 '22 02:11

Michael


You can call ZwQueryDirectoryFile directly. Going further down to the driver level would require sending a bunch of IRPs and would probably be an overkill.

like image 2
Eugene Mayevski 'Callback Avatar answered Nov 15 '22 03:11

Eugene Mayevski 'Callback


"dir /s" is using FindFirst/Next. It doesn't do any special magic to enumerate the files.

QueryDirectory appears to be how Procmon exposes what FindFirst/Next does to get its data from the file system.

like image 2
jrtipton Avatar answered Nov 15 '22 03:11

jrtipton


http://ntfs-search.sourceforge.net/

It works well. And faster.
It opens a volume, and parses directly.

But it only works on NTFS.

like image 1
Benjamin Avatar answered Nov 15 '22 03:11

Benjamin