简体   繁体   中英

How do I mapping usb storage device path to physicaldrive?

I get the usb device path from

SetupDiGetDeviceInterfaceDetail()

and I can get the device path such like

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

but I want to map device path to physical drvie

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

or inverse I can map physical drvie to device path
Is there any way to do that?

oh, I found it. put the HANDLE into DeviceIoControl and use 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
);

and the number.DeviceNumber is the PhysicalDrive number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM