求教:谁给解释一下这个怎么实现的

zhci31462 2008-07-12 11:24:54
在csdn上看到一个显示硬盘id的小程序:谁能帮忙解释一下在nt 下它是什么工作的阿。。用的什么方法得到的呢〉。。谢谢高人
nt下获得硬盘 id 代码如下:
void hdidnt(){
char hd[80];
PIDSECTOR phdinfo;
char s[41];

ZeroMemory(&vers,sizeof(vers));
//We start in NT/Win2000
for (j=0;j<4;j++){
sprintf(hd,"\\\\.\\PhysicalDrive%d",j);
h=CreateFile(hd,GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (!h){
continue;
}
if (!DeviceIoControl(h,DFP_GET_VERSION,0,0,&vers,sizeof(vers),&i,0)){
CloseHandle(h);
continue;
}
//If IDE identify command not supported, fails
if (!(vers.fCapabilities&1)){
cout<<"Error: IDE identify command not supported.";
CloseHandle(h);
return;
}
//Identify the IDE drives
ZeroMemory(&in,sizeof(in));
ZeroMemory(&out,sizeof(out));
if (j&1){
in.irDriveRegs.bDriveHeadReg=0xb0;
}else{
in.irDriveRegs.bDriveHeadReg=0xa0;
}
if (vers.fCapabilities&(16>>j)){
//We don't detect a ATAPI device.
cout<<"Drive "<<(int)(j+1)<<" is a ATAPI device, we don't detect it"<<endl;
continue;
}else{
in.irDriveRegs.bCommandReg=0xec;
}
in.bDriveNumber=j;
in.irDriveRegs.bSectorCountReg=1;
in.irDriveRegs.bSectorNumberReg=1;
in.cBufferSize=512;
if (!DeviceIoControl(h,DFP_RECEIVE_DRIVE_DATA,&in,sizeof(in),&out,sizeof(out),&i,0)){
cout<<"DeviceIoControl failed:DFP_RECEIVE_DRIVE_DATA"<<endl;
CloseHandle(h);
return;
}
phdinfo=(PIDSECTOR)out.bBuffer;
memcpy(s,phdinfo->sModelNumber,40);
s[40]=0;
ChangeByteOrder(s,40);
cout<<endl<<"Module Number:"<<s<<endl;
memcpy(s,phdinfo->sFirmwareRev,8);
s[8]=0;
ChangeByteOrder(s,8);
cout<<"\tFirmware rev:"<<s<<endl;
memcpy(s,phdinfo->sSerialNumber,20);
s[20]=0;
ChangeByteOrder(s,20);
cout<<"\tSerial Number:"<<s<<endl;
cout<<"\tCapacity:"<<phdinfo->ulTotalAddressableSectors/2/1024<<"M"<<endl<<endl;
CloseHandle(h);
}
CopyRight();
}
...全文
48 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Yofoo 2008-07-13
  • 打赏
  • 举报
回复
MSDN搜索 DFP_GET_VERSION

SMART IOCTL API Specification
The DeviceIoControl function sends a control code directly to a device driver, causing the given device to perform the specified operation.

DFP_GET_VERSION
DFP_SEND_DRIVE_COMMAND
DFP_RECEIVE_DRIVE_DATA

2,641

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧