Jump to content
  • Advertisement
Sign in to follow this  
Syranide

Determining physical disk home for files (C++)

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Uhm, unsure of what I would call it. However, simple, I want to be able to tell on which _physical disk_ a file resides on (that is, "C:\log.txt" and "D:\log.txt" reside on the same physical disk or two separate), it doesn't really matter what I get as long as I can tell whether two or more files reside on the same physical disk. However, going through the documentation, all I could find was volume information, which isn't any satisfying as each disk could have many partitions/volumes. After some additional research I figured I could get some device data using DeviceIoControl, whether or not it is possible, it doesn't really help me in the end, as the file could potentially reside in a directory mount, in which case using the drive letter will produce improper results. Does anyone have any information/knowledge about this?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
GetVolumeInformation

Share this post


Link to post
Share on other sites
That is pretty much what I explained, volume information only gives information to whether they are on the same volume or not, but a physical disk can and commonly has many volumes.

Share this post


Link to post
Share on other sites
Get the volume for each file, for example C:.

Open this using CreateFile and use the returned handle to called DeviceIOControl with the following control code:

IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS

This will give you a VOLUME_DISK_EXTENTS structure which contains one or more DISK_EXTENT structures. This structure tell you the physical disc that a volume is one.

Compare the two and see if both files are on the same physical disc.

Share this post


Link to post
Share on other sites
Thank you so very much.

I totally overlooked the volume control codes in DeviceIoControl.
Got it working with determining which drive letter belongs to which disk using what you said.

Gonna fiddle around little and see if I can somehow get accurate information on directory mount points too (as files could potentially be on C: disk1 but been mounted as disk2 using directory mounts).

Share this post


Link to post
Share on other sites
Why do you want to know? I'd be very suspicious of this, mostly because there's no way it can be reliable in all situations.

For example, what happens when you've got a RAID configuration? One file could span multiple physical disks in that case...

Share this post


Link to post
Share on other sites
The reason I want to know is basically, I want to be able to read from multiple disks simultaneously, and, if I happen to read from the same physical disk, well, then it gets really bad with horrible speeds.

Accurate? Might be true, but I'm very close now to determining a from what disk a certain file is on, even for mount points. And, as far as I can see, it shouldn't pose any problems unless they make drastical changes.

RAID, yes, I guess there could be some hidden problem (perhaps I was slightly unclear of this, but being a minor concern to other I left it out to avoid confusion, if they use RAID I don't care, as long as I'm not reading 2 files from the same disks), so no, shouldn't really pose a problem as I rely on the system to give me the information for a volume/drive. And, really, it can only give me one number regardless of RAID or not, and that is all I want.

EDIT: sure, I'm not saying my solution doesn't have flaws, but as far as I've come, it seems rigid enough to work for my purpose considering the competitor applications doesn't even support this at all, so, worst case ends up being, same performance as the other.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!