21,595
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------
// WriteDiskSector: Write disk sector (512 bytes) in Windows
//---------------------------------------------------------------------
extern "C" BOOL WriteDiskSector(int drive, DWORD startinglogicalsector, int numberofsectors, BYTE *buffer)
{
HANDLE hDevice;
DWORD byteswritten;
// Creating a handle to drive a: using CreateFile () function ..
char _devicename[] = "\\\\.\\PhysicalDrive0";
_devicename[17] += drive;
hDevice = CreateFile(_devicename, // drive to open
GENERIC_READ|GENERIC_WRITE, // access type
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes
if (hDevice == INVALID_HANDLE_VALUE)
return FALSE;
DiskFileSeek(hDevice, (startinglogicalsector),FILE_BEGIN);
if (!WriteFile (hDevice, buffer, 512*numberofsectors, &byteswritten, NULL) )
return FALSE;
CloseHandle(hDevice);
return TRUE;
}