DbgPrint("The Serial Number Hard Disk is %s \n",getascii(dd,10,19));
}
char *getascii(unsigned int in_data[], int off_start, int off_end)
{
static char ret_val[255];
int loop, loop1;
for(loop = off_start, loop1 = 0; loop <=off_end; loop++)
{
ret_val[loop1++] =(char)(in_data[loop]/256); /* Get High byte */
ret_val[loop1++]=(char)(in_data[loop]%256); /* Get Low byte */
}
ret_val[loop1]=' '; /* Make sure it ends in a NULL character */
return(ret_val);
}
// The command can either be IDE identify or ATAPI identify.
scip.irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
scip.bDriveNumber = (UCHAR)drive;
scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
//
// Copy the IOCTL parameters to the srb control buffer area.
//
irp2 = IoBuildDeviceIoControlRequest(DFP_RECEIVE_DRIVE_DATA,
DeviceObject,
&scip,
sizeof(SENDCMDINPARAMS) - 1,
IdOutCmd,
sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
FALSE,
&event,
&ioStatus);
//
// Call the port driver with the request and wait for it to complete.
//
status = IoCallDriver(DeviceObject, irp2);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
//
// Copy the data received into the output buffer. Since the status buffer
// contains error information also, always perform this copy. IO will will
// either pass this back to the app, or zero it, in case of error.
//
if (NT_SUCCESS(status)) {
ULONG diskdata [256];
int ijk = 0;
USHORT *pIdSector = (USHORT *)
((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;
DbgPrint("successs in read disk id \n");
char *ConvertToString (ULONG diskdata [256], int firstIndex, int lastIndex)
{
static char string [1024];
int index = 0;
int position = 0;
// each integer has two characters stored in it backwards
for (index = firstIndex; index <= lastIndex; index++)
{
// get high byte for 1st character
string [position] = (char) (diskdata [index] / 256);
position++;
// get low byte for 2nd character
string [position] = (char) (diskdata [index] % 256);
position++;
}
// end the string
string [position] = '\0';
// cut off the trailing blanks
for (index = position - 1; index > 0 && ' ' == string [index]; index--)
string [index] = '\0';
return string;
}
读取硬盘ID的时候总是不成功,是在下发IRP的时候有问题,应该是这句
status = IoCallDriver(DeviceObject, irp2);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
ioStatus.Status不是STATUS_SUCCESS;
请问各位,怎么设置物理设备对象才能让这段代码发送成功啊???