summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-11 00:46:06 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-11 00:51:06 +0200
commit6a27de2d946c649af0fe78dfef07f9e183af3af5 (patch)
tree6b0d6856e0d37517e1341dc48418b0997f844112 /Kernel
parent79552c91d5812c17914adea09ae2b8a94b153d0e (diff)
downloadserenity-6a27de2d946c649af0fe78dfef07f9e183af3af5.zip
Kernel: Make VirtualFileSystem::Mount a top-level class
And move it to its own compilation unit.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/CMakeLists.txt1
-rw-r--r--Kernel/FileSystem/Forward.h17
-rw-r--r--Kernel/FileSystem/Mount.cpp51
-rw-r--r--Kernel/FileSystem/Mount.h39
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.cpp37
-rw-r--r--Kernel/FileSystem/VirtualFileSystem.h26
6 files changed, 109 insertions, 62 deletions
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt
index dd4ea7cb0b..0a2cc43a36 100644
--- a/Kernel/CMakeLists.txt
+++ b/Kernel/CMakeLists.txt
@@ -109,6 +109,7 @@ set(KERNEL_SOURCES
FileSystem/Inode.cpp
FileSystem/InodeFile.cpp
FileSystem/InodeWatcher.cpp
+ FileSystem/Mount.cpp
FileSystem/Plan9FileSystem.cpp
FileSystem/ProcFS.cpp
FileSystem/SysFS.cpp
diff --git a/Kernel/FileSystem/Forward.h b/Kernel/FileSystem/Forward.h
new file mode 100644
index 0000000000..5216927667
--- /dev/null
+++ b/Kernel/FileSystem/Forward.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace Kernel {
+
+class FileSystem;
+class Inode;
+class Mount;
+class VirtualFileSystem;
+struct InodeMetadata;
+
+}
diff --git a/Kernel/FileSystem/Mount.cpp b/Kernel/FileSystem/Mount.cpp
new file mode 100644
index 0000000000..1f05f36c81
--- /dev/null
+++ b/Kernel/FileSystem/Mount.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <Kernel/FileSystem/Custody.h>
+#include <Kernel/FileSystem/FileSystem.h>
+#include <Kernel/FileSystem/Inode.h>
+#include <Kernel/FileSystem/Mount.h>
+
+namespace Kernel {
+
+Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
+ : m_guest(guest_fs.root_inode())
+ , m_guest_fs(guest_fs)
+ , m_host_custody(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)
+ , m_flags(flags)
+{
+}
+
+String Mount::absolute_path() const
+{
+ if (!m_host_custody)
+ return "/";
+ return m_host_custody->absolute_path();
+}
+
+Inode* Mount::host()
+{
+ if (!m_host_custody)
+ return nullptr;
+ return &m_host_custody->inode();
+}
+
+Inode const* Mount::host() const
+{
+ if (!m_host_custody)
+ return nullptr;
+ return &m_host_custody->inode();
+}
+
+}
diff --git a/Kernel/FileSystem/Mount.h b/Kernel/FileSystem/Mount.h
new file mode 100644
index 0000000000..44397744cc
--- /dev/null
+++ b/Kernel/FileSystem/Mount.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/NonnullRefPtr.h>
+#include <Kernel/FileSystem/Forward.h>
+
+namespace Kernel {
+
+class Mount {
+public:
+ Mount(FileSystem&, Custody* host_custody, int flags);
+ Mount(Inode& source, Custody& host_custody, int flags);
+
+ Inode const* host() const;
+ Inode* host();
+
+ Inode const& guest() const { return *m_guest; }
+ Inode& guest() { return *m_guest; }
+
+ FileSystem const& guest_fs() const { return *m_guest_fs; }
+
+ String absolute_path() const;
+
+ int flags() const { return m_flags; }
+ void set_flags(int flags) { m_flags = flags; }
+
+private:
+ NonnullRefPtr<Inode> m_guest;
+ NonnullRefPtr<FileSystem> m_guest_fs;
+ RefPtr<Custody> m_host_custody;
+ int m_flags;
+};
+
+}
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp
index ab30db3000..1066de52e4 100644
--- a/Kernel/FileSystem/VirtualFileSystem.cpp
+++ b/Kernel/FileSystem/VirtualFileSystem.cpp
@@ -780,43 +780,6 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
return parent_inode.remove_child(KLexicalPath::basename(path));
}
-VirtualFileSystem::Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
- : m_guest(guest_fs.root_inode())
- , m_guest_fs(guest_fs)
- , m_host_custody(host_custody)
- , m_flags(flags)
-{
-}
-
-VirtualFileSystem::Mount::Mount(Inode& source, Custody& host_custody, int flags)
- : m_guest(source)
- , m_guest_fs(source.fs())
- , m_host_custody(host_custody)
- , m_flags(flags)
-{
-}
-
-String VirtualFileSystem::Mount::absolute_path() const
-{
- if (!m_host_custody)
- return "/";
- return m_host_custody->absolute_path();
-}
-
-Inode* VirtualFileSystem::Mount::host()
-{
- if (!m_host_custody)
- return nullptr;
- return &m_host_custody->inode();
-}
-
-const Inode* VirtualFileSystem::Mount::host() const
-{
- if (!m_host_custody)
- return nullptr;
- return &m_host_custody->inode();
-}
-
void VirtualFileSystem::for_each_mount(Function<void(const Mount&)> callback) const
{
for (auto& mount : m_mounts) {
diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h
index 555d9705ff..58241db6d2 100644
--- a/Kernel/FileSystem/VirtualFileSystem.h
+++ b/Kernel/FileSystem/VirtualFileSystem.h
@@ -16,6 +16,7 @@
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/FileSystem/InodeMetadata.h>
+#include <Kernel/FileSystem/Mount.h>
#include <Kernel/KResult.h>
#include <Kernel/UnveilNode.h>
@@ -33,31 +34,6 @@ struct UidAndGid {
class VirtualFileSystem {
AK_MAKE_ETERNAL
public:
- class Mount {
- public:
- Mount(FileSystem&, Custody* host_custody, int flags);
- Mount(Inode& source, Custody& host_custody, int flags);
-
- const Inode* host() const;
- Inode* host();
-
- const Inode& guest() const { return *m_guest; }
- Inode& guest() { return *m_guest; }
-
- FileSystem const& guest_fs() const { return *m_guest_fs; }
-
- String absolute_path() const;
-
- int flags() const { return m_flags; }
- void set_flags(int flags) { m_flags = flags; }
-
- private:
- NonnullRefPtr<Inode> m_guest;
- NonnullRefPtr<FileSystem> m_guest_fs;
- RefPtr<Custody> m_host_custody;
- int m_flags;
- };
-
static void initialize();
static VirtualFileSystem& the();