Skip to content

Commit

Permalink
ide: Cap LBA28 capacity announcement to 2^28-1
Browse files Browse the repository at this point in the history
The LBA28 capacity (at offsets 60/61 of identification) is supposed to
express the maximum size supported by LBA28 commands. If the device is
larger than this, we have to cap it to 2^28-1.

At least NetBSD happens to be using this value to determine whether to use
LBA28 or LBA48 for its commands, using LBA28 for sectors that don't need
LBA48. This commit thus fixes NetBSD access to disks larger than 128GiB.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Message-Id: <20210824104344.3878849-1-samuel.thibault@ens-lyon.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
sthibaul authored and kevmw committed Nov 2, 2021
1 parent 0347a8f commit 46e018e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hw/ide/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ static void put_le16(uint16_t *p, unsigned int v)
static void ide_identify_size(IDEState *s)
{
uint16_t *p = (uint16_t *)s->identify_data;
put_le16(p + 60, s->nb_sectors);
put_le16(p + 61, s->nb_sectors >> 16);
int64_t nb_sectors_lba28 = s->nb_sectors;
if (nb_sectors_lba28 >= 1 << 28) {
nb_sectors_lba28 = (1 << 28) - 1;
}
put_le16(p + 60, nb_sectors_lba28);
put_le16(p + 61, nb_sectors_lba28 >> 16);
put_le16(p + 100, s->nb_sectors);
put_le16(p + 101, s->nb_sectors >> 16);
put_le16(p + 102, s->nb_sectors >> 32);
Expand Down

0 comments on commit 46e018e

Please sign in to comment.