Link to home
Start Free TrialLog in
Avatar of Ocrana
Ocrana

asked on

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
Avatar of sarabande
sarabande
Flag of Luxembourg image

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

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
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
ASKER CERTIFIED SOLUTION
Avatar of tampnic
tampnic
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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