Hi Guys I am making tool for getting SMART data from HDD which is connected to RAID contoller but i am getting "Incorrect function" error while i am trying to send Identify device command via DeviceIoConrol()....Below is my code sample...plz help me to get rid of that error...
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <conio.h>
#include <winioctl.h>
#include <ntddscsi.h>
ATA_PASS_THROUGH_EX ATAData;
ATA_OUTPUT_BUFFER ATAOut;typedef struct _ATA_OUTPUT_BUFFER
{
ATA_PASS_THROUGH_EX pSCOP;
BYTE output_buff[512];
}ATA_OUTPUT_BUFFER,*PATA_OUTPUT_BUFFER;
int main()
{
HANDLE hSMARTIOCTL;
int i,status,dataSize,flag=0;
DWORD cbBytesReturned=0;
BYTE bIDCmd;
BYTE bDfpDriveMap = 0;
dataSize=512;
for(i=1;i<2;i++)
{
if ((hSMARTIOCTL = OpenSMART(i)) != INVALID_HANDLE_VALUE) {
memset(ATAOut.output_buff, 0, sizeof(512));
ATA_PASS_THROUGH_EX and clear the contents
if ( DoIDENTIFY(hSMARTIOCTL, &ATAData,&ATAOut,bIDCmd, i, &cbBytesReturned))
{
DisplayIdInfo((PIDSECTOR) ATAOut.output_buff,bIDCmd,i);
}
else
{
printf("Identify Command Error %d\n",GetLastError());
}
}
}
}
HANDLE OpenSMART(int n)
{
HANDLE hSMARTIOCTL = 0;
char szT1[256]={0};
printf("***----------------------------------------***\n");
printf(" << Device Discover >>\n");
printf("***----------------------------------------***\n\n");
wsprintf(szT1,"\\\\.\\PHYSICALDRIVE%d",n);
if ((hSMARTIOCTL = CreateFile(szT1,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL)) == INVALID_HANDLE_VALUE)
printf("Unable to open physical drive, error code: 0x%lX\n", GetLastError());
else
printf("Physical drive %d opened successfully\n\n",n);
return hSMARTIOCTL;
}
BOOL DoIDENTIFY(HANDLE hSMARTIOCTL, PATA_PASS_THROUGH_EX pSCIP,PATA_OUTPUT_BUFFER pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned)
{
int val;
pSCIP->AtaFlags = ATA_FLAGS_DATA_IN;
pSCIP->Length= sizeof(ATAData);
pSCIP->DataTransferLength= IDENTIFY_BUFFER_SIZE;
pSCIP->TimeOutValue= 10;
pSCIP->DataBufferOffset= offsetof(ATA_OUTPUT_BUFFER,output_buff);
pSCIP->CurrentTaskFile[0]=0;
pSCIP->CurrentTaskFile[1]=1;
pSCIP->CurrentTaskFile[2]=1;
pSCIP->CurrentTaskFile[3]=0;
pSCIP->CurrentTaskFile[4]=0;
pSCIP->CurrentTaskFile[5]=0xA0 | ((bDriveNum & 1) << 4); pSCIP->CurrentTaskFile[6]=0XEC;
pSCIP->CurrentTaskFile[7] = 0; pSCIP->TargetId=bDriveNum;
val=DeviceIoControl(hSMARTIOCTL, IOCTL_ATA_PASS_THROUGH,
pSCIP,sizeof(ATAOut),pSCOP, sizeof(ATAOut),
lpcbBytesReturned, NULL);
return val;
}