Actual Combat DeviceIoControl Series IV: Get the hard drive details

Source: Internet
Author: User
Tags define data structures error code reserved

Q with IOCTL_DISK_GET_DRIVE_GEOMETRYIOCTL_STORAGE_GET_MEDIA_TYPES_EX can only get very little disk parameters, I would like to get the serial number including the hard disk of more detailed information, what method?

A Indeed, with what you call the I/O control code, you can only get the most basic disk parameters. Get the disk factory information I/O control code, Microsoft in the VC/MFC environment is not open, in the DDK can find some clues. Earlier, Lynn McGuire wrote a very famous program to get details of the IDE's hard disk DiskID32, and the following examples are based on additions, deletions, and improvements.

In this case, we need to use the ATA/APAPI identify device instructions. ATA/APAPI is the standard for the interface between the IDE/EIDE/UDMA hard disk and other Removable storage devices T13 drafted and released by the international organization and has now been ata/apapi-7 version. The interface standard prescribes the input output registers and instruction sets of the ATA/ATAPI device. For more detailed ATA/ATAPI technical information, you can visit the T13 site.

The following constants and data structures are used:

IOCTL control Code
#define Dfp_send_drive_command 0x0007c084
#define Dfp_send_drive_command Ctl_code (ioctl_disk_base, 0x0021,
method_buffered, File_read_access | file_write_access)
#define Dfp_receive_drive_data 0x0007c088
#define Dfp_receive_drive_data Ctl_code (ioctl_disk_base, 0x0022,
method_buffered, File_read_access | file_write_access)
#define FILE_DEVICE_SCSI 0x0000001b
#define IOCTL_SCSI_MINIPORT_IDENTIFY ((file_device_scsi <<) + 0x0501)
#define IOCTL_SCSI_MINIPORT 0x0004d008//NTDDSCSI. H for definition
ATA/ATAPI directives
#define IDE_ATA_IDENTIFY 0xEC//ATA ID directive (identify DEVICE)
IDE Command Registers
typedef struct _IDEREGS
{
BYTE Bfeaturesreg;   Feature registers (for smart commands) BYTE Bsectorcountreg; Sector number Register
BYTE Bsectornumberreg; Start Sector Register
BYTE Bcyllowreg; Start cylinder Low byte register
BYTE Bcylhighreg; Start cylinder High byte register
BYTE Bdriveheadreg; Drive/Head Registers
BYTE Bcommandreg; Instruction Registers
BYTE breserved; Keep
Ideregs, *pideregs, *lpideregs;
Status returned from the driver
typedef struct _DRIVERSTATUS
{
BYTE Bdrivererror; Error code
BYTE Bidestatus; IDE Status Registers
BYTE breserved[2]; Keep
DWORD dwreserved[2]; Keep
Driverstatus, *pdriverstatus, *lpdriverstatus;
IDE device IOCTL input data structure
typedef struct _SENDCMDINPARAMS
{
DWORD cbuffersize; Number of buffer bytes
Ideregs Irdriveregs; IDE Register Group
BYTE Bdrivenumber; Drive letter
BYTE Breserved[3]; Keep
DWORD Dwreserved[4]; Keep
BYTE Bbuffer[1]; Input buffer (symbolically contains 1 bytes)
Sendcmdinparams, *psendcmdinparams, *lpsendcmdinparams;
IDE device IOCTL output data structure
typedef struct _SENDCMDOUTPARAMS
{
DWORD cbuffersize; Number of buffer bytes
Driverstatus Driverstatus; Driver return Status
BYTE Bbuffer[1]; Input buffer (symbolically contains 1 bytes)
Sendcmdoutparams, *psendcmdoutparams, *lpsendcmdoutparams;
The data returned by the IDE's ID command
Total 512 bytes (256 word), only some items of interest are defined here (basically based on ata/atapi-4)
typedef struct _IDINFO
{
USHORT Wgenconfig; Word 0: basic information Word
USHORT wnumcyls; WORD 1: Number of cylinders
USHORT WReserved2; WORD 2: Reserved
USHORT wnumheads;     WORD 3: The number of heads USHORT wReserved4; WORD 4: Reserved
USHORT WReserved5; WORD 5: Reserved
USHORT Wnumsectorspertrack; WORD 6: Number of sectors per track
USHORT Wvendorunique[3]; WORD 7-9: Factory Set Value
CHAR SSERIALNUMBER[20]; WORD 10-19: Serial number
USHORT Wbuffertype; WORD 20: Buffer type
USHORT wbuffersize; WORD 21: Buffer size
USHORT weccsize; WORD 22:ECC Check Size
CHAR Sfirmwarerev[8]; WORD 23-26: Firmware version
CHAR smodelnumber[40]; WORD 27-46: Internal model
USHORT Wmorevendorunique; WORD 47: Factory Set Value
USHORT wReserved48; WORD 48: Reserved
struct {
USHORT Reserved1:8;
USHORT dma:1; 1= supports DMA
USHORT lba:1; 1= supports LBA
USHORT disiordy:1; 1= don't use Iordy.
USHORT iordy:1; 1= Support Iordy
USHORT softreset:1; 1= requires ATA soft boot
USHORT overlap:1; 1= support for overlapping operations
USHORT queue:1; 1= Support Command queues
USHORT inldma:1; 1= supports cross-access DMA
} wcapabilities; WORD 49: General Capabilities
USHORT wReserved1; WORD 50: Reserved
USHORT wpiotiming; WORD 51:pio Timing
USHORT wdmatiming; WORD 52:DMA Timing
struct {
USHORT chsnumber:1; 1=word 54-58 Effective
USHORT cyclenumber:1; 1=word 64-70 Effective
USHORT unltradma:1; 1=word 88 Effective
USHORT reserved:13;
} wfieldvalidity; WORD 53: Subsequent field validation flags
USHORT wnumcurcyls; WORD 54:chs number of addressable cylinders
USHORT wnumcurheads; WORD 55:chs The number of heads that can be addressed
USHORT Wnumcursectorspertrack; WORD 56:chs The number of sectors per track to address
USHORT Wcursectorslow; Word 57:chs addressable number of sectors low word
USHORT Wcursectorshigh; Word 58:chs addressable number of sectors high word
struct {
USHORT Curnumber:8; The current number of disposable sectors that can be read and write
USHORT multi:1; 1= has selected multiple sectors to read and write
USHORT Reserved1:7;
} Wmultsectorstuff; WORD 59: Multiple sectors Read and write settings
ULONG dwtotalsectors; WORD 60-61:lba number of addressable sectors
USHORT WSINGLEWORDDMA; WORD 62: Single-byte DMA support capability struct {
USHORT mode0:1; 1= Support Mode 0 (4.17MB/S)
USHORT mode1:1; 1= Support Mode 1 (13.3mb/s)
USHORT mode2:1; 1= Support Mode 2 (16.7MB/S)
USHORT Reserved1:5;
USHORT mode0sel:1; 1= has selected mode 0
USHORT mode1sel:1; 1= has selected Mode 1
USHORT mode2sel:1; 1= has selected Mode 2
USHORT Reserved2:5;
} WMULTIWORDDMA; WORD 63: Multi-byte DMA support capability
struct {
USHORT Advpoimodes:8; Support Advanced POI mode number
USHORT Reserved:8;
} wpiocapacity; WORD 64: Advanced PIO Support Capabilities
USHORT wminmultiworddmacycle; WORD 65: Minimum value for multibyte DMA transfer cycles
USHORT wrecmultiworddmacycle; WORD 66: Recommended values for multibyte DMA transfer cycles
USHORT wminpionoflowcycle; WORD 67: Minimum value for PIO transmission period without flow control
USHORT wminpoiflowcycle; WORD 68: Minimum value for PIO transmission period when there is flow control
USHORT wReserved69 [11]; WORD 69-79: Reserved
struct {
USHORT reserved1:1;
USHORT ata1:1; 1= Support ATA-1
USHORT ata2:1; 1= Support ATA-2
USHORT ata3:1; 1= Support ATA-3
USHORT ata4:1; 1= Support Ata/atapi-4
USHORT ata5:1; 1= Support Ata/atapi-5
USHORT ata6:1; 1= Support Ata/atapi-6
USHORT ata7:1; 1= Support Ata/atapi-7
USHORT ata8:1; 1= Support Ata/atapi-8
USHORT ata9:1; 1= Support Ata/atapi-9
USHORT ata10:1; 1= Support ATA/ATAPI-10
USHORT ata11:1; 1= Support ata/atapi-11
USHORT ata12:1; 1= Support ata/atapi-12
USHORT ata13:1; 1= Support ATA/ATAPI-13
USHORT ata14:1; 1= Support ATA/ATAPI-14
USHORT reserved2:1;
} wmajorversion; WORD 80: Major Version
USHORT wminorversion; WORD 81: Secondary version
USHORT Wreserved82[6]; WORD 82-87: Reserved
struct {
USHORT mode0:1; 1= Support Mode 0 (16.7MB/S)
USHORT mode1:1; 1= Support Mode 1 (25mb/s)
USHORT mode2:1; 1= Support Mode 2 (33MB/S)
USHORT mode3:1;  1= Support Mode 3 (44MB/S) USHORT mode4:1; 1= Support Mode 4 (66MB/S)
USHORT mode5:1; 1= Support Mode 5 (100MB/S)
USHORT mode6:1; 1= Support Mode 6 (133MB/S)
USHORT mode7:1; 1= Support Mode 7 (166MB/S)???
USHORT mode0sel:1; 1= has selected mode 0
USHORT mode1sel:1; 1= has selected Mode 1
USHORT mode2sel:1; 1= has selected Mode 2
USHORT mode3sel:1; 1= has selected mode 3
USHORT mode4sel:1; 1= has selected Mode 4
USHORT mode5sel:1; 1= has selected mode 5
USHORT mode6sel:1; 1= has selected mode 6
USHORT mode7sel:1; 1= has selected Mode 7
} WULTRADMA; WORD 88:ultra DMA Support capabilities
USHORT wreserved89[167]; WORD 89-255
} idinfo, *pidinfo;
The shared structure of the input and output required by the SCSI driver
typedef struct _SRB_IO_CONTROL
{
ULONG headerlength; Head length
Uchar Signature[8]; Feature name
ULONG Timeout; Timeout time
ULONG Controlcode; Control code
ULONG ReturnCode; Return code
ULONG Length; Buffer length
} Srb_io_control, *psrb_io_control;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.