mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:27: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
|
@ -28,31 +28,4 @@ SysFSBlockDevicesDirectory& SysFSBlockDevicesDirectory::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:
|
||||
virtual StringView name() const override { return "block"sv; }
|
||||
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();
|
||||
|
||||
using DevicesList = SpinlockProtected<IntrusiveList<&SysFSDeviceComponent::m_list_node>>;
|
||||
DevicesList& devices_list(Badge<Device>) { return m_devices_list; }
|
||||
ChildList& devices_list(Badge<Device>) { return m_child_components; }
|
||||
|
||||
private:
|
||||
explicit SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||
|
||||
DevicesList m_devices_list;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,20 +21,6 @@ SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDeviceIdenti
|
|||
{
|
||||
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()
|
||||
{
|
||||
|
@ -42,16 +28,4 @@ SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::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:
|
||||
virtual StringView name() const override { return "char"sv; }
|
||||
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();
|
||||
|
||||
using DevicesList = SpinlockProtected<IntrusiveList<&SysFSDeviceComponent::m_list_node>>;
|
||||
DevicesList& devices_list(Badge<Device>) { return m_devices_list; }
|
||||
ChildList& devices_list(Badge<Device>) { return m_child_components; }
|
||||
|
||||
private:
|
||||
explicit SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||
|
||||
DevicesList m_devices_list;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ public:
|
|||
|
||||
private:
|
||||
SysFSDeviceComponent(NonnullOwnPtr<KString> major_minor_formatted_device_name, Device const&);
|
||||
IntrusiveListNode<SysFSDeviceComponent, NonnullRefPtr<SysFSDeviceComponent>> m_list_node;
|
||||
bool m_block_device;
|
||||
|
||||
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)
|
||||
{
|
||||
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<void> {
|
||||
list.append(SysFSBlockDevicesDirectory::must_create(*devices_directory));
|
||||
list.append(SysFSCharacterDevicesDirectory::must_create(*devices_directory));
|
||||
return {};
|
||||
}));
|
||||
|
||||
return devices_directory;
|
||||
}
|
||||
SysFSDeviceIdentifiersDirectory::SysFSDeviceIdentifiersDirectory(SysFSRootDirectory const& root_directory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue