views:

190

answers:

3

I need to get the list of all the files on a drive. I am using a recursive solution. But it is taking a lot of time. I was wondering that, is it possible to get the names and location of all the files on a NTFS drive from it's Master File Table? I think it will be very fast. Any suggestions?

+1  A: 

When you get a list of all the files on an NTFS-formatted drive using a recursive solution, you are getting them from the MFT. There should be little disk IO outside of the MFT when simply retrieving a list of filenames and directories.

Before going down the path of determining the format of the MFT (which is available from a variety of places on the Internet) and writing code to read it directly, you should probably profile your code and determine that you aren't already CPU or IO bound.

Grant Wagner
+1  A: 

I have the impression you're imagining some kind of list-like structure in the MFT which you can read in one go with no or minimal seeking.

This is not the case. The MFT uses a type of b-tree to store pathnames. When you scan the directory structure on your disk, you are in fact walking the MFT b-tree; you are doing what you would have to do if you accessed the MFT directly.

Blank Xavier
Actually, you are wrong. The MFT does not use a b-tree. The MFT is a flat list of records. NTFS directories do use some type of binary tree (b+tree?). Reading the MFT could be a quicker solution for the OP, depending on the amount of deleted entries that would have to be ignored, and that you don't need to re-create a usable path-name.
Trevor Harrison
+1  A: 

There is a tool that will search the mft directly, it's called ndff. I have used it before and it is very fast.

Presumably it is possible to do what you want - there is another tool called "Everything" which I guess does the same thing - it also uses the USN change journal to update it's index.

MisterW