1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 00:57:43 +00:00

Kernel/SysFS: Reduce the responsibilities of the Registry object

Instead, let the /sys/dev/block and /sys/dev/char directories to handle
the registering part of SysFSDeviceComponents by themselves.
This commit is contained in:
Liav A 2022-04-23 00:26:36 +03:00 committed by Andreas Kling
parent ecc29bb52e
commit 6733f19b3c
11 changed files with 72 additions and 31 deletions

View file

@ -10,6 +10,8 @@
namespace Kernel {
static SysFSCharacterDevicesDirectory* s_the { nullptr };
NonnullRefPtr<SysFSCharacterDevicesDirectory> SysFSCharacterDevicesDirectory::must_create(SysFSDeviceIdentifiersDirectory const& devices_directory)
{
return adopt_ref_if_nonnull(new SysFSCharacterDevicesDirectory(devices_directory)).release_nonnull();
@ -17,6 +19,7 @@ NonnullRefPtr<SysFSCharacterDevicesDirectory> SysFSCharacterDevicesDirectory::mu
SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const& devices_directory)
: SysFSDirectory(devices_directory)
{
s_the = this;
}
ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
@ -24,22 +27,26 @@ ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(FileSystemID
TRY(callback({ "."sv, { fsid, component_index() }, 0 }));
TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 }));
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> ErrorOr<void> {
return m_devices_list.with([&](auto& list) -> ErrorOr<void> {
for (auto& exposed_device : list) {
if (exposed_device.is_block_device())
continue;
VERIFY(!exposed_device.is_block_device());
TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 }));
}
return {};
});
}
SysFSCharacterDevicesDirectory& SysFSCharacterDevicesDirectory::the()
{
VERIFY(s_the);
return *s_the;
}
RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
{
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
return m_devices_list.with([&](auto& list) -> RefPtr<SysFSComponent> {
for (auto& exposed_device : list) {
if (exposed_device.is_block_device())
continue;
VERIFY(!exposed_device.is_block_device());
if (exposed_device.name() == name)
return exposed_device;
}