views:

539

answers:

4

Based on a file name, or a file handle, is there a Win-API method of determining what physical sector the file starts on?

A: 

I suspect that there is no such function.

Even if you know where the file starts, what good would it do? The rest of the file could be anywhere as soon as the file is larger than a single sector due to fragmentation.

You would probably need to develop deeper understanding of the file system involved and read the necessary information from the file allocation table or such mechanism.

HS
+1  A: 

You'd have to read the allocation table directly.

Dave Swersky
A: 

No. Why? Because a file system is an abstraction of physical hardware. You don't need to know if you're on a RAM disk, hard drive, CD, or network drive, or if your data is compressed or encrypted -- Windows takes care of these little details for you.

You can always open the physical disk, but you'd need knowledge of the file system used.

What are you trying to accomplish with this?

zildjohn01
A: 

You can get file cluster allocation by sending FSCTL_GET_RETRIEVAL_POINTERS using DeviceIoControl.

KIV