diff --git a/Kernel/FileSystem/SysFS/Component.cpp b/Kernel/FileSystem/SysFS/Component.cpp index fb9cfce122..c42901ed7b 100644 --- a/Kernel/FileSystem/SysFS/Component.cpp +++ b/Kernel/FileSystem/SysFS/Component.cpp @@ -106,26 +106,33 @@ SysFSSymbolicLink::SysFSSymbolicLink(SysFSDirectory const& parent_directory, Sys ErrorOr SysFSDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const { - MutexLocker locker(m_traverse_lock); - VERIFY(m_parent_directory); TRY(callback({ "."sv, { fsid, component_index() }, 0 })); - TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 })); - - for (auto& component : m_components) { - InodeIdentifier identifier = { fsid, component.component_index() }; - TRY(callback({ component.name(), identifier, 0 })); + if (is_root_directory()) { + TRY(callback({ ".."sv, { fsid, component_index() }, 0 })); + } else { + VERIFY(m_parent_directory); + TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 })); } - return {}; + + return m_child_components.with([&](auto& list) -> ErrorOr { + for (auto& child_component : list) { + InodeIdentifier identifier = { fsid, child_component.component_index() }; + TRY(callback({ child_component.name(), identifier, 0 })); + } + return {}; + }); } RefPtr SysFSDirectory::lookup(StringView name) { - for (auto& component : m_components) { - if (component.name() == name) { - return component; + return m_child_components.with([&](auto& list) -> RefPtr { + for (auto& child_component : list) { + if (child_component.name() == name) { + return child_component; + } } - } - return {}; + return nullptr; + }); } SysFSDirectory::SysFSDirectory(SysFSDirectory const& parent_directory) diff --git a/Kernel/FileSystem/SysFS/Component.h b/Kernel/FileSystem/SysFS/Component.h index c5711ea1f0..825453ecdf 100644 --- a/Kernel/FileSystem/SysFS/Component.h +++ b/Kernel/FileSystem/SysFS/Component.h @@ -25,6 +25,8 @@ struct SysFSInodeData : public OpenFileDescriptionData { class SysFSDirectory; class SysFSComponent : public RefCounted { + friend class SysFSDirectory; + public: virtual StringView name() const = 0; virtual ErrorOr read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); } @@ -52,6 +54,8 @@ protected: RefPtr m_parent_directory; + IntrusiveListNode> m_list_node; + private: InodeIndex m_component_index {}; }; @@ -72,17 +76,19 @@ protected: class SysFSDirectory : public SysFSComponent { public: - virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; - virtual RefPtr lookup(StringView name) override; + virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override final; + virtual RefPtr lookup(StringView name) override final; virtual ErrorOr> to_inode(SysFS const& sysfs_instance) const override final; + using ChildList = SpinlockProtected>; + protected: + virtual bool is_root_directory() const { return false; } + SysFSDirectory() {}; explicit SysFSDirectory(SysFSDirectory const& parent_directory); - NonnullRefPtrVector m_components; - - mutable Mutex m_traverse_lock; + ChildList m_child_components; }; } diff --git a/Kernel/FileSystem/SysFS/Registry.cpp b/Kernel/FileSystem/SysFS/Registry.cpp index c8d623f67b..08bac173ab 100644 --- a/Kernel/FileSystem/SysFS/Registry.cpp +++ b/Kernel/FileSystem/SysFS/Registry.cpp @@ -32,7 +32,10 @@ UNMAP_AFTER_INIT SysFSComponentRegistry::SysFSComponentRegistry() UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component) { SpinlockLocker locker(m_root_directory_lock); - m_root_directory->m_components.append(component); + MUST(m_root_directory->m_child_components.with([&](auto& list) -> ErrorOr { + list.append(component); + return {}; + })); } SysFSBusDirectory& SysFSComponentRegistry::buses_directory() @@ -43,7 +46,10 @@ SysFSBusDirectory& SysFSComponentRegistry::buses_directory() void SysFSComponentRegistry::register_new_bus_directory(SysFSDirectory& new_bus_directory) { VERIFY(!m_root_directory->m_buses_directory.is_null()); - m_root_directory->m_buses_directory->m_components.append(new_bus_directory); + MUST(m_root_directory->m_buses_directory->m_child_components.with([&](auto& list) -> ErrorOr { + list.append(new_bus_directory); + return {}; + })); } } diff --git a/Kernel/FileSystem/SysFS/RootDirectory.cpp b/Kernel/FileSystem/SysFS/RootDirectory.cpp index d32f2e0332..1f21579a26 100644 --- a/Kernel/FileSystem/SysFS/RootDirectory.cpp +++ b/Kernel/FileSystem/SysFS/RootDirectory.cpp @@ -17,25 +17,15 @@ NonnullRefPtr SysFSRootDirectory::create() return adopt_ref(*new (nothrow) SysFSRootDirectory); } -ErrorOr SysFSRootDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const -{ - MutexLocker locker(m_traverse_lock); - TRY(callback({ "."sv, { fsid, component_index() }, 0 })); - TRY(callback({ ".."sv, { fsid, 0 }, 0 })); - - for (auto const& component : m_components) { - InodeIdentifier identifier = { fsid, component.component_index() }; - TRY(callback({ component.name(), identifier, 0 })); - } - return {}; -} - SysFSRootDirectory::SysFSRootDirectory() { auto buses_directory = SysFSBusDirectory::must_create(*this); auto device_identifiers_directory = SysFSDeviceIdentifiersDirectory::must_create(*this); - m_components.append(buses_directory); - m_components.append(device_identifiers_directory); + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + list.append(buses_directory); + list.append(device_identifiers_directory); + return {}; + })); m_buses_directory = buses_directory; } diff --git a/Kernel/FileSystem/SysFS/RootDirectory.h b/Kernel/FileSystem/SysFS/RootDirectory.h index 555e80079a..09a67b7cf0 100644 --- a/Kernel/FileSystem/SysFS/RootDirectory.h +++ b/Kernel/FileSystem/SysFS/RootDirectory.h @@ -17,9 +17,9 @@ class SysFSRootDirectory final : public SysFSDirectory { public: virtual StringView name() const override { return "."sv; } static NonnullRefPtr create(); - virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; private: + virtual bool is_root_directory() const override final { return true; } SysFSRootDirectory(); RefPtr m_buses_directory; }; diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp index 9b46be9f4e..e2f99411b3 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp @@ -23,9 +23,12 @@ UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize() UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory() : SysFSDirectory(SysFSComponentRegistry::the().buses_directory()) { - MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { - auto pci_device = PCIDeviceSysFSDirectory::create(*this, device_identifier.address()); - m_components.append(pci_device); + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { + auto pci_device = PCIDeviceSysFSDirectory::create(*this, device_identifier.address()); + list.append(pci_device); + })); + return {}; })); } diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp index 1431e68ac4..0719d73058 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/PCI/DeviceDirectory.cpp @@ -17,7 +17,26 @@ UNMAP_AFTER_INIT NonnullRefPtr PCIDeviceSysFSDirectory: { // FIXME: Handle allocation failure gracefully auto device_name = MUST(KString::formatted("{:04x}:{:02x}:{:02x}.{}", address.domain(), address.bus(), address.device(), address.function())); - return adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, address)); + auto directory = adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(move(device_name), parent_directory, address)); + MUST(directory->m_child_components.with([&](auto& list) -> ErrorOr { + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::VENDOR_ID, 2)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::DEVICE_ID, 2)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::CLASS, 1)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::SUBCLASS, 1)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::REVISION_ID, 1)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::PROG_IF, 1)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::SUBSYSTEM_VENDOR_ID, 2)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::SUBSYSTEM_ID, 2)); + + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR0, 4)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR1, 4)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR2, 4)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR3, 4)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR4, 4)); + list.append(PCIDeviceAttributeSysFSComponent::create(*directory, PCI::RegisterOffset::BAR5, 4)); + return {}; + })); + return directory; } UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(NonnullOwnPtr device_directory_name, SysFSDirectory const& parent_directory, PCI::Address address) @@ -25,21 +44,6 @@ UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(NonnullOwnPtr< , m_address(address) , m_device_directory_name(move(device_directory_name)) { - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::VENDOR_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::DEVICE_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::CLASS, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBCLASS, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::REVISION_ID, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::PROG_IF, 1)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBSYSTEM_VENDOR_ID, 2)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::SUBSYSTEM_ID, 2)); - - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR0, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR1, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR2, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR3, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR4, 4)); - m_components.append(PCIDeviceAttributeSysFSComponent::create(*this, PCI::RegisterOffset::BAR5, 4)); } } diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp index bcd77960dd..4f31888a87 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.cpp @@ -12,32 +12,6 @@ namespace Kernel { static SysFSUSBBusDirectory* s_procfs_usb_bus_directory; -ErrorOr SysFSUSBBusDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const -{ - SpinlockLocker lock(m_lock); - // Note: if the parent directory is null, it means something bad happened as this should not happen for the USB directory. - VERIFY(m_parent_directory); - TRY(callback({ "."sv, { fsid, component_index() }, 0 })); - TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 })); - - for (auto const& device_node : m_device_nodes) { - InodeIdentifier identifier = { fsid, device_node.component_index() }; - TRY(callback({ device_node.name(), identifier, 0 })); - } - return {}; -} - -RefPtr SysFSUSBBusDirectory::lookup(StringView name) -{ - SpinlockLocker lock(m_lock); - for (auto& device_node : m_device_nodes) { - if (device_node.name() == name) { - return device_node; - } - } - return {}; -} - RefPtr SysFSUSBBusDirectory::device_node_for(USB::Device& device) { RefPtr checked_device = device; diff --git a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h index 871303c01a..197e597bcf 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h +++ b/Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h @@ -23,9 +23,6 @@ public: void plug(USB::Device&); void unplug(USB::Device&); - virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; - virtual RefPtr lookup(StringView name) override; - private: explicit SysFSUSBBusDirectory(SysFSBusDirectory&); diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.cpp index feeea0634d..234f6d37a5 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.cpp @@ -28,31 +28,4 @@ SysFSBlockDevicesDirectory& SysFSBlockDevicesDirectory::the() return *s_the; } -ErrorOr SysFSBlockDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const -{ - VERIFY(m_parent_directory); - TRY(callback({ "."sv, { fsid, component_index() }, 0 })); - TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 })); - - return m_devices_list.with([&](auto& list) -> ErrorOr { - for (auto& exposed_device : list) { - VERIFY(exposed_device.is_block_device()); - TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 })); - } - return {}; - }); -} - -RefPtr SysFSBlockDevicesDirectory::lookup(StringView name) -{ - return m_devices_list.with([&](auto& list) -> RefPtr { - for (auto& exposed_device : list) { - VERIFY(exposed_device.is_block_device()); - if (exposed_device.name() == name) - return exposed_device; - } - return nullptr; - }); -} - } diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h index 9ae2ade125..8b23fcda06 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h @@ -17,18 +17,13 @@ class SysFSBlockDevicesDirectory final : public SysFSDirectory { public: virtual StringView name() const override { return "block"sv; } static NonnullRefPtr must_create(SysFSDeviceIdentifiersDirectory const&); - virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; - virtual RefPtr lookup(StringView name) override; static SysFSBlockDevicesDirectory& the(); - using DevicesList = SpinlockProtected>; - DevicesList& devices_list(Badge) { return m_devices_list; } + ChildList& devices_list(Badge) { return m_child_components; } private: explicit SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const&); - - DevicesList m_devices_list; }; } diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.cpp b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.cpp index 9d59452404..4bc3fc6983 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.cpp @@ -21,20 +21,6 @@ SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDeviceIdenti { s_the = this; } -ErrorOr SysFSCharacterDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const -{ - VERIFY(m_parent_directory); - TRY(callback({ "."sv, { fsid, component_index() }, 0 })); - TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 })); - - return m_devices_list.with([&](auto& list) -> ErrorOr { - for (auto& exposed_device : list) { - VERIFY(!exposed_device.is_block_device()); - TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 })); - } - return {}; - }); -} SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::the() { @@ -42,16 +28,4 @@ SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::the() return *s_the; } -RefPtr SysFSCharacterDevicesDirectory::lookup(StringView name) -{ - return m_devices_list.with([&](auto& list) -> RefPtr { - for (auto& exposed_device : list) { - VERIFY(!exposed_device.is_block_device()); - if (exposed_device.name() == name) - return exposed_device; - } - return nullptr; - }); -} - } diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h index c273cf820f..e6714124a3 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h @@ -17,18 +17,13 @@ class SysFSCharacterDevicesDirectory final : public SysFSDirectory { public: virtual StringView name() const override { return "char"sv; } static NonnullRefPtr must_create(SysFSDeviceIdentifiersDirectory const&); - virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; - virtual RefPtr lookup(StringView name) override; static SysFSCharacterDevicesDirectory& the(); - using DevicesList = SpinlockProtected>; - DevicesList& devices_list(Badge) { return m_devices_list; } + ChildList& devices_list(Badge) { return m_child_components; } private: explicit SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const&); - - DevicesList m_devices_list; }; } diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h index 479b1b0b4e..3f9650fdc7 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h @@ -25,7 +25,6 @@ public: private: SysFSDeviceComponent(NonnullOwnPtr major_minor_formatted_device_name, Device const&); - IntrusiveListNode> m_list_node; bool m_block_device; NonnullOwnPtr m_major_minor_formatted_device_name; diff --git a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.cpp b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.cpp index 893c798bb6..32b51391e5 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.cpp @@ -15,8 +15,12 @@ namespace Kernel { UNMAP_AFTER_INIT NonnullRefPtr SysFSDeviceIdentifiersDirectory::must_create(SysFSRootDirectory const& root_directory) { auto devices_directory = adopt_ref_if_nonnull(new SysFSDeviceIdentifiersDirectory(root_directory)).release_nonnull(); - devices_directory->m_components.append(SysFSBlockDevicesDirectory::must_create(*devices_directory)); - devices_directory->m_components.append(SysFSCharacterDevicesDirectory::must_create(*devices_directory)); + MUST(devices_directory->m_child_components.with([&](auto& list) -> ErrorOr { + list.append(SysFSBlockDevicesDirectory::must_create(*devices_directory)); + list.append(SysFSCharacterDevicesDirectory::must_create(*devices_directory)); + return {}; + })); + return devices_directory; } SysFSDeviceIdentifiersDirectory::SysFSDeviceIdentifiersDirectory(SysFSRootDirectory const& root_directory) diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp index 5fa0c6def0..bc1532bd94 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp @@ -58,8 +58,11 @@ void BIOSSysFSDirectory::create_components() dbgln("BIOSSysFSDirectory: invalid smbios structure table length"); return; } - m_components.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::DMIEntryPoint, m_dmi_entry_point, m_dmi_entry_point_length)); - m_components.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::SMBIOSTable, m_smbios_structure_table, m_smbios_structure_table_length)); + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + list.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::DMIEntryPoint, m_dmi_entry_point, m_dmi_entry_point_length)); + list.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::SMBIOSTable, m_smbios_structure_table, m_smbios_structure_table_length)); + return {}; + })); } UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer() diff --git a/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp b/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp index b21451678c..3b481971fc 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.cpp @@ -22,10 +22,13 @@ UNMAP_AFTER_INIT void FirmwareSysFSDirectory::initialize() void FirmwareSysFSDirectory::create_components() { - m_components.append(BIOSSysFSDirectory::must_create(*this)); - if (ACPI::is_enabled()) - m_components.append(ACPI::ACPISysFSDirectory::must_create(*this)); - m_components.append(PowerStateSwitchNode::must_create(*this)); + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + list.append(BIOSSysFSDirectory::must_create(*this)); + if (ACPI::is_enabled()) + list.append(ACPI::ACPISysFSDirectory::must_create(*this)); + list.append(PowerStateSwitchNode::must_create(*this)); + return {}; + })); } UNMAP_AFTER_INIT FirmwareSysFSDirectory::FirmwareSysFSDirectory() diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index 5be352e4f2..04f94f766e 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -70,28 +70,31 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(NonnullOwnPtr t UNMAP_AFTER_INIT void ACPISysFSDirectory::find_tables_and_register_them_as_components() { - NonnullRefPtrVector components; size_t ssdt_count = 0; - ACPI::Parser::the()->enumerate_static_tables([&](StringView signature, PhysicalAddress p_table, size_t length) { - if (signature == "SSDT") { - auto component_name = KString::formatted("{:4s}{}", signature.characters_without_null_termination(), ssdt_count).release_value_but_fixme_should_propagate_errors(); - components.append(ACPISysFSComponent::create(component_name->view(), p_table, length)); - ssdt_count++; - return; + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + ACPI::Parser::the()->enumerate_static_tables([&](StringView signature, PhysicalAddress p_table, size_t length) { + if (signature == "SSDT") { + auto component_name = KString::formatted("{:4s}{}", signature.characters_without_null_termination(), ssdt_count).release_value_but_fixme_should_propagate_errors(); + list.append(ACPISysFSComponent::create(component_name->view(), p_table, length)); + ssdt_count++; + return; + } + list.append(ACPISysFSComponent::create(signature, p_table, length)); + }); + return {}; + })); + + MUST(m_child_components.with([&](auto& list) -> ErrorOr { + auto rsdp = Memory::map_typed(ACPI::Parser::the()->rsdp()).release_value_but_fixme_should_propagate_errors(); + list.append(ACPISysFSComponent::create("RSDP"sv, ACPI::Parser::the()->rsdp(), rsdp->base.revision == 0 ? sizeof(Structures::RSDPDescriptor) : rsdp->length)); + auto main_system_description_table = Memory::map_typed(ACPI::Parser::the()->main_system_description_table()).release_value_but_fixme_should_propagate_errors(); + if (ACPI::Parser::the()->is_xsdt_supported()) { + list.append(ACPISysFSComponent::create("XSDT"sv, ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length)); + } else { + list.append(ACPISysFSComponent::create("RSDT"sv, ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length)); } - components.append(ACPISysFSComponent::create(signature, p_table, length)); - }); - m_components = components; - - auto rsdp = Memory::map_typed(ACPI::Parser::the()->rsdp()).release_value_but_fixme_should_propagate_errors(); - m_components.append(ACPISysFSComponent::create("RSDP"sv, ACPI::Parser::the()->rsdp(), rsdp->base.revision == 0 ? sizeof(Structures::RSDPDescriptor) : rsdp->length)); - - auto main_system_description_table = Memory::map_typed(ACPI::Parser::the()->main_system_description_table()).release_value_but_fixme_should_propagate_errors(); - if (ACPI::Parser::the()->is_xsdt_supported()) { - m_components.append(ACPISysFSComponent::create("XSDT"sv, ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length)); - } else { - m_components.append(ACPISysFSComponent::create("RSDT"sv, ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length)); - } + return {}; + })); } UNMAP_AFTER_INIT NonnullRefPtr ACPISysFSDirectory::must_create(FirmwareSysFSDirectory& firmware_directory)