Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Jul 6 '10 at 1:38

This question came from our site for professional and enthusiast programmers.

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.

share|improve this answer

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.

share|improve this answer
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.