[SeaBIOS] [PATCH 2/3] On disk format request, verify cylinders and pass to driver.
Kevin O'Connor
kevin at koconnor.net
Thu Dec 12 05:47:15 CET 2013
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 at koconnor.net>
---
src/disk.c | 13 +++++++------
src/hw/floppy.c | 4 ++--
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/disk.c b/src/disk.c
index 1011b39..4421d9d 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -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);
diff --git a/src/hw/floppy.c b/src/hw/floppy.c
index e2b494d..8f3ec9e 100644
--- a/src/hw/floppy.c
+++ b/src/hw/floppy.c
@@ -622,12 +622,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;
--
1.8.3.1
More information about the SeaBIOS
mailing list