I want to read a particular sector(MBR Sector) of a disk using ATA commands in vc++. I am new to VC++ so i am facing a problem when sending command to disk using DeviceIoControl. I am providing a code that i am using to read out a sector using command Read Sector(s)(0x20).
BOOL status = FALSE;
PATA_PASS_THROUGH_EX pATAData;
DWORD dataSize = sizeof(ATA_PASS_THROUGH_EX) + 512;
BYTE Buffer[sizeof(ATA_PASS_THROUGH_EX) + 512];
DWORD bytescopied = 0;
pATAData = (ATA_PASS_THROUGH_EX*)Buffer;
ZeroMemory(pATAData,dataSize); // clears the buffer
pATAData->Length = sizeof(ATA_PASS_THROUGH_EX);
pATAData->DataBufferOffset = sizeof(ATA_PASS_THROUGH_EX);
pATAData->DataTransferLength = 512;
pATAData->TimeOutValue = 2;
pATAData->CurrentTaskFile[1] = 0x01;
pATAData->CurrentTaskFile[2] = 0x00;
pATAData->CurrentTaskFile[3] = 0x00;
pATAData->CurrentTaskFile[4] = 0x00;
pATAData->AtaFlags =ATA_FLAGS_DATA_IN;
pATAData->CurrentTaskFile[6] = 0x20; // command Read Sector(s)(0x20)
/* sends the command to the device, **hDevice** is device handle*/
status = DeviceIoControl(hDevice, IOCTL_ATA_PASS_THROUGH, pATAData, dataSize,Buffer, dataSize, &bytescopied, NULL );
I can't undersatnd that what's wrong in this code and what i am missing here, but it is not working. What i am missing here ? If there is a problem with parametres of PATA_PASS_THROUGH_EX structure than tell how to read first sector(MBR).