如何下ATA Command讀寫SATA硬盤
大家好,
請問我要怎麼樣下ATA指令來讀寫硬盤呢
我是用底下這樣子去讀寫的
指令是有下成功,但資料沒有寫進硬盤裡
ATA_PASS_THROUGH_DIRECT sptdwb;
ZeroMemory(&sptdwb,sizeof(ATA_PASS_THROUGH_DIRECT));
sptdwb.Length= sizeof(ATA_PASS_THROUGH_DIRECT);
sptdwb.AtaFlags = ATA_FLAGS_DATA_OUT|ATA_FLAGS_USE_DMA;
sptdwb.TargetId = 1;
sptdwb.DataTransferLength = BufSize+sizeof(ATA_PASS_THROUGH_DIRECT);
sptdwb.TimeOutValue = 300;
sptdwb.DataBuffer = DataBuffer;
sptdwb.CurrentTaskFile[0]= 0;
sptdwb.CurrentTaskFile[1]=((BufSize/512)&0xFF);
sptdwb.CurrentTaskFile[2]=(SectorNumberMuti&0xFF);
sptdwb.CurrentTaskFile[3]= ((SectorNumberMuti>>8)&0xFF);
sptdwb.CurrentTaskFile[4]=((SectorNumberMuti>>16)&0xFF);
sptdwb.CurrentTaskFile[5]=((SectorNumberMuti>>24)&0xFF);
sptdwb.CurrentTaskFile[6]=0xCA;//// read 0x20
sptdwb.CurrentTaskFile[7] = 0x0;
//ULONG length = sizeof(ATA_PASS_THROUGH_DIRECT)+sptdwb.DataTransferLength;
ULONG length = sizeof(ATA_PASS_THROUGH_DIRECT);
//ULONG length = sptdwb.DataTransferLength;
/////////////////////////////////////////////////////////////////////////////////////////////
ULONG returned = 0;
BOOL success = false;
if( hDevice != INVALID_HANDLE_VALUE )
{
success = DeviceIoControl(
hDevice,
IOCTL_ATA_PASS_THROUGH_DIRECT,
&sptdwb,
length,
&sptdwb,
length,
&returned,
FALSE );
int nLastError=GetLastError();
FlushFileBuffers( hDevice);
if(!success)
return success;
}
}
return success;