/* * Copyright (c) 2022, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include namespace Kernel { NonnullRefPtr SysFSRootDirectory::create() { return adopt_ref(*new (nothrow) SysFSRootDirectory); } ErrorOr SysFSRootDirectory::traverse_as_directory(FileSystemID fsid, Function(FileSystem::DirectoryEntryView const&)> callback) const { MutexLocker locker(m_traverse_lock); TRY(callback({ "."sv, { fsid, component_index() }, 0 })); TRY(callback({ ".."sv, { fsid, 0 }, 0 })); for (auto const& component : m_components) { InodeIdentifier identifier = { fsid, component.component_index() }; TRY(callback({ component.name(), identifier, 0 })); } return {}; } SysFSRootDirectory::SysFSRootDirectory() { auto buses_directory = SysFSBusDirectory::must_create(*this); auto device_identifiers_directory = SysFSDeviceIdentifiersDirectory::must_create(*this); m_components.append(buses_directory); m_components.append(device_identifiers_directory); m_buses_directory = buses_directory; } }