通过端口获取IDE硬盘ID

rijingaot2120

rijingaot2120

2016-02-19 15:03

下面是个简单易学的通过端口获取IDE硬盘ID教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!

  

#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 for 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______________________: %sn", GetAscii(diskData, 27, 46));
   printf("Serial Number_____________________: %sn", GetAscii(diskData, 10, 19));
   printf("Controller Revision Number________: %snn", GetAscii(diskData, 23, 26));
   printf("Able to do Double Word Transfer___: %6sn", (diskData[48] == 0 ? "No" : "Yes"));
   printf("Controller type___________________:  %04Xn", diskData[20]);
   printf("Controller buffer size (bytes)____: %6un", diskData[21] * 512);
   printf("Number of ECC bytes transferred___: %6un", diskData[22]);
   printf("Number of sectors per interrupt___: %6unn", diskData[47]);
   printf("Hard Disk Reportsn");
   printf("Number of Cylinders (Fixed)_______: %6un", diskData[1]);
   printf("Number of Heads___________________: %6un", diskData[3]);
   printf("Number of Sectors per Track_______: %6unn", diskData[6]);
   printf("BIOS Reportsn");
   printf("Number of Cylinders_______________: %6un", biosCyl[loop]);
   printf("Number of Heads___________________: %6un", biosHead[loop]);
   printf("Number of Sectors per Track_______: %6unn", biosSec[loop]);
   printf("Press any key to continue...nn");
   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] = '
展开更多 50%)
分享

猜你喜欢

通过端口获取IDE硬盘ID

编程语言 网络编程
通过端口获取IDE硬盘ID

通过VisualBasic获取网卡地址

编程语言 网络编程
通过VisualBasic获取网卡地址

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

VC通过HTTP方式获取网页

编程语言 网络编程
VC通过HTTP方式获取网页

如何通过VB获取网卡地址

编程语言 网络编程
如何通过VB获取网卡地址

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

什么是IDE模式IDE模式怎么用

电脑入门
什么是IDE模式IDE模式怎么用

Java IDE-NetBeans IDE 4.1 入门指南

编程语言 网络编程
Java IDE-NetBeans IDE 4.1 入门指南

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

PowerPoint2024新功能--取色器的使用

PowerPoint2024新功能--取色器的使用

将PowerPoint2010中的对象快速对齐

将PowerPoint2010中的对象快速对齐
下拉加载更多内容 ↓