How to get the relation between (hd0,6) and D:\ without guessing?
3 Answers
You can get device number and partition number using IOCTL_STORAGE_GET_DEVICE_NUMBER:
HANDLE h = ::CreateFile(L"\\\\.\\d:", 0, 0, NULL, OPEN_EXISTING, 0, NULL);
STORAGE_DEVICE_NUMBER info = {};
DWORD bytesReturned = 0;
::DeviceIoControl(h, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &info, sizeof(info), &bytesReturned, NULL);But be aware that logical volume can be on several physical disks.
4In a command prompt:
diskpart
list disk
select disk x
list partitionwhere x is the disk number you wish to select.
I just had to fix a boot.ini when it couldn't boot a WinXP's install --after creating new primary partitions in its drive.
Turns out WinXP was located in a logical volume, and NT's loader first assigns a number to primary partitions and then to logical volumes (arguably by sector order in both cases), so by creating new primary partitions (even at the end of the disk) WinXP's partition number changed.
As for disk number, I don't really know but I'd expect it to be even more obscure. I seem to recall SATA controllers are numbered before PATAs, I'd imagine by connector order (and master status for PATA drives), but don't quote me on this.