How to get the relation between (hd0,6) and D:\ without guessing?

  • Programmatically? In what language? – jeffamaphone Jul 5 '10 at 5:44
  • No requirement for that, I just need to figure a way to know the numbers ... – wamp Jul 5 '10 at 5:57

In a command prompt:


list disk

select disk x

list partition

where x is the disk number you wish to select.


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);

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.

  • I guess it's C, how to compile and run it? – wamp Jul 5 '10 at 6:13
  • Yes, it is C. But you can use any language that is able to call Win32API. The main point is IOCTL_STORAGE_GET_DEVICE_NUMBER. – Sergius Jul 5 '10 at 8:43
  • @Sergius , can you elaborate a little about the header files and libraries to include to build it successfully ? – wamp Jul 5 '10 at 9:17
  • #include <windows.h> – Sergius Jul 5 '10 at 10:38

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy