Skip to content

Commit

Permalink
ata_set_lba(): allow up to 256-sector I/O when LBA48 is unavailable
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
francescolavra committed Mar 14, 2023
1 parent 6acd2df commit 469d2e6
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/drivers/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 469d2e6

Please sign in to comment.