From 8957c49612075da4b1460843fd86b7d8cacf79ce Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 11 Jul 2008 01:29:49 -0400 Subject: chain.c32: explicitly verify after writing MBR If we write the MBR, do verify by reading it back and comparing. Right now all we do is print an error, though. --- com32/modules/chain.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/com32/modules/chain.c b/com32/modules/chain.c index 9fda1c9a..e6409b4e 100644 --- a/com32/modules/chain.c +++ b/com32/modules/chain.c @@ -244,7 +244,7 @@ static int write_sector(unsigned int lba, const void *buf) inreg.esi.w[0] = OFFS(dapa); inreg.ds = SEG(dapa); inreg.edx.b[0] = disk_info.disk; - inreg.eax.b[1] = 0x43; /* Extended write */ + inreg.eax.w[0] = 0x4300; /* Extended write */ } else { unsigned int c, h, s, t; @@ -280,6 +280,22 @@ static int write_sector(unsigned int lba, const void *buf) return 0; /* ok */ } +static int write_verify_sector(unsigned int lba, const void *buf) +{ + char *rb; + int rv; + + rv = write_sector(lba, buf); + if (rv) + return rv; /* Write failure */ + rb = read_sector(lba); + if (!rb) + return -1; /* Readback failure */ + rv = memcmp(buf, rb, SECTOR); + free(rb); + return rv ? -1 : 0; +} + /* Search for a specific drive, based on the MBR signature; bytes 440-443. */ static int find_disk(uint32_t mbr_sig) @@ -621,9 +637,9 @@ static int hide_unhide(char *mbr, int part) } if (write_back) - return write_sector(0, mbr); - else - return 0; /* Nothing to do, return OK */ + return write_verify_sector(0, mbr); + + return 0; /* ok */ } int main(int argc, char *argv[]) -- cgit v1.2.1