mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Kernel: Split the DevPtsFS files into smaller components
This commit is contained in:
parent
3fc52a6d1c
commit
fca3b7f1f9
7 changed files with 110 additions and 81 deletions
|
@ -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
|
||||
|
|
67
Kernel/FileSystem/DevPtsFS/FileSystem.cpp
Normal file
67
Kernel/FileSystem/DevPtsFS/FileSystem.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS/Inode.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<FileSystem>> DevPtsFS::try_create()
|
||||
{
|
||||
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFS));
|
||||
}
|
||||
|
||||
DevPtsFS::DevPtsFS() = default;
|
||||
DevPtsFS::~DevPtsFS() = default;
|
||||
|
||||
ErrorOr<void> 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<NonnullLockRefPtr<Inode>> 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<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(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;
|
||||
}
|
||||
|
||||
}
|
37
Kernel/FileSystem/DevPtsFS/FileSystem.h
Normal file
37
Kernel/FileSystem/DevPtsFS/FileSystem.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class SlavePTY;
|
||||
class DevPtsFSInode;
|
||||
|
||||
class DevPtsFS final : public FileSystem {
|
||||
friend class DevPtsFSInode;
|
||||
|
||||
public:
|
||||
virtual ~DevPtsFS() override;
|
||||
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
|
||||
|
||||
virtual ErrorOr<void> initialize() override;
|
||||
virtual StringView class_name() const override { return "DevPtsFS"sv; }
|
||||
|
||||
virtual Inode& root_inode() override;
|
||||
|
||||
private:
|
||||
DevPtsFS();
|
||||
ErrorOr<NonnullLockRefPtr<Inode>> get_inode(InodeIdentifier) const;
|
||||
|
||||
LockRefPtr<DevPtsFSInode> m_root_inode;
|
||||
};
|
||||
|
||||
}
|
|
@ -6,69 +6,15 @@
|
|||
*/
|
||||
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS/Inode.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<FileSystem>> DevPtsFS::try_create()
|
||||
{
|
||||
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DevPtsFS));
|
||||
}
|
||||
|
||||
DevPtsFS::DevPtsFS() = default;
|
||||
DevPtsFS::~DevPtsFS() = default;
|
||||
|
||||
ErrorOr<void> 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<NonnullLockRefPtr<Inode>> 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<DevPtsFS&>(*this), inode_id.index(), static_cast<SlavePTY*>(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)
|
||||
{
|
|
@ -7,33 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class SlavePTY;
|
||||
class DevPtsFSInode;
|
||||
|
||||
class DevPtsFS final : public FileSystem {
|
||||
friend class DevPtsFSInode;
|
||||
|
||||
public:
|
||||
virtual ~DevPtsFS() override;
|
||||
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
|
||||
|
||||
virtual ErrorOr<void> initialize() override;
|
||||
virtual StringView class_name() const override { return "DevPtsFS"sv; }
|
||||
|
||||
virtual Inode& root_inode() override;
|
||||
|
||||
private:
|
||||
DevPtsFS();
|
||||
ErrorOr<NonnullLockRefPtr<Inode>> get_inode(InodeIdentifier) const;
|
||||
|
||||
LockRefPtr<DevPtsFSInode> m_root_inode;
|
||||
};
|
||||
|
||||
class DevPtsFSInode final : public Inode {
|
||||
friend class DevPtsFS;
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Ext2FileSystem.h>
|
||||
#include <Kernel/FileSystem/FATFS/FileSystem.h>
|
||||
#include <Kernel/FileSystem/ISO9660FileSystem.h>
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <AK/Singleton.h>
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/FileSystem/DevPtsFS.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/TTY/MasterPTY.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
|
|
Loading…
Add table
Reference in a new issue