Kernel: Split the TmpFS core files into smaller components

This commit is contained in:
Liav A 2022-10-23 22:01:40 +03:00 committed by Andrew Kaster
parent f53149d5f6
commit 5e6101dd3e
Notes: sideshowbarker 2024-07-17 04:41:10 +09:00
7 changed files with 85 additions and 59 deletions

View file

@ -183,7 +183,8 @@ set(KERNEL_SOURCES
FileSystem/SysFS/Subsystems/Kernel/Variables/Directory.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/UBSANDeadly.cpp
FileSystem/TmpFS.cpp
FileSystem/TmpFS/FileSystem.cpp
FileSystem/TmpFS/Inode.cpp
FileSystem/VirtualFileSystem.cpp
Firmware/BIOS.cpp
Firmware/ACPI/Initialize.cpp

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/TmpFS/FileSystem.h>
#include <Kernel/FileSystem/TmpFS/Inode.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<FileSystem>> TmpFS::try_create()
{
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) TmpFS));
}
TmpFS::TmpFS() = default;
TmpFS::~TmpFS() = default;
ErrorOr<void> TmpFS::initialize()
{
m_root_inode = TRY(TmpFSInode::try_create_root(*this));
return {};
}
Inode& TmpFS::root_inode()
{
VERIFY(!m_root_inode.is_null());
return *m_root_inode;
}
unsigned TmpFS::next_inode_index()
{
MutexLocker locker(m_lock);
return m_next_inode_index++;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Forward.h>
namespace Kernel {
class TmpFS final : public FileSystem {
friend class TmpFSInode;
public:
virtual ~TmpFS() override;
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "TmpFS"sv; }
virtual bool supports_watchers() const override { return true; }
virtual Inode& root_inode() override;
private:
TmpFS();
LockRefPtr<TmpFSInode> m_root_inode;
unsigned m_next_inode_index { 1 };
unsigned next_inode_index();
};
}

View file

@ -5,39 +5,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/TmpFS.h>
#include <Kernel/FileSystem/TmpFS/Inode.h>
#include <Kernel/Process.h>
#include <LibC/limits.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<FileSystem>> TmpFS::try_create()
{
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) TmpFS));
}
TmpFS::TmpFS() = default;
TmpFS::~TmpFS() = default;
ErrorOr<void> TmpFS::initialize()
{
m_root_inode = TRY(TmpFSInode::try_create_root(*this));
return {};
}
Inode& TmpFS::root_inode()
{
VERIFY(!m_root_inode.is_null());
return *m_root_inode;
}
unsigned TmpFS::next_inode_index()
{
MutexLocker locker(m_lock);
return m_next_inode_index++;
}
TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent)
: Inode(fs, fs.next_inode_index())
, m_metadata(metadata)

View file

@ -7,39 +7,12 @@
#pragma once
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/KBuffer.h>
#include <Kernel/Locking/MutexProtected.h>
#include <Kernel/FileSystem/TmpFS/FileSystem.h>
#include <Kernel/Memory/AnonymousVMObject.h>
namespace Kernel {
class TmpFSInode;
class TmpFS final : public FileSystem {
friend class TmpFSInode;
public:
virtual ~TmpFS() override;
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "TmpFS"sv; }
virtual bool supports_watchers() const override { return true; }
virtual Inode& root_inode() override;
private:
TmpFS();
LockRefPtr<TmpFSInode> m_root_inode;
unsigned m_next_inode_index { 1 };
unsigned next_inode_index();
};
class TmpFSInode final : public Inode {
friend class TmpFS;

View file

@ -61,6 +61,7 @@ class TCPSocket;
class TTY;
class Thread;
class ThreadTracer;
class TmpFSInode;
class UDPSocket;
class UserOrKernelBuffer;
class VirtualFileSystem;

View file

@ -12,7 +12,7 @@
#include <Kernel/FileSystem/Plan9FileSystem.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/FileSystem/SysFS/FileSystem.h>
#include <Kernel/FileSystem/TmpFS.h>
#include <Kernel/FileSystem/TmpFS/FileSystem.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Process.h>