Kernel: Fix device identification with all bits as ones

If device identification sends all ones, don't initialize the device.
This commit is contained in:
Bananymous 2023-10-16 16:57:07 +03:00
parent 0c88c74b76
commit 00dd7d85ce
2 changed files with 12 additions and 1 deletions

View File

@ -73,6 +73,14 @@ namespace Kernel
select_delay();
}
static bool identify_all_ones(BAN::Span<const uint16_t> identify_data)
{
for (size_t i = 0; i < 256; i++)
if (identify_data[i] != 0xFFFF)
return false;
return true;
}
BAN::ErrorOr<ATABus::DeviceType> ATABus::identify(bool secondary, BAN::Span<uint16_t> buffer)
{
select_device(secondary);
@ -117,6 +125,9 @@ namespace Kernel
ASSERT(buffer.size() >= 256);
read_buffer(ATA_PORT_DATA, buffer.data(), 256);
if (identify_all_ones(buffer))
return BAN::Error::from_errno(ENODEV);
return type;
}

View File

@ -71,7 +71,7 @@ namespace Kernel
while (model_len > 0 && m_model[model_len - 1] == ' ')
model_len--;
dprintln("Initialized disk '{}' {} MB", BAN::StringView(m_model, model_len), total_size() / 1024 / 1024);
dprintln("Initialized disk '{}' {} MiB", BAN::StringView(m_model, model_len), total_size() / 1024 / 1024);
add_disk_cache();