From 469d2e65f000c46f3bacb38350e4c97d9526b4f3 Mon Sep 17 00:00:00 2001 From: Francesco Lavra Date: Tue, 14 Mar 2023 11:20:23 +0100 Subject: [PATCH] ata_set_lba(): allow up to 256-sector I/O when LBA48 is unavailable When not using LBA48 addressing on an ATA disk, a zero value written to the sector count register means 256 sectors (in the same way a zero value means 64K sectors when using LBA48 addressing). This commit changes the sector count limit from 255 to 256 when LBA48 is not used. In addition, the code that explicitly sets the sector count to zero when it is 64K in LBA48 mode is being removed, since not necessary (the two least significant bytes of the `nsectors` variable are zero when the sector count is 64K). --- src/drivers/ata.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/drivers/ata.c b/src/drivers/ata.c index b0f9f1f48..e1eb473aa 100644 --- a/src/drivers/ata.c +++ b/src/drivers/ata.c @@ -201,8 +201,6 @@ static boolean ata_set_lba(struct ata *dev, u64 lba, u64 nsectors) if (dev->command_sets & ATA_CS_LBA48) { assert(nsectors <= 65536); - if (nsectors == 65536) - nsectors = 0; ata_out8(dev, ATA_COUNT, nsectors >> 8); ata_out8(dev, ATA_COUNT, nsectors); ata_out8(dev, ATA_CYL_MSB, lba >> 40); @@ -213,7 +211,7 @@ static boolean ata_set_lba(struct ata *dev, u64 lba, u64 nsectors) ata_out8(dev, ATA_SECTOR, lba); ata_out8(dev, ATA_DRIVE, ATA_D_LBA | ATA_DEV(dev->unit)); } else { - assert(nsectors <= 255); + assert(nsectors <= 256); ata_out8(dev, ATA_COUNT, nsectors); ata_out8(dev, ATA_CYL_MSB, lba >> 16); ata_out8(dev, ATA_CYL_LSB, lba >> 8);