for(i=0;i<256;i++) wDataBuf=(WORD)dwDataBuf; /* convert WORD data to char array(string)*/ i=ConvertToString(wDataBuf,27,46,SerialNum,0); SerialNum='-'; j=ConvertToString(wDataBuf,10,19,SerialNum,i+1); SerialNum[j]='-'; ConvertToString(wDataBuf,23,26,SerialNum,j+1); strcpy(buffer,SerialNum); return TRUE; }
首先调用GetIdeDiskInformation来获取IDE硬盘的信息,如果系统没有IDE硬盘,那么再用GetScsiDiskInformation试图获取 Scsi硬盘的信息,两者都找不到就返回FALSE。找到信息后,调用ConvertToString把序列号相关的信息转换为string 存在buffer参数指定的内存中,返回给调用者。 GetIdeDiskInformation的代码如下: /*get IDE disk infromation Arguments: * buffer--return the IDE disk first sector information * DiskNum--IDE disk number, must between 0 and MAX_IDE_DISK *return: * FALSE---can't get infromation * TRUE---successfully, the buffer contains all information we need */ BOOL GetIdeDiskInformation(DWORD *buffer, int DiskNum) { char szIdeDeviceName[32]; HANDLE hIdeDriver; DWORD dwByteRet; GETVERSIONOUTPARAMS VersionParam; SENDCMDINPARAMS InParam; BYTE bIdCmd; BYTE OutBuf[sizeof(SENDCMDOUTPARAMS)+IDENTIFY_BUFFER_SIZE-1]; int i; USHORT *pIdSector;
if((DiskNum>MAX_IDE_DISK-1)||(DiskNum<0)){ SysInfoDebug(" GetIdeDiskInformation--Invalid Disk Number"); return FALSE; } sprintf(szIdeDeviceName,"\\\\.\\PhysicalDrive%d",DiskNum); hIdeDriver=CreateFile(szIdeDeviceName,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); if(hIdeDriver!=INVALID_HANDLE_VALUE){ SysInfoDebug("GetIdeDiskInformation--Open Disk success"); memset((void*)&VersionParam,0,sizeof(VersionParam)); if(DeviceIoControl(hIdeDriver,SMART_GET_VERSION,NULL,0,&VersionParam, sizeof(VersionParam),&dwByteRet,NULL)){ if(VersionParam.bIDEDeviceMap > 0){ bIdCmd=(VersionParam.bIDEDeviceMap>>DiskNum&0x10)?IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY; memset((void*)&InParam,0,sizeof(InParam)); memset((void*)OutBuf,0,sizeof(OutBuf)); if(DoIdentify(hIdeDriver,&InParam,(PSENDCMDOUTPARAMS)&OutBuf,bIdCmd,(BYTE)DiskNum,&dwByteRet)){ pIdSector=(USHORT *)((PSENDCMDOUTPARAMS)OutBuf)->bBuffer; for(i=0;i<256;i++) buffer=pIdSector; SysInfoDebug("GetIdeDiskInformation--get disk information success"); return TRUE; } } } } SysInfoDebug("GetIdeDiskInformation--cannot get disk information"); return FALSE; }
// The command can either be IDE identify or ATAPI identify. pSCIP->irDriveRegs.bCommandReg = btIDCmd; pSCIP->bDriveNumber = btDriveNum; pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE;
而GetScsiDiskInformation的代码如下: /* get scsi disk information ,if any * we query scsi miniport driver to get these information * Arguments: * buffer--return the scsi disk first sector information * DiskNum--scsi disk number, must between 0 and MAX_SCSI_DISK *return: * FALSE---can't get infromation * TRUE---successfully, the buffer contains all information we need */
用户1361860 2009-3-9 13:42
用户180278 2009-3-3 21:38
用户180278 2009-3-3 21:34