Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find IOCTL constant values?

I need to know the IOCTL constants for the various strings (for example the value of the constant of IOCTL_ATA_PASS_THROUGH). Searching the net I found that those constants are defined in the header Ntddscsi.h but those constant are wrong. For example the constant value of IOCTL_ATA_PASS_THROUGH should be 4D02C while in the header file it is 40B

The question is: where can I find a list with ALL the right values?

Thanks

EDIT:

I've found http://www.ioctls.net/ where there are listed all the codes. Thanks anyway for the explanation of why the value in Ntddscsi.h is not the "final" value

like image 941
Jubba Avatar asked Jun 22 '12 08:06

Jubba


1 Answers

They are in ntddscsi.h found at c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\ (on a 64 bit system). They are defied as:

#define IOCTL_ATA_PASS_THROUGH          CTL_CODE(IOCTL_SCSI_BASE, 0x040b, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

and IOCTL_SCSI_BASE is

#define IOCTL_SCSI_BASE                 FILE_DEVICE_CONTROLLER

from the same file

and these from WinIoCtl.h

#define METHOD_BUFFERED                 0
#define FILE_DEVICE_CONTROLLER          0x00000004
#define FILE_READ_ACCESS          ( 0x0001 )    // file & pipe
#define FILE_WRITE_ACCESS         ( 0x0002 )    // file & pipe

and CTL_CODE comes from WinIoCtl.h found at c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\

#define CTL_CODE( DeviceType, Function, Method, Access ) (                 \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \

)

so your final value for IOCTL_ATA_PASS_THROUGH will be:

(4 << 16 | (1 | 2) << 14 | 0x040b << 2 | 0) = 315436 = 4D02C 

:D

And if you will apply these calculations to the other IO_.... macros you will find the values. On the other end it's much easier to write a short application just to print out their values as hex ;)

like image 117
Ferenc Deak Avatar answered Sep 25 '22 16:09

Ferenc Deak