Kernel: Split the SysFS core files into smaller components

This commit is contained in:
Liav A 2022-10-23 21:51:56 +03:00 committed by Andrew Kaster
parent 7eed3dab5d
commit f53149d5f6
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00
19 changed files with 234 additions and 148 deletions

View file

@ -30,7 +30,7 @@
#include <Kernel/Devices/SerialDevice.h>
#include <Kernel/Devices/ZeroDevice.h>
#include <Kernel/FileSystem/Ext2FileSystem.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Firmware/ACPI/Initialize.h>

View file

@ -7,11 +7,11 @@
#pragma once
#include <AK/Bitmap.h>
#include <AK/HashMap.h>
#include <AK/Try.h>
#include <AK/Vector.h>
#include <Kernel/Bus/PCI/Controller/HostController.h>
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/Locking/Spinlock.h>
namespace Kernel::PCI {
@ -59,7 +59,7 @@ private:
mutable RecursiveSpinlock m_access_lock { LockRank::None };
mutable Spinlock m_scan_lock { LockRank::None };
HashMap<u32, NonnullOwnPtr<HostController>> m_host_controllers;
HashMap<u32, NonnullOwnPtr<PCI::HostController>> m_host_controllers;
Vector<DeviceIdentifier> m_device_identifiers;
};
}

View file

@ -7,6 +7,7 @@
#include <AK/ByteReader.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Controller/MemoryBackedHostBridge.h>
#include <Kernel/Memory/MemoryManager.h>
namespace Kernel::PCI {

View file

@ -10,6 +10,7 @@
#include <AK/Vector.h>
#include <Kernel/Bus/PCI/Controller/HostController.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Memory/Region.h>
namespace Kernel::PCI {

View file

@ -125,8 +125,11 @@ set(KERNEL_SOURCES
FileSystem/OpenFileDescription.cpp
FileSystem/Plan9FileSystem.cpp
FileSystem/ProcFS.cpp
FileSystem/SysFS.cpp
FileSystem/SysFS/Component.cpp
FileSystem/SysFS/DirectoryInode.cpp
FileSystem/SysFS/FileSystem.cpp
FileSystem/SysFS/Inode.cpp
FileSystem/SysFS/LinkInode.cpp
FileSystem/SysFS/Registry.cpp
FileSystem/SysFS/RootDirectory.cpp
FileSystem/SysFS/Subsystems/Bus/PCI/BusDirectory.cpp

View file

@ -8,7 +8,7 @@
#include <Kernel/Devices/Device.h>
#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h>
#include <Kernel/Sections.h>

View file

@ -4,8 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/DirectoryInode.h>
#include <Kernel/FileSystem/SysFS/Inode.h>
#include <Kernel/FileSystem/SysFS/LinkInode.h>
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/KLexicalPath.h>

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringView.h>
#include <Kernel/FileSystem/SysFS/DirectoryInode.h>
#include <Kernel/Sections.h>
#include <Kernel/Time/TimeManagement.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<SysFSDirectoryInode>> SysFSDirectoryInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSDirectoryInode(sysfs, component));
}
SysFSDirectoryInode::SysFSDirectoryInode(SysFS const& fs, SysFSComponent const& component)
: SysFSInode(fs, component)
{
}
SysFSDirectoryInode::~SysFSDirectoryInode() = default;
InodeMetadata SysFSDirectoryInode::metadata() const
{
// NOTE: No locking required as m_associated_component or its component index will never change during our lifetime.
InodeMetadata metadata;
metadata.inode = { fsid(), m_associated_component->component_index() };
metadata.mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXOTH;
metadata.uid = 0;
metadata.gid = 0;
metadata.size = 0;
metadata.mtime = TimeManagement::boot_time();
return metadata;
}
ErrorOr<void> SysFSDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(fs().m_lock);
return m_associated_component->traverse_as_directory(fs().fsid(), move(callback));
}
ErrorOr<NonnullLockRefPtr<Inode>> SysFSDirectoryInode::lookup(StringView name)
{
MutexLocker locker(fs().m_lock);
auto component = m_associated_component->lookup(name);
if (!component)
return ENOENT;
return TRY(component->to_inode(fs()));
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/SysFS/Inode.h>
namespace Kernel {
class SysFSDirectoryInode : public SysFSInode {
friend class SysFS;
public:
static ErrorOr<NonnullLockRefPtr<SysFSDirectoryInode>> try_create(SysFS const&, SysFSComponent const&);
virtual ~SysFSDirectoryInode() override;
SysFS& fs() { return static_cast<SysFS&>(Inode::fs()); }
SysFS const& fs() const { return static_cast<SysFS const&>(Inode::fs()); }
protected:
SysFSDirectoryInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView name) override;
};
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringView.h>
#include <Kernel/FileSystem/SysFS/FileSystem.h>
#include <Kernel/FileSystem/SysFS/Inode.h>
#include <Kernel/FileSystem/SysFS/Registry.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<FileSystem>> SysFS::try_create()
{
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFS));
}
SysFS::SysFS() = default;
SysFS::~SysFS() = default;
ErrorOr<void> SysFS::initialize()
{
m_root_inode = TRY(SysFSComponentRegistry::the().root_directory().to_inode(*this));
return {};
}
Inode& SysFS::root_inode()
{
return *m_root_inode;
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, 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/FileSystem/SysFS/Component.h>
#include <Kernel/Forward.h>
#include <Kernel/Locking/MutexProtected.h>
namespace Kernel {
class SysFS final : public FileSystem {
friend class SysFSInode;
friend class SysFSDirectoryInode;
public:
virtual ~SysFS() override;
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "SysFS"sv; }
virtual Inode& root_inode() override;
private:
SysFS();
LockRefPtr<SysFSInode> m_root_inode;
};
}

View file

@ -5,32 +5,11 @@
*/
#include <AK/StringView.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/Sections.h>
#include <Kernel/FileSystem/SysFS/Inode.h>
#include <Kernel/Time/TimeManagement.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<FileSystem>> SysFS::try_create()
{
return TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFS));
}
SysFS::SysFS() = default;
SysFS::~SysFS() = default;
ErrorOr<void> SysFS::initialize()
{
m_root_inode = TRY(SysFSComponentRegistry::the().root_directory().to_inode(*this));
return {};
}
Inode& SysFS::root_inode()
{
return *m_root_inode;
}
ErrorOr<NonnullLockRefPtr<SysFSInode>> SysFSInode::try_create(SysFS const& fs, SysFSComponent const& component)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSInode(fs, component));
@ -131,68 +110,4 @@ ErrorOr<void> SysFSInode::update_timestamps(Optional<time_t>, Optional<time_t>,
return {};
}
ErrorOr<NonnullLockRefPtr<SysFSLinkInode>> SysFSLinkInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSLinkInode(sysfs, component));
}
SysFSLinkInode::SysFSLinkInode(SysFS const& fs, SysFSComponent const& component)
: SysFSInode(fs, component)
{
}
SysFSLinkInode::~SysFSLinkInode() = default;
InodeMetadata SysFSLinkInode::metadata() const
{
// NOTE: No locking required as m_associated_component or its component index will never change during our lifetime.
InodeMetadata metadata;
metadata.inode = { fsid(), m_associated_component->component_index() };
metadata.mode = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH | S_IXOTH;
metadata.uid = 0;
metadata.gid = 0;
metadata.size = 0;
metadata.mtime = TimeManagement::boot_time();
return metadata;
}
ErrorOr<NonnullLockRefPtr<SysFSDirectoryInode>> SysFSDirectoryInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSDirectoryInode(sysfs, component));
}
SysFSDirectoryInode::SysFSDirectoryInode(SysFS const& fs, SysFSComponent const& component)
: SysFSInode(fs, component)
{
}
SysFSDirectoryInode::~SysFSDirectoryInode() = default;
InodeMetadata SysFSDirectoryInode::metadata() const
{
// NOTE: No locking required as m_associated_component or its component index will never change during our lifetime.
InodeMetadata metadata;
metadata.inode = { fsid(), m_associated_component->component_index() };
metadata.mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXOTH;
metadata.uid = 0;
metadata.gid = 0;
metadata.size = 0;
metadata.mtime = TimeManagement::boot_time();
return metadata;
}
ErrorOr<void> SysFSDirectoryInode::traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
{
MutexLocker locker(fs().m_lock);
return m_associated_component->traverse_as_directory(fs().fsid(), move(callback));
}
ErrorOr<NonnullLockRefPtr<Inode>> SysFSDirectoryInode::lookup(StringView name)
{
MutexLocker locker(fs().m_lock);
auto component = m_associated_component->lookup(name);
if (!component)
return ENOENT;
return TRY(component->to_inode(fs()));
}
}

View file

@ -6,32 +6,12 @@
#pragma once
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/Locking/MutexProtected.h>
#include <Kernel/FileSystem/SysFS/FileSystem.h>
namespace Kernel {
class SysFS final : public FileSystem {
friend class SysFSInode;
friend class SysFSDirectoryInode;
public:
virtual ~SysFS() override;
static ErrorOr<NonnullLockRefPtr<FileSystem>> try_create();
virtual ErrorOr<void> initialize() override;
virtual StringView class_name() const override { return "SysFS"sv; }
virtual Inode& root_inode() override;
private:
SysFS();
LockRefPtr<SysFSInode> m_root_inode;
};
class SysFSInode : public Inode {
friend class SysFS;
friend class SysFSDirectoryInode;
@ -62,35 +42,4 @@ protected:
NonnullLockRefPtr<SysFSComponent> m_associated_component;
};
class SysFSLinkInode : public SysFSInode {
friend class SysFS;
public:
static ErrorOr<NonnullLockRefPtr<SysFSLinkInode>> try_create(SysFS const&, SysFSComponent const&);
virtual ~SysFSLinkInode() override;
protected:
SysFSLinkInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
};
class SysFSDirectoryInode : public SysFSInode {
friend class SysFS;
public:
static ErrorOr<NonnullLockRefPtr<SysFSDirectoryInode>> try_create(SysFS const&, SysFSComponent const&);
virtual ~SysFSDirectoryInode() override;
SysFS& fs() { return static_cast<SysFS&>(Inode::fs()); }
SysFS const& fs() const { return static_cast<SysFS const&>(Inode::fs()); }
protected:
SysFSDirectoryInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView name) override;
};
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/LinkInode.h>
#include <Kernel/Time/TimeManagement.h>
namespace Kernel {
ErrorOr<NonnullLockRefPtr<SysFSLinkInode>> SysFSLinkInode::try_create(SysFS const& sysfs, SysFSComponent const& component)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) SysFSLinkInode(sysfs, component));
}
SysFSLinkInode::SysFSLinkInode(SysFS const& fs, SysFSComponent const& component)
: SysFSInode(fs, component)
{
}
SysFSLinkInode::~SysFSLinkInode() = default;
InodeMetadata SysFSLinkInode::metadata() const
{
// NOTE: No locking required as m_associated_component or its component index will never change during our lifetime.
InodeMetadata metadata;
metadata.inode = { fsid(), m_associated_component->component_index() };
metadata.mode = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH | S_IXOTH;
metadata.uid = 0;
metadata.gid = 0;
metadata.size = 0;
metadata.mtime = TimeManagement::boot_time();
return metadata;
}
}

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/SysFS/Inode.h>
namespace Kernel {
class SysFSLinkInode : public SysFSInode {
friend class SysFS;
public:
static ErrorOr<NonnullLockRefPtr<SysFSLinkInode>> try_create(SysFS const&, SysFSComponent const&);
virtual ~SysFSLinkInode() override;
protected:
SysFSLinkInode(SysFS const&, SysFSComponent const&);
// ^Inode
virtual InodeMetadata metadata() const override;
};
}

View file

@ -8,7 +8,6 @@
#include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/PhysicalAddress.h>

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Component.h>
namespace Kernel {

View file

@ -9,7 +9,6 @@
#include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Directory.h>
#include <Kernel/KBuffer.h>
#include <Kernel/Library/LockRefPtr.h>

View file

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