From 78ae4b053041c1452f002550ee37ac7e889abedf Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 19 Dec 2020 15:19:01 +0200 Subject: [PATCH] Kernel: Change the indexing of storage devices in IDEController class Previously, the indexing scheme was that 0 is Primary-Master, 1 is Primary-Slave, 2 is Secondary-Master, 3 is Secondary-Slave. Instead of merely matching between numbers to the channel & position, the IDEController code will try to find all available drives connected to the two channels, then it will create a Vector with nonnull RefPtr to them. Then we take use the given index with this Vector. --- Kernel/Storage/IDEController.cpp | 18 ++++++++++++++++-- Kernel/Storage/IDEController.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Kernel/Storage/IDEController.cpp b/Kernel/Storage/IDEController.cpp index 0d64d8d331..b825523354 100644 --- a/Kernel/Storage/IDEController.cpp +++ b/Kernel/Storage/IDEController.cpp @@ -95,7 +95,7 @@ void IDEController::initialize(bool force_pio) m_channels.append(IDEChannel::create(*this, { base_io, control_io, bus_master_base.offset(8) }, IDEChannel::ChannelType::Secondary, force_pio)); } -RefPtr IDEController::device(u32 index) const +RefPtr IDEController::device_by_channel_and_position(u32 index) const { switch (index) { case 0: @@ -107,7 +107,21 @@ RefPtr IDEController::device(u32 index) const case 3: return m_channels[1].slave_device(); } - return nullptr; + ASSERT_NOT_REACHED(); +} + +RefPtr IDEController::device(u32 index) const +{ + NonnullRefPtrVector connected_devices; + for (size_t index = 0; index < 4; index++) { + auto checked_device = device_by_channel_and_position(index); + if (checked_device.is_null()) + continue; + connected_devices.append(checked_device.release_nonnull()); + } + if (index >= connected_devices.size()) + return nullptr; + return connected_devices[index]; } } diff --git a/Kernel/Storage/IDEController.h b/Kernel/Storage/IDEController.h index 402d1a44e3..1a26e49223 100644 --- a/Kernel/Storage/IDEController.h +++ b/Kernel/Storage/IDEController.h @@ -55,6 +55,7 @@ public: private: IDEController(PCI::Address address, bool force_pio); + RefPtr device_by_channel_and_position(u32 index) const; void initialize(bool force_pio); void detect_disks();