mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
Kernel/SysFS: Mark SysFSDirectory traverse and lookup methods as final
This enforces us to remove duplicated code across the SysFS code. This results in great simplification of how the SysFS works now, because we enforce one way to treat SysFSDirectory objects.
This commit is contained in:
parent
6733f19b3c
commit
70afa0b171
18 changed files with 114 additions and 178 deletions
|
@ -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<void> {
|
||||
MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
||||
auto pci_device = PCIDeviceSysFSDirectory::create(*this, device_identifier.address());
|
||||
list.append(pci_device);
|
||||
}));
|
||||
return {};
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,26 @@ UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> 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<void> {
|
||||
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<KString> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,32 +12,6 @@ namespace Kernel {
|
|||
|
||||
static SysFSUSBBusDirectory* s_procfs_usb_bus_directory;
|
||||
|
||||
ErrorOr<void> SysFSUSBBusDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(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<SysFSComponent> 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<SysFSUSBDeviceInformation> SysFSUSBBusDirectory::device_node_for(USB::Device& device)
|
||||
{
|
||||
RefPtr<USB::Device> checked_device = device;
|
||||
|
|
|
@ -23,9 +23,6 @@ public:
|
|||
void plug(USB::Device&);
|
||||
void unplug(USB::Device&);
|
||||
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
||||
|
||||
private:
|
||||
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue