问题描述:

I would like to find out what physical media a file is on (either by filename or by handle).

I've read here that I can determine the physical drive of a given partition handle with a DeviceIoControl call.

But how do I get a partition handle from a filename? (Because NTFS allows to mount partitions in folders, I can't simply go by drive letter.)

The reason I'm asking is that copying a file to another physical drive is fastest when using asynchronous methods, but on the same drive it is fastest when done synchronously with a larger buffer. I want to write a function to determine the optimum copying algorithm for a given file and destination.

网友答案:

Volumes in Windows are generally mapped to drive letters (except on network shares).

You can create a volume file device handle on the source and destination using CreateFile() just passing in the drive letter path (ie: \\.\C:\). Use the returned handle with DeviceIoControl(). Compare the physical drives between the source and destination, and you should be good.

Discussion explained here: "To obtain the physical drive identifier for a volume, open ..." http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx

相关阅读:
Top