mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
Kernel: Make VirtualFileSystem::Mount a top-level class
And move it to its own compilation unit.
This commit is contained in:
parent
79552c91d5
commit
6a27de2d94
6 changed files with 109 additions and 62 deletions
|
@ -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
|
||||
|
|
17
Kernel/FileSystem/Forward.h
Normal file
17
Kernel/FileSystem/Forward.h
Normal file
|
@ -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;
|
||||
|
||||
}
|
51
Kernel/FileSystem/Mount.cpp
Normal file
51
Kernel/FileSystem/Mount.cpp
Normal file
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
39
Kernel/FileSystem/Mount.h
Normal file
39
Kernel/FileSystem/Mount.h
Normal file
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue