1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +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 SysFSBlockDevicesDirectory* s_the { nullptr };
NonnullRefPtr<SysFSBlockDevicesDirectory> SysFSBlockDevicesDirectory::must_create(SysFSDeviceIdentifiersDirectory const& devices_directory)
{
return adopt_ref_if_nonnull(new SysFSBlockDevicesDirectory(devices_directory)).release_nonnull();
@ -17,6 +19,13 @@ NonnullRefPtr<SysFSBlockDevicesDirectory> SysFSBlockDevicesDirectory::must_creat
SysFSBlockDevicesDirectory::SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const& devices_directory)
: SysFSDirectory(devices_directory)
{
s_the = this;
}
SysFSBlockDevicesDirectory& SysFSBlockDevicesDirectory::the()
{
VERIFY(s_the);
return *s_the;
}
ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
@ -25,10 +34,9 @@ ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(FileSystemID fsi
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 {};
@ -37,10 +45,9 @@ ErrorOr<void> SysFSBlockDevicesDirectory::traverse_as_directory(FileSystemID fsi
RefPtr<SysFSComponent> SysFSBlockDevicesDirectory::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;
}