Get IDE hard drive ID via port

Source: Internet
Author: User
Tags printf ide hard drive

#include


#include


#include


#include


#include


char *getascii (unsigned int indata[], int offstart, int offend);


int main (void)


{


unsigned int diskdata[256]; /* Disk data */


unsigned int offset; /* Disk Data offset */


int loop;


int numdrv; /* Number of IDE hard drives * *


Union regs Registers;


unsigned int bioscyl[2]; * Cylinders, Heads, sectors * *


unsigned int bioshead[2];


unsigned int biossec [2];


numdrv = peekb (0x40, 0x75); /* BIOS Data area, number of Hard disks * *


for (loop = 0; loop < numdrv; loop++)


  {


while (INP (0X01F7)!= 0x50); /* Wait for controller not busy * *


OUTP (0x01f6, (loop = = 0? 0xa0:0xb0)); /* Get First/second Drive * *


outp (0x01f7, 0xec); /* Get drive Info data */


while (INP (0X1F7)!= 0x58); /* Wait for data ready */


for (offset = 0; offset!= 256 offset++)/* Read "Sector" * * *


Diskdata[offset] = INPW (0x1f0);


/* Get BIOS Drive info */


Registers.h.ah = 0x08; /* Get drive Info */


registers.h.dl = 0x80 + loop; /* Drive is 80H to disk 0, 81H for disk 1 */


int86 (0x13, Isters, isters);


if (!registers.x.cflag)/all OK if carry not set */


   {


Bioshead[loop] = registers.h.dh + 1; /* Heads are from 0 * *


Biossec[loop] = registers.h.cl & 0x3f; /* sec is bits 5-0 */


/* +1 because starts from 0 and +1 for FDISK leaving one out/


Bioscyl[loop] = ((registers.h.cl & 0xc0) << 2) + registers.h.ch + 2;


}/* End of If * *


printf ("DRIVE%d:\n", loop);


printf ("Model number______________________:%s\n", Getascii (Diskdata, 27, 46));


printf ("Serial number_____________________:%s\n", Getascii (Diskdata, 10, 19));


printf ("Controller Revision number________:%s\n\n", Getascii (Diskdata, 23, 26));


printf ("Able to do Double Word transfer___:%6s\n", (diskdata[48) = = 0? "No": "Yes");


printf ("Controller type___________________:%04x\n", diskdata[20]);


printf ("Controller buffer size (bytes) ___:%6u\n", diskdata[21] * 512);


printf ("Number of ECC bytes transferred___:%6u\n", diskdata[22]);


printf ("Number of sectors per interrupt___:%6u\n\n", diskdata[47]);


printf ("Hard Disk reports\n");


printf ("Number of cylinders (Fixed) ___:%6u\n", diskdata[1]);


printf ("Number of heads___________________:%6u\n", diskdata[3));


printf ("Number of sectors per track_______:%6u\n\n", diskdata[6]);


printf ("BIOS reports\n");


printf ("Number of cylinders_______________:%6u\n", Bioscyl[loop));


printf ("Number of heads___________________:%6u\n", Bioshead[loop));


printf ("Number of sectors per track_______:%6u\n\n", Biossec[loop]);


printf ("Press any key to continue...\n\n");


Getch ();


}/* End of For/*


return 0;


}/* Main () */


Char *getascii (unsigned int indata[], int offstart, int offend)


{


static char retval[255];


int loop, LOOP1;


for (loop = offstart, Loop1 = 0; loop <= offend; loop++)


  {


retval[loop1++] = (char) (Indata[loop]/256); /* Get high byte */


retval[loop1++] = (char) (Indata[loop]% 256); /* Get Low byte */


}/* End of For/*


RETVAL[LOOP1] = ' the '; /* Make sure it ends in a NULL character * *


return retVal;


}/* GETASCII () * *

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.