nshao
驱动牛犊
驱动牛犊
  • 注册日期2002-06-29
  • 最后登录2004-09-07
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:874回复:1

读Win9x的硬盘ID出了些意外

楼主#
更多 发布于:2003-01-10 01:51
这是一段在WIN9X读硬盘ID的code, 绝大部分时间正常. 如果在一个自动启动的w9x service里的一开始, 有时值会不正确, 大概10次里有4次把. 大家帮忙看看

bool readDrivePortsWin9X(void)
{
bool done  = false;
int  drive = 0;

bool isWinIoInitialized = true;

// Get IDE Drive info from the hardware ports
// loop thru all possible drives

for (drive = 0; drive < maxIDEdrives; drive++)
{
DWORD diskdata[256];
WORD baseAddress = 0;   //  Base address of drive controller
DWORD portValue = 0;
int waitLoop = 0;
int index = 0;
 
switch (drive / 2)
{
case 0: baseAddress = 0x1f0; break;
case 1: baseAddress = 0x170; break;
case 2: baseAddress = 0x1e8; break;
case 3: baseAddress = 0x168; break;
}

//  Wait for controller not busy

waitLoop = 100000;

while (--waitLoop > 0)
{
getPortVal((WORD) (baseAddress + 7), &portValue, (BYTE) 1);

//  drive is ready
if ((portValue & 0x40) == 0x40) break;

//  previous drive command ended in error
if ((portValue & 0x01) == 0x01) break;
}

if (waitLoop < 1) continue;

//  Set Master or Slave drive

if ((drive % 2) == 0) setPortVal((WORD) (baseAddress + 6), 0xA0, 1);
else  setPortVal((WORD) (baseAddress + 6), 0xB0, 1);

//  Get drive info data
setPortVal((WORD) (baseAddress + 7), 0xEC, 1);

// Wait for data ready
waitLoop = 100000;

while (--waitLoop > 0)
{
getPortVal ((WORD) (baseAddress + 7), &portValue, 1);

//  see if the drive is ready and has it\'s info ready for us
if ((portValue & 0x48) == 0x48) break;

//  see if there is a drive error
if ((portValue & 0x01) == 0x01) break;
}

//  check for time out or other error                                                    
if (waitLoop < 1 || portValue & 0x01) continue;

//  read drive id information
for (index = 0; index < 256; index++)
{
diskdata [index] = 0x00;   //  init the space
getPortVal(baseAddress, &(diskdata [index]), 2);
}

printIdeInfo (drive, diskdata);
done = true;
}

return done;
}

最新喜欢:

okincnokincn
ruozhen
驱动牛犊
驱动牛犊
  • 注册日期2002-11-27
  • 最后登录2005-08-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-01-10 10:02
我个人认为应该编写VXD
游客

返回顶部