mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +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:
parent
ecc29bb52e
commit
6733f19b3c
11 changed files with 72 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <Kernel/FileSystem/SysFS/Component.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Device;
|
||||
class SysFSBlockDevicesDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
virtual StringView name() const override { return "block"sv; }
|
||||
|
@ -18,8 +20,15 @@ public:
|
|||
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; }
|
||||
|
||||
private:
|
||||
explicit SysFSBlockDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||
|
||||
DevicesList m_devices_list;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <Kernel/FileSystem/SysFS/Component.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/Directory.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Device;
|
||||
class SysFSCharacterDevicesDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
virtual StringView name() const override { return "char"sv; }
|
||||
|
@ -18,8 +20,15 @@ public:
|
|||
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; }
|
||||
|
||||
private:
|
||||
explicit SysFSCharacterDevicesDirectory(SysFSDeviceIdentifiersDirectory const&);
|
||||
|
||||
DevicesList m_devices_list;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ namespace Kernel {
|
|||
class SysFSDeviceComponent final
|
||||
: public SysFSComponent
|
||||
, public Weakable<SysFSDeviceComponent> {
|
||||
friend class SysFSComponentRegistry;
|
||||
friend class SysFSBlockDevicesDirectory;
|
||||
friend class SysFSCharacterDevicesDirectory;
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<SysFSDeviceComponent> must_create(Device const&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue