diff options
author | Liav A <liavalb@gmail.com> | 2020-12-19 13:56:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-21 00:19:21 +0100 |
commit | 6a691306b56ec58b2c77859e124446546f82f04a (patch) | |
tree | 3595dee50aa5988283353759b4341d1a1f99362d /Kernel | |
parent | e3b3805abfe0995c356920879a98de0aac57c987 (diff) | |
download | serenity-6a691306b56ec58b2c77859e124446546f82f04a.zip |
Kernel: Add a method to gather the devices count of a Storage controller
Also, change device() method to be const.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Storage/IDEChannel.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/IDEChannel.h | 4 | ||||
-rw-r--r-- | Kernel/Storage/IDEController.cpp | 12 | ||||
-rw-r--r-- | Kernel/Storage/IDEController.h | 3 | ||||
-rw-r--r-- | Kernel/Storage/StorageController.h | 3 |
5 files changed, 19 insertions, 7 deletions
diff --git a/Kernel/Storage/IDEChannel.cpp b/Kernel/Storage/IDEChannel.cpp index 0bb1e41e34..6334605c2c 100644 --- a/Kernel/Storage/IDEChannel.cpp +++ b/Kernel/Storage/IDEChannel.cpp @@ -114,11 +114,11 @@ NonnullOwnPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IO return make<IDEChannel>(controller, io_group, type, force_pio); } -RefPtr<StorageDevice> IDEChannel::master_device() +RefPtr<StorageDevice> IDEChannel::master_device() const { return m_master; } -RefPtr<StorageDevice> IDEChannel::slave_device() +RefPtr<StorageDevice> IDEChannel::slave_device() const { return m_slave; } diff --git a/Kernel/Storage/IDEChannel.h b/Kernel/Storage/IDEChannel.h index ae2cfea5f3..d138a18bba 100644 --- a/Kernel/Storage/IDEChannel.h +++ b/Kernel/Storage/IDEChannel.h @@ -108,8 +108,8 @@ public: IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio); virtual ~IDEChannel() override; - RefPtr<StorageDevice> master_device(); - RefPtr<StorageDevice> slave_device(); + RefPtr<StorageDevice> master_device() const; + RefPtr<StorageDevice> slave_device() const; virtual const char* purpose() const override { return "PATA Channel"; } diff --git a/Kernel/Storage/IDEController.cpp b/Kernel/Storage/IDEController.cpp index 00e89284ce..0d64d8d331 100644 --- a/Kernel/Storage/IDEController.cpp +++ b/Kernel/Storage/IDEController.cpp @@ -47,6 +47,16 @@ bool IDEController::shutdown() TODO(); } +size_t IDEController::devices_count() const +{ + size_t count = 0; + for (u32 index = 0; index < 4; index++) { + if (!device(index).is_null()) + count++; + } + return count; +} + void IDEController::start_request(const StorageDevice&, AsyncBlockDeviceRequest&) { ASSERT_NOT_REACHED(); @@ -85,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<StorageDevice> IDEController::device(u32 index) +RefPtr<StorageDevice> IDEController::device(u32 index) const { switch (index) { case 0: diff --git a/Kernel/Storage/IDEController.h b/Kernel/Storage/IDEController.h index 40ab04886a..402d1a44e3 100644 --- a/Kernel/Storage/IDEController.h +++ b/Kernel/Storage/IDEController.h @@ -45,9 +45,10 @@ public: virtual ~IDEController() override; virtual Type type() const override { return Type::IDE; } - virtual RefPtr<StorageDevice> device(u32 index) override; + virtual RefPtr<StorageDevice> device(u32 index) const override; virtual bool reset() override; virtual bool shutdown() override; + virtual size_t devices_count() const override; virtual void start_request(const StorageDevice&, AsyncBlockDeviceRequest&) override; virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override; diff --git a/Kernel/Storage/StorageController.h b/Kernel/Storage/StorageController.h index 6dba3f21fe..d01a3374a4 100644 --- a/Kernel/Storage/StorageController.h +++ b/Kernel/Storage/StorageController.h @@ -51,7 +51,8 @@ public: NVMe }; virtual Type type() const = 0; - virtual RefPtr<StorageDevice> device(u32 index) = 0; + virtual RefPtr<StorageDevice> device(u32 index) const = 0; + virtual size_t devices_count() const = 0; protected: explicit StorageController(PCI::Address address) |