Home > Back-end >  Write data to the hard drive somewhere offset, shutdown again after boot, the system can't norm
Write data to the hard drive somewhere offset, shutdown again after boot, the system can't norm

Time:09-20


.
.
Const int BUFSIZE=161 * 1024;//322 * 512=164864 bytes
Unsigned char lpWriteBuff [BUFSIZE];//to write hard drives (here) drive F data
.
.
Char devName [200].
Strcpy (devName, "\ \ \ \ \ \ PHYSICALDRIVE0");
WriteSectors (devName, 322, 238852096, lpWriteBuff);
//322 is the number of sectors
//I want to write the contents of the lpWriteBuff hard disk (here) drive F offset of 238852096 (logical sector: LBA=238852096 bytes)
.
.
BOOL CCRegProgramDlg: : WriteSectors (char devName [], LONG redpos, LONG wSectors, unsigned char lpWriteBuff [])
{//I want to write the contents of the lpWriteBuff hard disk (here) drive F offset of 238852096 (logical sector: LBA=238852096 bytes) the location of the
//I understand: redpos=322: the number of sectors, wSectors=238852096: set the write data address (the starting point to write data offset)
LARGE_INTEGER li={0};
Li. QuadPart=wSectors;//wSectors=25700620;//should be 512 integer times, (//0 x200=512)
//by setting the write address
//li. LowPart=redpos * 512;
//li redpos HighPart=1024 * * 512;//11983574;//158575088;//redpos * 1024 * 512;
Cstrings ss; Ss. The Format (" li. Li LowPart=% d. HighPart=% d % d % d ", li. The LowPart, li. HighPart, redpos, li. The QuadPart); AfxMessageBox (ss);
HANDLE hDev=CreateFile (devName, GENERIC_WRITE FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

If (hDev==INVALID_HANDLE_VALUE) return 0;
//SetFilePointer (hDev, 512 * dwStartSector, 0, FILE_BEGIN);//the original code
//SetFilePointer (hDev, li LowPart, 0, FILE_BEGIN);//the statement the results
SetFilePointer (hDev, li LowPart, & amp; Li. HighPart FILE_BEGIN);
//DWORD dwCB;//the original code
Unsigned long dwCB;
BOOL bRet=WriteFile (hDev, lpWriteBuff redpos * 512, & amp; DwCB, NULL);//li LowPart
The CloseHandle (hDev);
Return bRet.
}

//the problem is: SetFilePointer (hDev, li LowPart, & amp; Li. HighPart FILE_BEGIN); Statement
//can't lpWriteBuff [BUFSIZE] the contents of the disk (F) offset address is: the location of the 238852096
//but almost wrote disk C "starting point", to turn it off again after boot, the system can't normal boot
//you can do to help the author to solve this problem, the author is not a computer professional, in terms not necessarily accurate

CodePudding user response:

Strcpy (devName, "\ \ \ \. \ \ F:");

CodePudding user response:

Opens first 0 disk, get other 梹, li. QuadPart is equal to the absolute sectors, written content like you is not enough, and the file system
  • Related