We help IT Professionals succeed at work.

Driveletter and IDE Channel

Hello,

do anybody know a way to get the IDEChannel from a Drive letter?
I want to know as sample, if Drive F: is Primary or Secondary channel.

As sample I want to build a table:
C: | Primary | 0
D: | Primary| 1
E: | Secondary | 0
F: | Secondary | 1

Maybe with Registry or other way.

Thanks,

OCrana
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
a drive letter in windows normally would not map to an ide channel.

for example if you have one harddisk it could be sata disk and then no ide channel is involved.

or you create one primary partition and 1 extended partion for that disk (channel). and for the extended partition you configure 3 logical drives. then c is the primary partition, d, e, f are the logical drives and all is associated to primary ide channel.

i don't know an api that could go from drive letter to ide channel. the best i know is functions GetVolumeInformation and GetDriveType which would allow to find out whether a drive letter represents a hard disk, cdrom, network share or other.

more info you could get by using system tool diskpart and the command 'list disk'. you also can get that output programmatically by putting the 'list disk' into a textfile and call

system("diskpart /s listdisks.scr > listdisks.out");

Open in new window


where listdisks.scr contains the list command and the partition info is in listdisks.out later.

from diskpart you can get more information about disks, partitions and volumes. for example the commands

select disk 0
detail disk
detail partition
detail volume

Open in new window


would give more detailed disk information like drive letter IDE/SATA such that it is nearly what you want.

Sara
CERTIFIED EXPERT

Commented:
Here is a small extract from WinIoCtl.h

//
// IOCTL_DISK_CONTROLLER_NUMBER returns the controller and disk
// number for the handle.  This is used to determine if a disk
// is attached to the primary or secondary IDE controller.
//

typedef struct _DISK_CONTROLLER_NUMBER {
    DWORD ControllerNumber;
    DWORD DiskNumber;
} DISK_CONTROLLER_NUMBER, *PDISK_CONTROLLER_NUMBER;

Open in new window


So it looks like you can query the info using the Windows Device Driver Kit through a call to DeviceIoControl().

Cheers,
  Chris

CERTIFIED EXPERT

Commented:
Having just looked through the MSDN information, it looks like DeviceIOControl() calls with IOCTL_DISK_CONTROLLER_NUMBER are obsolete, so you might have to use IOCTL_STORAGE_QUERY_PROPERTY to get the information you are after. I will try and dig out the parameters required for a IOCTL_STORAGE_QUERY_PROPERTY query to work.

Cheers,
  Chris
CERTIFIED EXPERT

Commented:
As far as I can tell, if you use IOCTL_STORAGE_QUERY_PROPERTY  with the STORAGE_PROPERTY_QUERY set to StorageDeviceProperty,PropertyStandardQuery then the STORAGE_DEVICE_DESCRIPTOR.RawDeviceProperties[] might contain the information you are after. I don't know and couldn't check as I have no IDE disks on my system.

I wil ltry and get together the code for a DeviceIOControl() call using IOCTL_DISK_CONTROLLER_NUMBER - you can check on your own system if it returns the information you are after.

Cheers,
   Chris
CERTIFIED EXPERT
Commented:
Try  

HANDLE hDevice = CreateFile(_T("\\\\?\\E:"), 0, FILE_SHARE_READ | FILE_SHARE_WRITE,	NULL, OPEN_EXISTING, 0, NULL);
	
	if ( hDevice != INVALID_HANDLE_VALUE ) {
		DWORD dwOutBytes = 0;             
		DISK_CONTROLLER_NUMBER dcn;    
		BOOL res = DeviceIoControl(	hDevice,IOCTL_DISK_CONTROLLER_NUMBER,NULL, 0, &dcn, sizeof(DISK_CONTROLLER_NUMBER), &dwOutBytes,(LPOVERLAPPED)NULL);    
		CloseHandle(hDevice);    
	}

Open in new window


Substitute your own drive letter in the CreateFile() call.

The deviceIOControl() call returns 0 on my system, as I might have expected as I have no IDE disks. It might work on your system though. Inspect the dcn.ControllerNumber and dcn.DiskNumber variables in the debugger.

Cheers,
   Chris
CERTIFIED EXPERT

Commented:
N.B. you will need the Windows Driver Kit (usually called the DDK) from here http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11800

#include "WinIOCtl.h" from your SDK headers and #include "Ntdddisk.h" from the directory you install the DKK.

Cheers,
  Chris
CERTIFIED EXPERT

Commented:
I posted a valid piece of code for the questioner to try - it should give the controller number and disk number on a system with IDE disks. From these two values the IDE channel can be deduced.

Cheers,
   Chris
CERTIFIED EXPERT
Top Expert 2016

Commented:
unfortunately we didn't get any feedback from OCrana. i wonder whether the author was aware that computers with P-ATA (IDE) disks are a rare exception nowadays.

Chris has posted a valid solution. so he should get the points if you decide to add the question to the PAQ database.

Sara

Explore More ContentExplore courses, solutions, and other research materials related to this topic.