如何将USB存储设备路径映射到PhysicalDrive?

时间:2019-01-03 07:41:55

标签: c++ windows usb driver

我从

获取USB设备路径
SetupDiGetDeviceInterfaceDetail()

我可以得到像这样的设备路径

\\?\usbstor#disk&ven_&prod_2307_pram&......

但我想将设备路径映射到物理Drvie

->  \\physicaldrive0,1,2......

或反之,我可以将物理Drvie映射到设备路径
有什么办法吗?

1 个答案:

答案 0 :(得分:0)

哦,我找到了。 将HANDLE放入DeviceIoControl并使用IOCTL_STORAGE_GET_DEVICE_NUMBER

STORAGE_DEVICE_NUMBER number;   //use this to get disk numbers
DWORD readed;                   // discard results
BOOL result = DeviceIoControl(
    hdl,                // handle to device
    IOCTL_STORAGE_GET_DEVICE_NUMBER, // dwIoControlCode
    NULL,                            // lpInBuffer
    0,                               // nInBufferSize
    &number,           // output buffer
    sizeof(number),         // size of output buffer
    &readed,       // number of bytes returned
    NULL      // OVERLAPPED structure
);

和数字。DeviceNumber是PhysicalDrive编号