mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 23:10:32 +00:00
Change BootMHDOldRead and BootMHDOldWrite to not use hardcoded 512 byte single-block count, but to instead take an optional new 'size' function argument, and to read OldMBR.BIN filesize to determine MBR+gap destination write size, respectively.
This commit is contained in:
parent
e8d87009a9
commit
f02a3c844f
1 changed files with 10 additions and 7 deletions
|
@ -12,12 +12,13 @@
|
||||||
//Old master boot record
|
//Old master boot record
|
||||||
#define BOOT_DIR_OLDMBR_BIN BOOT_DIR "/OldMBR.BIN"
|
#define BOOT_DIR_OLDMBR_BIN BOOT_DIR "/OldMBR.BIN"
|
||||||
|
|
||||||
public U0 BootMHDOldRead(U8 src_drive, U8 dst_drive)
|
public U0 BootMHDOldRead(U8 src_drive, U8 dst_drive, I64 size=1)
|
||||||
{//Reads MBR from disk drive containing src partition.
|
{//Reads MBR from disk drive containing src partition.
|
||||||
//Writes a single block file to dst BOOT_DIR.
|
//Writes MBR file to dst BOOT_DIR.
|
||||||
|
// Takes optional arg 'size': count of 512-byte blocks.
|
||||||
CBlkDev *bd = Letter2BlkDev(src_drive);
|
CBlkDev *bd = Letter2BlkDev(src_drive);
|
||||||
CDrive *drive;
|
CDrive *drive;
|
||||||
CMasterBoot mbr;
|
U8 *mbr = MAlloc(BLK_SIZE * size);
|
||||||
|
|
||||||
Drive(dst_drive);
|
Drive(dst_drive);
|
||||||
drive = Fs->cur_dv;
|
drive = Fs->cur_dv;
|
||||||
|
@ -28,28 +29,30 @@ public U0 BootMHDOldRead(U8 src_drive, U8 dst_drive)
|
||||||
{
|
{
|
||||||
//Bypass partition bounds-checking
|
//Bypass partition bounds-checking
|
||||||
BlkDevLock(bd);
|
BlkDevLock(bd);
|
||||||
AHCIAtaBlksRead(bd, &mbr, 0, 1);
|
AHCIAtaBlksRead(bd, mbr, 0, size);
|
||||||
BlkDevUnlock(bd);
|
BlkDevUnlock(bd);
|
||||||
|
|
||||||
Drive(dst_drive);
|
Drive(dst_drive);
|
||||||
DirMake(BOOT_DIR);
|
DirMake(BOOT_DIR);
|
||||||
FileWrite(BOOT_DIR_OLDMBR_BIN, &mbr, BLK_SIZE);
|
FileWrite(BOOT_DIR_OLDMBR_BIN, mbr, size * BLK_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public U0 BootMHDOldWrite(U8 src_drive, U8 dst_drive)
|
public U0 BootMHDOldWrite(U8 src_drive, U8 dst_drive)
|
||||||
{//Reads OldMBR from src drive BOOT_DIR.
|
{//Reads OldMBR from src drive BOOT_DIR.
|
||||||
//writes it to the MBR of the drive with dst partition.
|
//writes it to the MBR of the drive with dst partition.
|
||||||
|
// If OldMBR.BIN size > BLK_SIZE, writes to post-MBR gap.
|
||||||
CBlkDev *bd = Letter2BlkDev(dst_drive);
|
CBlkDev *bd = Letter2BlkDev(dst_drive);
|
||||||
CMasterBoot *mbr;
|
CMasterBoot *mbr;
|
||||||
|
I64 size;
|
||||||
|
|
||||||
Drive(src_drive);
|
Drive(src_drive);
|
||||||
|
|
||||||
if (mbr = FileRead(BOOT_DIR_OLDMBR_BIN))
|
if (mbr = FileRead(BOOT_DIR_OLDMBR_BIN, &size))
|
||||||
{
|
{
|
||||||
//Bypass partition bounds-checking
|
//Bypass partition bounds-checking
|
||||||
BlkDevLock(bd);
|
BlkDevLock(bd);
|
||||||
AHCIAtaBlksWrite(bd, mbr, 0, 1);
|
AHCIAtaBlksWrite(bd, mbr, 0, size / BLK_SIZE);
|
||||||
BlkDevUnlock(bd);
|
BlkDevUnlock(bd);
|
||||||
}
|
}
|
||||||
Free(mbr);
|
Free(mbr);
|
||||||
|
|
Loading…
Reference in a new issue