>My driver would know the assigned drive letters *some how*.
No. It would not.
The user mode app will send a custom IOCTL to query this data
No, it will determine it using:
a) get the volume instance (i.e. drive letter), you can enum all volumes using volmgmt API
b) from volume instance, send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, it will return the StorageDeviceNumber of the underlying physical disk.
c) open (\.\PhysicalDrive%d, StorageDeviceNumber), and read the MBR signature (either faked by your driver or contained in your image file)
d) the driver must also know all of its MBR signatures. Then you send the custom IOCTL of “get vdisk info by MBR signature” to your driver.
For GPT case, use GPT GUID instead of MBR signature.
To simplify all of this, you can read about IOCTL_STORAGE_QUERY_PROPERTY, this will probably allow some piece of data which will replace the MBR signature for c) and d).
Also, instead of c), you can:
c1) enumerate all physical disks in the system using SetupDi APIs
c2) call CM_Get_Parent for each to filter away the disks not belonging to your driver
c3) call IOCTL_STORAGE_GET_DEVICE_NUMBER on each, and match this to device number from item b) to corellate volumes/partitions/drive letters to the physical disk.
c4) call IOCTL_SCSI_GET_ADDRESS to get bus/target/LUN (faked by your driver)
c5) call your custom IOCTL about “get vdisk info by bus/target/LUN”
As you can see, the StorageDeviceNumber (NOTE: not persistent across boots and even across disk plug/unplug) is the standard way of corellating volumes/partitions to physical disks.
And, to corellate phys disk to your driver internal instance, you can use bus/target/LUN, or MBR signature, or some storage propery (possibly).
–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com