@samitouri / QOSamiQemu / commits / 0df27c66dc

hw/ide: report the default CHS translation in IDENTIFY DEVICE

IDENTIFY DEVICE words 1, 3 and 6 describe the default CHS translation, and ATA-5 8.16.8 requires INITIALIZE DEVICE PARAMETERS to leave them alone; the translation in effect is described by words 54 to 56 instead. Words 3 and 6 were filled from s->heads and s->sectors, which the command replaces, so a guest that selected a translation of its own was told that its choice was what the drive came with, and could no longer find out the default. Word 1 is already right, as no command changes s->cylinders. Report s->drive_heads and s->drive_sectors, which ide_init_drive() keeps for exactly this, along with the retired word 4 derived from them. The CompactFlash data labels those words as the default geometry too, and INITIALIZE DEVICE PARAMETERS is accepted for CFA drives, so fix both. Cc: John Snow <jsnow@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Cc: qemu-stable@nongnu.org Fixes: 176e4961bb33 ("hw/ide/core.c: Implement ATA INITIALIZE_DEVICE_PARAMETERS command") Signed-off-by: Denis V. Lunev <den@openvz.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>

Denis V. Lunev committed Aug 14, 2026 at 17:41 UTC 0df27c66dc7271ee2e63636b5183c0b3acdf7eed
1 file changed +6 -5
hw/ide/core.c
+6 -5
@@ -138,11 +138,12 @@ static void ide_identify(IDEState *s)
138 memset(p, 0, sizeof(s->identify_data));
139
140 put_le16(p + 0, 0x0040);
141 + /* Words 1, 3 and 6 describe the default translation (ATA-5 8.16.8) */
142 put_le16(p + 1, s->cylinders);
142 - put_le16(p + 3, s->heads);
143 - put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
143 + put_le16(p + 3, s->drive_heads);
144 + put_le16(p + 4, 512 * s->drive_sectors); /* XXX: retired, remove ? */
145 put_le16(p + 5, 512); /* XXX: retired, remove ? */
145 - put_le16(p + 6, s->sectors);
146 + put_le16(p + 6, s->drive_sectors);
147 padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
148 put_le16(p + 20, 3); /* XXX: retired, remove ? */
149 put_le16(p + 21, 512); /* cache size in sectors */
@@ -332,8 +333,8 @@ static void ide_cfata_identify(IDEState *s)
333
334 put_le16(p + 0, 0x848a); /* CF Storage Card signature */
335 put_le16(p + 1, s->cylinders); /* Default cylinders */
335 - put_le16(p + 3, s->heads); /* Default heads */
336 - put_le16(p + 6, s->sectors); /* Default sectors per track */
336 + put_le16(p + 3, s->drive_heads); /* Default heads */
337 + put_le16(p + 6, s->drive_sectors); /* Default sectors per track */
338 /* *(p + 7) := nb_sectors >> 16 -- see ide_cfata_identify_size */
339 /* *(p + 8) := nb_sectors -- see ide_cfata_identify_size */
340 padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */