mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +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
|
@ -106,26 +106,33 @@ SysFSSymbolicLink::SysFSSymbolicLink(SysFSDirectory const& parent_directory, Sys
|
||||||
|
|
||||||
ErrorOr<void> SysFSDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
ErrorOr<void> SysFSDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(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, component_index() }, 0 }));
|
||||||
TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 }));
|
if (is_root_directory()) {
|
||||||
|
TRY(callback({ ".."sv, { fsid, component_index() }, 0 }));
|
||||||
for (auto& component : m_components) {
|
} else {
|
||||||
InodeIdentifier identifier = { fsid, component.component_index() };
|
VERIFY(m_parent_directory);
|
||||||
TRY(callback({ component.name(), identifier, 0 }));
|
TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 }));
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
return m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
|
for (auto& child_component : list) {
|
||||||
|
InodeIdentifier identifier = { fsid, child_component.component_index() };
|
||||||
|
TRY(callback({ child_component.name(), identifier, 0 }));
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<SysFSComponent> SysFSDirectory::lookup(StringView name)
|
RefPtr<SysFSComponent> SysFSDirectory::lookup(StringView name)
|
||||||
{
|
{
|
||||||
for (auto& component : m_components) {
|
return m_child_components.with([&](auto& list) -> RefPtr<SysFSComponent> {
|
||||||
if (component.name() == name) {
|
for (auto& child_component : list) {
|
||||||
return component;
|
if (child_component.name() == name) {
|
||||||
|
return child_component;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return nullptr;
|
||||||
return {};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SysFSDirectory::SysFSDirectory(SysFSDirectory const& parent_directory)
|
SysFSDirectory::SysFSDirectory(SysFSDirectory const& parent_directory)
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct SysFSInodeData : public OpenFileDescriptionData {
|
||||||
|
|
||||||
class SysFSDirectory;
|
class SysFSDirectory;
|
||||||
class SysFSComponent : public RefCounted<SysFSComponent> {
|
class SysFSComponent : public RefCounted<SysFSComponent> {
|
||||||
|
friend class SysFSDirectory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual StringView name() const = 0;
|
virtual StringView name() const = 0;
|
||||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
|
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
|
||||||
|
@ -52,6 +54,8 @@ protected:
|
||||||
|
|
||||||
RefPtr<SysFSDirectory> m_parent_directory;
|
RefPtr<SysFSDirectory> m_parent_directory;
|
||||||
|
|
||||||
|
IntrusiveListNode<SysFSComponent, NonnullRefPtr<SysFSComponent>> m_list_node;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InodeIndex m_component_index {};
|
InodeIndex m_component_index {};
|
||||||
};
|
};
|
||||||
|
@ -72,17 +76,19 @@ protected:
|
||||||
|
|
||||||
class SysFSDirectory : public SysFSComponent {
|
class SysFSDirectory : public SysFSComponent {
|
||||||
public:
|
public:
|
||||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override final;
|
||||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
virtual RefPtr<SysFSComponent> lookup(StringView name) override final;
|
||||||
|
|
||||||
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
|
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
|
||||||
|
|
||||||
|
using ChildList = SpinlockProtected<IntrusiveList<&SysFSComponent::m_list_node>>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool is_root_directory() const { return false; }
|
||||||
|
|
||||||
SysFSDirectory() {};
|
SysFSDirectory() {};
|
||||||
explicit SysFSDirectory(SysFSDirectory const& parent_directory);
|
explicit SysFSDirectory(SysFSDirectory const& parent_directory);
|
||||||
NonnullRefPtrVector<SysFSComponent> m_components;
|
ChildList m_child_components;
|
||||||
|
|
||||||
mutable Mutex m_traverse_lock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ UNMAP_AFTER_INIT SysFSComponentRegistry::SysFSComponentRegistry()
|
||||||
UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component)
|
UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component)
|
||||||
{
|
{
|
||||||
SpinlockLocker locker(m_root_directory_lock);
|
SpinlockLocker locker(m_root_directory_lock);
|
||||||
m_root_directory->m_components.append(component);
|
MUST(m_root_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
|
list.append(component);
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
SysFSBusDirectory& SysFSComponentRegistry::buses_directory()
|
SysFSBusDirectory& SysFSComponentRegistry::buses_directory()
|
||||||
|
@ -43,7 +46,10 @@ SysFSBusDirectory& SysFSComponentRegistry::buses_directory()
|
||||||
void SysFSComponentRegistry::register_new_bus_directory(SysFSDirectory& new_bus_directory)
|
void SysFSComponentRegistry::register_new_bus_directory(SysFSDirectory& new_bus_directory)
|
||||||
{
|
{
|
||||||
VERIFY(!m_root_directory->m_buses_directory.is_null());
|
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<void> {
|
||||||
|
list.append(new_bus_directory);
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,25 +17,15 @@ NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create()
|
||||||
return adopt_ref(*new (nothrow) SysFSRootDirectory);
|
return adopt_ref(*new (nothrow) SysFSRootDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> SysFSRootDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(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()
|
SysFSRootDirectory::SysFSRootDirectory()
|
||||||
{
|
{
|
||||||
auto buses_directory = SysFSBusDirectory::must_create(*this);
|
auto buses_directory = SysFSBusDirectory::must_create(*this);
|
||||||
auto device_identifiers_directory = SysFSDeviceIdentifiersDirectory::must_create(*this);
|
auto device_identifiers_directory = SysFSDeviceIdentifiersDirectory::must_create(*this);
|
||||||
m_components.append(buses_directory);
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
m_components.append(device_identifiers_directory);
|
list.append(buses_directory);
|
||||||
|
list.append(device_identifiers_directory);
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
m_buses_directory = buses_directory;
|
m_buses_directory = buses_directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ class SysFSRootDirectory final : public SysFSDirectory {
|
||||||
public:
|
public:
|
||||||
virtual StringView name() const override { return "."sv; }
|
virtual StringView name() const override { return "."sv; }
|
||||||
static NonnullRefPtr<SysFSRootDirectory> create();
|
static NonnullRefPtr<SysFSRootDirectory> create();
|
||||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual bool is_root_directory() const override final { return true; }
|
||||||
SysFSRootDirectory();
|
SysFSRootDirectory();
|
||||||
RefPtr<SysFSBusDirectory> m_buses_directory;
|
RefPtr<SysFSBusDirectory> m_buses_directory;
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,9 +23,12 @@ UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
|
||||||
UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory()
|
UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory()
|
||||||
: SysFSDirectory(SysFSComponentRegistry::the().buses_directory())
|
: SysFSDirectory(SysFSComponentRegistry::the().buses_directory())
|
||||||
{
|
{
|
||||||
MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
auto pci_device = PCIDeviceSysFSDirectory::create(*this, device_identifier.address());
|
MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
||||||
m_components.append(pci_device);
|
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
|
// FIXME: Handle allocation failure gracefully
|
||||||
auto device_name = MUST(KString::formatted("{:04x}:{:02x}:{:02x}.{}", address.domain(), address.bus(), address.device(), address.function()));
|
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)
|
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_address(address)
|
||||||
, m_device_directory_name(move(device_directory_name))
|
, 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;
|
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<SysFSUSBDeviceInformation> SysFSUSBBusDirectory::device_node_for(USB::Device& device)
|
||||||
{
|
{
|
||||||
RefPtr<USB::Device> checked_device = device;
|
RefPtr<USB::Device> checked_device = device;
|
||||||
|
|
|
@ -23,9 +23,6 @@ public:
|
||||||
void plug(USB::Device&);
|
void plug(USB::Device&);
|
||||||
void unplug(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:
|
private:
|
||||||
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
|
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
|
||||||
|
|
||||||
|
|
|
@ -28,31 +28,4 @@ SysFSBlockDevicesDirectory& SysFSBlockDevicesDirectory::the()
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(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<void> {
|
|
||||||
for (auto& exposed_device : list) {
|
|
||||||
VERIFY(exposed_device.is_block_device());
|
|
||||||
TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 }));
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<SysFSComponent> SysFSBlockDevicesDirectory::lookup(StringView name)
|
|
||||||
{
|
|
||||||
return m_devices_list.with([&](auto& list) -> RefPtr<SysFSComponent> {
|
|
||||||
for (auto& exposed_device : list) {
|
|
||||||
VERIFY(exposed_device.is_block_device());
|
|
||||||
if (exposed_device.name() == name)
|
|
||||||
return exposed_device;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,13 @@ class SysFSBlockDevicesDirectory final : public SysFSDirectory {
|
||||||
public:
|
public:
|
||||||
virtual StringView name() const override { return "block"sv; }
|
virtual StringView name() const override { return "block"sv; }
|
||||||
static NonnullRefPtr<SysFSBlockDevicesDirectory> must_create(SysFSDeviceIdentifiersDirectory const&);
|
static NonnullRefPtr<SysFSBlockDevicesDirectory> must_create(SysFSDeviceIdentifiersDirectory const&);
|
||||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
|
||||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
|
||||||
|
|
||||||
static SysFSBlockDevicesDirectory& the();
|
static SysFSBlockDevicesDirectory& the();
|
||||||
|
|
||||||
using DevicesList = SpinlockProtected<IntrusiveList<&SysFSDeviceComponent::m_list_node>>;
|
ChildList& devices_list(Badge<Device>) { return m_child_components; }
|
||||||
DevicesList& devices_list(Badge<Device>) { return m_devices_list; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
explicit SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||||
|
|
||||||
DevicesList m_devices_list;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,6 @@ SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDeviceIdenti
|
||||||
{
|
{
|
||||||
s_the = this;
|
s_the = this;
|
||||||
}
|
}
|
||||||
ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(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<void> {
|
|
||||||
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()
|
SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::the()
|
||||||
{
|
{
|
||||||
|
@ -42,16 +28,4 @@ SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::the()
|
||||||
return *s_the;
|
return *s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
|
|
||||||
{
|
|
||||||
return m_devices_list.with([&](auto& list) -> RefPtr<SysFSComponent> {
|
|
||||||
for (auto& exposed_device : list) {
|
|
||||||
VERIFY(!exposed_device.is_block_device());
|
|
||||||
if (exposed_device.name() == name)
|
|
||||||
return exposed_device;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,13 @@ class SysFSCharacterDevicesDirectory final : public SysFSDirectory {
|
||||||
public:
|
public:
|
||||||
virtual StringView name() const override { return "char"sv; }
|
virtual StringView name() const override { return "char"sv; }
|
||||||
static NonnullRefPtr<SysFSCharacterDevicesDirectory> must_create(SysFSDeviceIdentifiersDirectory const&);
|
static NonnullRefPtr<SysFSCharacterDevicesDirectory> must_create(SysFSDeviceIdentifiersDirectory const&);
|
||||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
|
||||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
|
||||||
|
|
||||||
static SysFSCharacterDevicesDirectory& the();
|
static SysFSCharacterDevicesDirectory& the();
|
||||||
|
|
||||||
using DevicesList = SpinlockProtected<IntrusiveList<&SysFSDeviceComponent::m_list_node>>;
|
ChildList& devices_list(Badge<Device>) { return m_child_components; }
|
||||||
DevicesList& devices_list(Badge<Device>) { return m_devices_list; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
explicit SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||||
|
|
||||||
DevicesList m_devices_list;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SysFSDeviceComponent(NonnullOwnPtr<KString> major_minor_formatted_device_name, Device const&);
|
SysFSDeviceComponent(NonnullOwnPtr<KString> major_minor_formatted_device_name, Device const&);
|
||||||
IntrusiveListNode<SysFSDeviceComponent, NonnullRefPtr<SysFSDeviceComponent>> m_list_node;
|
|
||||||
bool m_block_device;
|
bool m_block_device;
|
||||||
|
|
||||||
NonnullOwnPtr<KString> m_major_minor_formatted_device_name;
|
NonnullOwnPtr<KString> m_major_minor_formatted_device_name;
|
||||||
|
|
|
@ -15,8 +15,12 @@ namespace Kernel {
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<SysFSDeviceIdentifiersDirectory> SysFSDeviceIdentifiersDirectory::must_create(SysFSRootDirectory const& root_directory)
|
UNMAP_AFTER_INIT NonnullRefPtr<SysFSDeviceIdentifiersDirectory> SysFSDeviceIdentifiersDirectory::must_create(SysFSRootDirectory const& root_directory)
|
||||||
{
|
{
|
||||||
auto devices_directory = adopt_ref_if_nonnull(new SysFSDeviceIdentifiersDirectory(root_directory)).release_nonnull();
|
auto devices_directory = adopt_ref_if_nonnull(new SysFSDeviceIdentifiersDirectory(root_directory)).release_nonnull();
|
||||||
devices_directory->m_components.append(SysFSBlockDevicesDirectory::must_create(*devices_directory));
|
MUST(devices_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
devices_directory->m_components.append(SysFSCharacterDevicesDirectory::must_create(*devices_directory));
|
list.append(SysFSBlockDevicesDirectory::must_create(*devices_directory));
|
||||||
|
list.append(SysFSCharacterDevicesDirectory::must_create(*devices_directory));
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
|
|
||||||
return devices_directory;
|
return devices_directory;
|
||||||
}
|
}
|
||||||
SysFSDeviceIdentifiersDirectory::SysFSDeviceIdentifiersDirectory(SysFSRootDirectory const& root_directory)
|
SysFSDeviceIdentifiersDirectory::SysFSDeviceIdentifiersDirectory(SysFSRootDirectory const& root_directory)
|
||||||
|
|
|
@ -58,8 +58,11 @@ void BIOSSysFSDirectory::create_components()
|
||||||
dbgln("BIOSSysFSDirectory: invalid smbios structure table length");
|
dbgln("BIOSSysFSDirectory: invalid smbios structure table length");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_components.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::DMIEntryPoint, m_dmi_entry_point, m_dmi_entry_point_length));
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
m_components.append(BIOSSysFSComponent::must_create(BIOSSysFSComponent::Type::SMBIOSTable, m_smbios_structure_table, m_smbios_structure_table_length));
|
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()
|
UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize_dmi_exposer()
|
||||||
|
|
|
@ -22,10 +22,13 @@ UNMAP_AFTER_INIT void FirmwareSysFSDirectory::initialize()
|
||||||
|
|
||||||
void FirmwareSysFSDirectory::create_components()
|
void FirmwareSysFSDirectory::create_components()
|
||||||
{
|
{
|
||||||
m_components.append(BIOSSysFSDirectory::must_create(*this));
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
if (ACPI::is_enabled())
|
list.append(BIOSSysFSDirectory::must_create(*this));
|
||||||
m_components.append(ACPI::ACPISysFSDirectory::must_create(*this));
|
if (ACPI::is_enabled())
|
||||||
m_components.append(PowerStateSwitchNode::must_create(*this));
|
list.append(ACPI::ACPISysFSDirectory::must_create(*this));
|
||||||
|
list.append(PowerStateSwitchNode::must_create(*this));
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT FirmwareSysFSDirectory::FirmwareSysFSDirectory()
|
UNMAP_AFTER_INIT FirmwareSysFSDirectory::FirmwareSysFSDirectory()
|
||||||
|
|
|
@ -70,28 +70,31 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(NonnullOwnPtr<KString> t
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void ACPISysFSDirectory::find_tables_and_register_them_as_components()
|
UNMAP_AFTER_INIT void ACPISysFSDirectory::find_tables_and_register_them_as_components()
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<SysFSComponent> components;
|
|
||||||
size_t ssdt_count = 0;
|
size_t ssdt_count = 0;
|
||||||
ACPI::Parser::the()->enumerate_static_tables([&](StringView signature, PhysicalAddress p_table, size_t length) {
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
if (signature == "SSDT") {
|
ACPI::Parser::the()->enumerate_static_tables([&](StringView signature, PhysicalAddress p_table, size_t length) {
|
||||||
auto component_name = KString::formatted("{:4s}{}", signature.characters_without_null_termination(), ssdt_count).release_value_but_fixme_should_propagate_errors();
|
if (signature == "SSDT") {
|
||||||
components.append(ACPISysFSComponent::create(component_name->view(), p_table, length));
|
auto component_name = KString::formatted("{:4s}{}", signature.characters_without_null_termination(), ssdt_count).release_value_but_fixme_should_propagate_errors();
|
||||||
ssdt_count++;
|
list.append(ACPISysFSComponent::create(component_name->view(), p_table, length));
|
||||||
return;
|
ssdt_count++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.append(ACPISysFSComponent::create(signature, p_table, length));
|
||||||
|
});
|
||||||
|
return {};
|
||||||
|
}));
|
||||||
|
|
||||||
|
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||||
|
auto rsdp = Memory::map_typed<Structures::RSDPDescriptor20>(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<Structures::SDTHeader>(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));
|
return {};
|
||||||
});
|
}));
|
||||||
m_components = components;
|
|
||||||
|
|
||||||
auto rsdp = Memory::map_typed<Structures::RSDPDescriptor20>(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<Structures::SDTHeader>(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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSDirectory> ACPISysFSDirectory::must_create(FirmwareSysFSDirectory& firmware_directory)
|
UNMAP_AFTER_INIT NonnullRefPtr<ACPISysFSDirectory> ACPISysFSDirectory::must_create(FirmwareSysFSDirectory& firmware_directory)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue