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:
TomAwezome 2022-11-02 15:29:43 -04:00
parent e8d87009a9
commit f02a3c844f

View file

@ -12,12 +12,13 @@
//Old master boot record
#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.
//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);
CDrive *drive;
CMasterBoot mbr;
U8 *mbr = MAlloc(BLK_SIZE * size);
Drive(dst_drive);
drive = Fs->cur_dv;
@ -28,28 +29,30 @@ public U0 BootMHDOldRead(U8 src_drive, U8 dst_drive)
{
//Bypass partition bounds-checking
BlkDevLock(bd);
AHCIAtaBlksRead(bd, &mbr, 0, 1);
AHCIAtaBlksRead(bd, mbr, 0, size);
BlkDevUnlock(bd);
Drive(dst_drive);
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)
{//Reads OldMBR from src drive BOOT_DIR.
//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);
CMasterBoot *mbr;
I64 size;
Drive(src_drive);
if (mbr = FileRead(BOOT_DIR_OLDMBR_BIN))
if (mbr = FileRead(BOOT_DIR_OLDMBR_BIN, &size))
{
//Bypass partition bounds-checking
BlkDevLock(bd);
AHCIAtaBlksWrite(bd, mbr, 0, 1);
AHCIAtaBlksWrite(bd, mbr, 0, size / BLK_SIZE);
BlkDevUnlock(bd);
}
Free(mbr);