/* * Copyright (c) 2024, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace Kernel { class VFSRootContext : public AtomicRefCounted { AK_MAKE_NONCOPYABLE(VFSRootContext); AK_MAKE_NONMOVABLE(VFSRootContext); public: AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, IndexID); static VFSRootContext const& empty_context_for_kernel_processes(); static Custody const& empty_context_custody_for_kernel_processes(); static void initialize_empty_ramfs_root_context_for_kernel_processes(); static ErrorOr> create_with_empty_ramfs(); static ErrorOr> create_empty(); SpinlockProtected, LockRank::None>& root_custody() { return m_root_custody; } SpinlockProtected, LockRank::None> const& root_custody() const { return m_root_custody; } SpinlockProtected, LockRank::None>& mounts() { return m_mounts; } SpinlockProtected, LockRank::None> const& mounts() const { return m_mounts; } struct Attributes { SetOnce attached_by_process; SetOnce immutable; }; SpinlockProtected& attributes() { return m_attributes; } bool mount_point_exists_at_custody(Custody& mount_point); enum class DoBindMount { Yes, No, }; ErrorOr add_new_mount(DoBindMount, Inode& source, Custody& mount_point, int flags); IndexID id() const { return m_id; } void set_attached(Badge); ErrorOr for_each_mount(Function(Mount const&)>) const; private: VFSRootContext(NonnullRefPtr custody); static void add_to_mounts_list_and_increment_fs_mounted_count(DoBindMount do_bind_mount, IntrusiveList<&Mount::m_vfs_list_node>&, NonnullOwnPtr); SpinlockProtected m_attributes {}; SpinlockProtected, LockRank::None> m_root_custody; SpinlockProtected, LockRank::None> m_mounts {}; IntrusiveListNode> m_list_node; IndexID m_id; // NOTE: This method is implemented in Kernel/FileSystem/VirtualFileSystem.cpp static SpinlockProtected, LockRank::FileSystem>& all_root_contexts_list(); public: using List = IntrusiveList<&VFSRootContext::m_list_node>; // NOTE: These methods are implemented in Kernel/FileSystem/VirtualFileSystem.cpp static SpinlockProtected& all_root_contexts_list(Badge); static SpinlockProtected& all_root_contexts_list(Badge); }; }