mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +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
|
@ -106,26 +106,33 @@ SysFSSymbolicLink::SysFSSymbolicLink(SysFSDirectory const& parent_directory, Sys
|
|||
|
||||
ErrorOr<void> SysFSDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
{
|
||||
MutexLocker locker(m_traverse_lock);
|
||||
VERIFY(m_parent_directory);
|
||||
TRY(callback({ "."sv, { fsid, component_index() }, 0 }));
|
||||
TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 }));
|
||||
|
||||
for (auto& component : m_components) {
|
||||
InodeIdentifier identifier = { fsid, component.component_index() };
|
||||
TRY(callback({ component.name(), identifier, 0 }));
|
||||
if (is_root_directory()) {
|
||||
TRY(callback({ ".."sv, { fsid, component_index() }, 0 }));
|
||||
} else {
|
||||
VERIFY(m_parent_directory);
|
||||
TRY(callback({ ".."sv, { fsid, m_parent_directory->component_index() }, 0 }));
|
||||
}
|
||||
return {};
|
||||
|
||||
return m_child_components.with([&](auto& list) -> ErrorOr<void> {
|
||||
for (auto& child_component : list) {
|
||||
InodeIdentifier identifier = { fsid, child_component.component_index() };
|
||||
TRY(callback({ child_component.name(), identifier, 0 }));
|
||||
}
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
RefPtr<SysFSComponent> SysFSDirectory::lookup(StringView name)
|
||||
{
|
||||
for (auto& component : m_components) {
|
||||
if (component.name() == name) {
|
||||
return component;
|
||||
return m_child_components.with([&](auto& list) -> RefPtr<SysFSComponent> {
|
||||
for (auto& child_component : list) {
|
||||
if (child_component.name() == name) {
|
||||
return child_component;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
SysFSDirectory::SysFSDirectory(SysFSDirectory const& parent_directory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue