If you have the handle to a volume, you can issue certain disk ioctls to the volume, and it will forward them to the underlying disk. We saw this earlier when we used IOCTL_
STORAGE_
GET_
DEVICE_
NUMBER
to obtain the physical drive number from a volume. The name of the ioctl is IOCTL_
STORAGE
, but we issued it against a volume anyway.
And as we saw earlier, if the volume does not have a unique physical disk, then the call will fail.
This feature is particularly handy with storage property queries. For example, you can ask what how the drive is connected to the system by querying the volume:
wil::unique_hfile volume = GetVolumeHandleForFile(L"C:\\"); STORAGE_PROPERTY_QUERY query{}; query.PropertyId = StorageAdapterProperty; query.QueryType = PropertyStandardQuery; DWORD bytesWritten; STORAGE_ADAPTER_DESCRIPTOR result{}; if (DeviceIoControl(volume.get(), IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &result, sizeof(result), &bytesWritten, nullptr)) { /* result.BusType tells you how the drive is connected */ }
Next time, we’ll use this to answer a commonly-asked question.
On the topic of shortcuts, QueryDosDevice seems like one.