1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel/SysFS: Migrate components code from SysFS.cpp to the SysFS folder

This commit is contained in:
Liav A 2022-04-22 12:46:19 +03:00 committed by Andreas Kling
parent 4d05a41b30
commit 23c1c40e86
29 changed files with 496 additions and 286 deletions

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/CharacterDevicesDirectory.h>
#include <Kernel/Sections.h>
namespace Kernel {
NonnullRefPtr<SysFSCharacterDevicesDirectory> SysFSCharacterDevicesDirectory::must_create(SysFSDevicesDirectory const& devices_directory)
{
return adopt_ref_if_nonnull(new SysFSCharacterDevicesDirectory(devices_directory)).release_nonnull();
}
SysFSCharacterDevicesDirectory::SysFSCharacterDevicesDirectory(SysFSDevicesDirectory const& devices_directory)
: SysFSDirectory(devices_directory)
{
}
ErrorOr<void> SysFSCharacterDevicesDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
VERIFY(m_parent_directory);
TRY(callback({ ".", { fsid, component_index() }, 0 }));
TRY(callback({ "..", { fsid, m_parent_directory->component_index() }, 0 }));
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> ErrorOr<void> {
for (auto& exposed_device : list) {
if (exposed_device.is_block_device())
continue;
TRY(callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 }));
}
return {};
});
}
RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
{
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
for (auto& exposed_device : list) {
if (exposed_device.is_block_device())
continue;
if (exposed_device.name() == name)
return exposed_device;
}
return nullptr;
});
}
}