Taking a shortcut: You can query properties from a volume, and it will forward to the physical drive

Raymond Chen

Raymond

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.

1 comment

Comments are closed. Login to edit/delete your existing comments