Free Source Code and Program Tips
How to read sectors of a physical drive under Win32?
How to read the sectors of physical drive under win32?
The API ReadFile is most useful function, and with it, you can read the physical sectors directly.
Here is a sample function, BOOL ReadSectors(…)
BOOL ReadSectors(
BYTE bDrive, //drive index
DWORD dwStartSector, //start sector
WORD wSectors, //sectors number
LPBYTE lpSectBuff)
{
 if (bDrive == 0) return 0;
 char devName[] = “\\\\.\\A:”;
 devName[4] =’A’ + bDrive – 1;
 HANDLE hDev = CreateFile(devName, GENERIC_READ,
FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
 if (hDev == INVALID_HANDLE_VALUE) return 0;
 SetFilePointer(hDev, 512 * dwStartSector,
0, FILE_BEGIN);
 DWORD dwCB;
 BOOL bRet = ReadFile(hDev, lpSectBuff,
512 * wSectors, &dwCB, NULL);
 CloseHandle(hDev);
 return bRet;
}
| Print article | This entry was posted by support on January 15, 2007 at 7:44 am, and is filed under Win32/MFC. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |