diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index c6b5413152..7f89394cf1 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -109,7 +109,8 @@ set(KERNEL_SOURCES FileSystem/AnonymousFile.cpp FileSystem/BlockBasedFileSystem.cpp FileSystem/Custody.cpp - FileSystem/DevPtsFS.cpp + FileSystem/DevPtsFS/FileSystem.cpp + FileSystem/DevPtsFS/Inode.cpp FileSystem/Ext2FileSystem.cpp FileSystem/FATFS/FileSystem.cpp FileSystem/FATFS/Inode.cpp diff --git a/Kernel/FileSystem/DevPtsFS/FileSystem.cpp b/Kernel/FileSystem/DevPtsFS/FileSystem.cpp new file mode 100644 index 0000000000..1cc4da8018 --- /dev/null +++ b/Kernel/FileSystem/DevPtsFS/FileSystem.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2019-2020, Sergey Bugaev + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Kernel { + +ErrorOr> DevPtsFS::try_create() +{ + return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFS)); +} + +DevPtsFS::DevPtsFS() = default; +DevPtsFS::~DevPtsFS() = default; + +ErrorOr DevPtsFS::initialize() +{ + m_root_inode = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFSInode(*this, 1, nullptr))); + m_root_inode->m_metadata.inode = { fsid(), 1 }; + m_root_inode->m_metadata.mode = 0040555; + m_root_inode->m_metadata.uid = 0; + m_root_inode->m_metadata.gid = 0; + m_root_inode->m_metadata.size = 0; + m_root_inode->m_metadata.mtime = TimeManagement::boot_time(); + return {}; +} + +static unsigned inode_index_to_pty_index(InodeIndex inode_index) +{ + VERIFY(inode_index > 1); + return inode_index.value() - 2; +} + +Inode& DevPtsFS::root_inode() +{ + return *m_root_inode; +} + +ErrorOr> DevPtsFS::get_inode(InodeIdentifier inode_id) const +{ + if (inode_id.index() == 1) + return *m_root_inode; + + unsigned pty_index = inode_index_to_pty_index(inode_id.index()); + auto* device = DeviceManagement::the().get_device(201, pty_index); + VERIFY(device); + + auto inode = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFSInode(const_cast(*this), inode_id.index(), static_cast(device)))); + inode->m_metadata.inode = inode_id; + inode->m_metadata.size = 0; + inode->m_metadata.uid = device->uid(); + inode->m_metadata.gid = device->gid(); + inode->m_metadata.mode = 0020600; + inode->m_metadata.major_device = device->major(); + inode->m_metadata.minor_device = device->minor(); + inode->m_metadata.mtime = TimeManagement::boot_time(); + return inode; +} + +} diff --git a/Kernel/FileSystem/DevPtsFS/FileSystem.h b/Kernel/FileSystem/DevPtsFS/FileSystem.h new file mode 100644 index 0000000000..801347387d --- /dev/null +++ b/Kernel/FileSystem/DevPtsFS/FileSystem.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2020, Sergey Bugaev + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Kernel { + +class SlavePTY; +class DevPtsFSInode; + +class DevPtsFS final : public FileSystem { + friend class DevPtsFSInode; + +public: + virtual ~DevPtsFS() override; + static ErrorOr> try_create(); + + virtual ErrorOr initialize() override; + virtual StringView class_name() const override { return "DevPtsFS"sv; } + + virtual Inode& root_inode() override; + +private: + DevPtsFS(); + ErrorOr> get_inode(InodeIdentifier) const; + + LockRefPtr m_root_inode; +}; + +} diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS/Inode.cpp similarity index 61% rename from Kernel/FileSystem/DevPtsFS.cpp rename to Kernel/FileSystem/DevPtsFS/Inode.cpp index 1643cddadc..116a9f3db6 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS/Inode.cpp @@ -6,69 +6,15 @@ */ #include -#include -#include -#include +#include namespace Kernel { -ErrorOr> DevPtsFS::try_create() -{ - return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFS)); -} - -DevPtsFS::DevPtsFS() = default; -DevPtsFS::~DevPtsFS() = default; - -ErrorOr DevPtsFS::initialize() -{ - m_root_inode = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFSInode(*this, 1, nullptr))); - m_root_inode->m_metadata.inode = { fsid(), 1 }; - m_root_inode->m_metadata.mode = 0040555; - m_root_inode->m_metadata.uid = 0; - m_root_inode->m_metadata.gid = 0; - m_root_inode->m_metadata.size = 0; - m_root_inode->m_metadata.mtime = TimeManagement::boot_time(); - return {}; -} - -static unsigned inode_index_to_pty_index(InodeIndex inode_index) -{ - VERIFY(inode_index > 1); - return inode_index.value() - 2; -} - static InodeIndex pty_index_to_inode_index(unsigned pty_index) { return pty_index + 2; } -Inode& DevPtsFS::root_inode() -{ - return *m_root_inode; -} - -ErrorOr> DevPtsFS::get_inode(InodeIdentifier inode_id) const -{ - if (inode_id.index() == 1) - return *m_root_inode; - - unsigned pty_index = inode_index_to_pty_index(inode_id.index()); - auto* device = DeviceManagement::the().get_device(201, pty_index); - VERIFY(device); - - auto inode = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFSInode(const_cast(*this), inode_id.index(), static_cast(device)))); - inode->m_metadata.inode = inode_id; - inode->m_metadata.size = 0; - inode->m_metadata.uid = device->uid(); - inode->m_metadata.gid = device->gid(); - inode->m_metadata.mode = 0020600; - inode->m_metadata.major_device = device->major(); - inode->m_metadata.minor_device = device->minor(); - inode->m_metadata.mtime = TimeManagement::boot_time(); - return inode; -} - DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, InodeIndex index, SlavePTY* pty) : Inode(fs, index) { diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS/Inode.h similarity index 73% rename from Kernel/FileSystem/DevPtsFS.h rename to Kernel/FileSystem/DevPtsFS/Inode.h index 9b3951820b..4d67ec6ba2 100644 --- a/Kernel/FileSystem/DevPtsFS.h +++ b/Kernel/FileSystem/DevPtsFS/Inode.h @@ -7,33 +7,12 @@ #pragma once #include -#include +#include #include +#include namespace Kernel { -class SlavePTY; -class DevPtsFSInode; - -class DevPtsFS final : public FileSystem { - friend class DevPtsFSInode; - -public: - virtual ~DevPtsFS() override; - static ErrorOr> try_create(); - - virtual ErrorOr initialize() override; - virtual StringView class_name() const override { return "DevPtsFS"sv; } - - virtual Inode& root_inode() override; - -private: - DevPtsFS(); - ErrorOr> get_inode(InodeIdentifier) const; - - LockRefPtr m_root_inode; -}; - class DevPtsFSInode final : public Inode { friend class DevPtsFS; diff --git a/Kernel/Syscalls/mount.cpp b/Kernel/Syscalls/mount.cpp index 5f79020eec..24b1ecb509 100644 --- a/Kernel/Syscalls/mount.cpp +++ b/Kernel/Syscalls/mount.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index bf442fae2d..c3865dbb05 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include