]> xenbits.xensource.com Git - seabios.git/commitdiff
On disk format request, verify cylinders and pass to driver.
authorKevin O'Connor <kevin@koconnor.net>
Thu, 12 Dec 2013 00:15:45 +0000 (19:15 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 13 Dec 2013 04:14:19 +0000 (23:14 -0500)
The regs->ch field contains the cylinder to format on a disk_1305
call.  Verify that parameter and pass to the low-level driver code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/disk.c
src/hw/floppy.c

index 1011b39291ed168c6301c0f703dc541b449c5c50..4421d9d7237cc0fecc1ba816fa511d37b6e29aed 100644 (file)
@@ -186,12 +186,13 @@ disk_1305(struct bregs *regs, struct drive_s *drive_gf)
     debug_stub(regs);
 
     struct chs_s chs = getLCHS(drive_gf);
-    u16 nlh=chs.head, nls=chs.sector;
+    u16 nlc=chs.cylinder, nlh=chs.head, nls=chs.sector;
 
-    u8 num_sectors = regs->al;
-    u8 head        = regs->dh;
+    u8 count = regs->al;
+    u8 cylinder = regs->ch;
+    u8 head = regs->dh;
 
-    if (head >= nlh || num_sectors == 0 || num_sectors > nls) {
+    if (cylinder >= nlc || head >= nlh || count == 0 || count > nls) {
         disk_ret(regs, DISK_RET_EPARAM);
         return;
     }
@@ -199,8 +200,8 @@ disk_1305(struct bregs *regs, struct drive_s *drive_gf)
     struct disk_op_s dop;
     dop.drive_gf = drive_gf;
     dop.command = CMD_FORMAT;
-    dop.lba = head;
-    dop.count = num_sectors;
+    dop.lba = (((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nls;
+    dop.count = count;
     dop.buf_fl = MAKE_FLATPTR(regs->es, regs->bx);
     int status = send_disk_op(&dop);
     disk_ret(regs, status);
index 7d38b12db453e9edc5f68789ef810d3f94f77e3a..d01f35459093347ca6de3c67226820a17506ba25 100644 (file)
@@ -604,12 +604,12 @@ fail:
 static int
 floppy_format(struct disk_op_s *op)
 {
-    u8 head = op->lba;
+    struct chs_s chs = lba2chs(op);
 
     // send format-track command to controller
     u8 floppyid = GET_GLOBALFLAT(op->drive_gf->cntl_id);
     u8 param[7];
-    param[0] = (head << 2) | floppyid; // HD DR1 DR2
+    param[0] = (chs.head << 2) | floppyid; // HD DR1 DR2
     param[1] = FLOPPY_SIZE_CODE;
     param[2] = op->count; // number of sectors per track
     param[3] = FLOPPY_FORMAT_GAPLEN;