From 66e3d71dbcfe8e0442ebcf79d858c5e6a5000399 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 7 Sep 2023 11:28:46 +0200 Subject: [PATCH] kernel/ATA: Fix sector number calculation for ATA drives --- kernel/src/arch/x86_64/disk/ATA.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/src/arch/x86_64/disk/ATA.cpp b/kernel/src/arch/x86_64/disk/ATA.cpp index 4b601c77..17ffc484 100644 --- a/kernel/src/arch/x86_64/disk/ATA.cpp +++ b/kernel/src/arch/x86_64/disk/ATA.cpp @@ -503,11 +503,17 @@ namespace ATA } else { - if (m_identify_data.big_lba) m_is_lba48 = true; + u8 buf[8]; + memcpy(buf, &m_identify_words[100], 8); - if (m_is_lba48) m_block_count = m_identify_data.sectors_48; - else - m_block_count = m_identify_data.sectors_28; + m_block_count = *reinterpret_cast(buf); + + if (!m_block_count) + { + memcpy(buf, &m_identify_words[60], 4); + m_block_count = *reinterpret_cast(buf); + } + else { m_is_lba48 = true; } // FIXME: Should we check for CHS?