diff --git a/Kernel/FileSystem/Mount.cpp b/Kernel/FileSystem/Mount.cpp index 3dbb8884777..dd7ec867dcc 100644 --- a/Kernel/FileSystem/Mount.cpp +++ b/Kernel/FileSystem/Mount.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,47 +11,41 @@ namespace Kernel { -Mount::Mount(NonnullRefPtr guest_fs, Custody* host_custody, int flags) - : m_guest(guest_fs->root_inode()) - , m_guest_fs(guest_fs) - , m_host_custody(host_custody) +Mount::Mount(NonnullRefPtr guest_fs, RefPtr host_custody, int flags) + : m_guest_fs(move(guest_fs)) + , m_guest(m_guest_fs->root_inode()) + , m_host_custody(move(host_custody)) , m_flags(flags) { } -Mount::Mount(Inode& source, Custody& host_custody, int flags) - : m_guest(source) - , m_guest_fs(source.fs()) - , m_host_custody(host_custody) +Mount::Mount(NonnullRefPtr source, NonnullRefPtr host_custody, int flags) + : m_guest_fs(source->fs()) + , m_guest(move(source)) + , m_host_custody(move(host_custody)) , m_flags(flags) { } ErrorOr> Mount::absolute_path() const { - return m_host_custody.with([&](auto& host_custody) -> ErrorOr> { - if (!host_custody) - return KString::try_create("/"sv); - return host_custody->try_serialize_absolute_path(); - }); + if (!m_host_custody) + return KString::try_create("/"sv); + return m_host_custody->try_serialize_absolute_path(); } RefPtr Mount::host() { - return m_host_custody.with([](auto& host_custody) -> RefPtr { - if (!host_custody) - return nullptr; - return &host_custody->inode(); - }); + if (!m_host_custody) + return nullptr; + return m_host_custody->inode(); } RefPtr Mount::host() const { - return m_host_custody.with([](auto& host_custody) -> RefPtr { - if (!host_custody) - return nullptr; - return &host_custody->inode(); - }); + if (!m_host_custody) + return nullptr; + return m_host_custody->inode(); } } diff --git a/Kernel/FileSystem/Mount.h b/Kernel/FileSystem/Mount.h index 25cb8c1abd7..8251bc74be0 100644 --- a/Kernel/FileSystem/Mount.h +++ b/Kernel/FileSystem/Mount.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2018-2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,11 +17,13 @@ namespace Kernel { class VirtualFileSystem; class Mount { + AK_MAKE_NONCOPYABLE(Mount); + AK_MAKE_NONMOVABLE(Mount); friend class VirtualFileSystem; public: - Mount(NonnullRefPtr, Custody* host_custody, int flags); - Mount(Inode& source, Custody& host_custody, int flags); + Mount(NonnullRefPtr, RefPtr host_custody, int flags); + Mount(NonnullRefPtr source, NonnullRefPtr host_custody, int flags); RefPtr host() const; RefPtr host(); @@ -38,10 +40,10 @@ public: void set_flags(int flags) { m_flags = flags; } private: - NonnullRefPtr m_guest; - NonnullRefPtr m_guest_fs; - SpinlockProtected, LockRank::None> m_host_custody; - int m_flags; + NonnullRefPtr const m_guest_fs; + NonnullRefPtr const m_guest; + RefPtr const m_host_custody; + int m_flags { 0 }; IntrusiveListNode m_vfs_list_node; };