From 3d5ddbab7488ccda86e19f4ddfab56e27c8ad033 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 14 Aug 2021 16:28:09 +0300 Subject: [PATCH] Kernel: Rename DevFS => DevTmpFS The current implementation of DevFS resembles the linux devtmpfs, and not the traditional DevFS, so let's rename it to better represent the direction of the development in regard to this filesystem. The abbreviation for DevTmpFS is still "dev", because it doesn't add value as a commandline option to make it longer. In quick summary - DevFS in unix OSes is simply a static filesystem, so device nodes are generated and removed by the kernel code. DevTmpFS is a "modern reinvention" of the DevFS, so it is much more like a TmpFS in the sense that not only it's stored entirely in RAM, but the userland is responsible to add and remove devices nodes as it sees fit, and no kernel code is directly being involved to keep the filesystem in sync. --- Kernel/CMakeLists.txt | 2 +- Kernel/FileSystem/{DevFS.cpp => DevTmpFS.cpp} | 117 +++++++++--------- Kernel/FileSystem/{DevFS.h => DevTmpFS.h} | 83 +++++++------ Kernel/Forward.h | 10 +- Kernel/Syscalls/mount.cpp | 6 +- 5 files changed, 110 insertions(+), 108 deletions(-) rename Kernel/FileSystem/{DevFS.cpp => DevTmpFS.cpp} (60%) rename Kernel/FileSystem/{DevFS.h => DevTmpFS.h} (64%) diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index b0c9d121eef..22b4a5fb234 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -109,8 +109,8 @@ set(KERNEL_SOURCES FileSystem/AnonymousFile.cpp FileSystem/BlockBasedFileSystem.cpp FileSystem/Custody.cpp - FileSystem/DevFS.cpp FileSystem/DevPtsFS.cpp + FileSystem/DevTmpFS.cpp FileSystem/Ext2FileSystem.cpp FileSystem/FIFO.cpp FileSystem/File.cpp diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevTmpFS.cpp similarity index 60% rename from Kernel/FileSystem/DevFS.cpp rename to Kernel/FileSystem/DevTmpFS.cpp index 7de9e8b590b..f84b2fc132c 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevTmpFS.cpp @@ -5,21 +5,21 @@ */ #include -#include +#include #include namespace Kernel { -KResultOr> DevFS::try_create() +KResultOr> DevTmpFS::try_create() { - return adopt_nonnull_ref_or_enomem(new (nothrow) DevFS); + return adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFS); } -DevFS::DevFS() +DevTmpFS::DevTmpFS() { } -size_t DevFS::allocate_inode_index() +size_t DevTmpFS::allocate_inode_index() { MutexLocker locker(m_lock); m_next_inode_index = m_next_inode_index.value() + 1; @@ -27,96 +27,96 @@ size_t DevFS::allocate_inode_index() return 1 + m_next_inode_index.value(); } -DevFS::~DevFS() +DevTmpFS::~DevTmpFS() { } -KResult DevFS::initialize() +KResult DevTmpFS::initialize() { - m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSRootDirectoryInode(*this))); + m_root_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFSRootDirectoryInode(*this))); return KSuccess; } -Inode& DevFS::root_inode() +Inode& DevTmpFS::root_inode() { return *m_root_inode; } -DevFSInode::DevFSInode(DevFS& fs) +DevTmpFSInode::DevTmpFSInode(DevTmpFS& fs) : Inode(fs, fs.allocate_inode_index()) { } -KResultOr DevFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const +KResultOr DevTmpFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } -KResult DevFSInode::traverse_as_directory(Function) const +KResult DevTmpFSInode::traverse_as_directory(Function) const { VERIFY_NOT_REACHED(); } -KResultOr> DevFSInode::lookup(StringView) +KResultOr> DevTmpFSInode::lookup(StringView) { VERIFY_NOT_REACHED(); } -void DevFSInode::flush_metadata() +void DevTmpFSInode::flush_metadata() { } -KResultOr DevFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) +KResultOr DevTmpFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { VERIFY_NOT_REACHED(); } -KResultOr> DevFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID) +KResultOr> DevTmpFSInode::create_child(StringView, mode_t, dev_t, UserID, GroupID) { return EROFS; } -KResult DevFSInode::add_child(Inode&, const StringView&, mode_t) +KResult DevTmpFSInode::add_child(Inode&, const StringView&, mode_t) { return EROFS; } -KResult DevFSInode::remove_child(const StringView&) +KResult DevTmpFSInode::remove_child(const StringView&) { return EROFS; } -KResult DevFSInode::chmod(mode_t) +KResult DevTmpFSInode::chmod(mode_t) { return EPERM; } -KResult DevFSInode::chown(UserID, GroupID) +KResult DevTmpFSInode::chown(UserID, GroupID) { return EPERM; } -KResult DevFSInode::truncate(u64) +KResult DevTmpFSInode::truncate(u64) { return EPERM; } -StringView DevFSLinkInode::name() const +StringView DevTmpFSLinkInode::name() const { return m_name->view(); } -DevFSLinkInode::~DevFSLinkInode() +DevTmpFSLinkInode::~DevTmpFSLinkInode() { } -DevFSLinkInode::DevFSLinkInode(DevFS& fs, NonnullOwnPtr name) - : DevFSInode(fs) +DevTmpFSLinkInode::DevTmpFSLinkInode(DevTmpFS& fs, NonnullOwnPtr name) + : DevTmpFSInode(fs) , m_name(move(name)) { } -KResultOr DevFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const +KResultOr DevTmpFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const { MutexLocker locker(m_inode_lock); VERIFY(offset == 0); @@ -125,7 +125,7 @@ KResultOr DevFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelB return m_link->length(); } -InodeMetadata DevFSLinkInode::metadata() const +InodeMetadata DevTmpFSLinkInode::metadata() const { InodeMetadata metadata; metadata.inode = { fsid(), index() }; @@ -137,7 +137,7 @@ InodeMetadata DevFSLinkInode::metadata() const return metadata; } -KResultOr DevFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*) +KResultOr DevTmpFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*) { auto new_string = TRY(buffer.try_copy_into_kstring(count)); @@ -148,15 +148,15 @@ KResultOr DevFSLinkInode::write_bytes(off_t offset, size_t count, UserOr return count; } -DevFSDirectoryInode::DevFSDirectoryInode(DevFS& fs) - : DevFSInode(fs) +DevTmpFSDirectoryInode::DevTmpFSDirectoryInode(DevTmpFS& fs) + : DevTmpFSInode(fs) { } -DevFSDirectoryInode::~DevFSDirectoryInode() +DevTmpFSDirectoryInode::~DevTmpFSDirectoryInode() { } -InodeMetadata DevFSDirectoryInode::metadata() const +InodeMetadata DevTmpFSDirectoryInode::metadata() const { InodeMetadata metadata; metadata.inode = { fsid(), 1 }; @@ -168,12 +168,12 @@ InodeMetadata DevFSDirectoryInode::metadata() const return metadata; } -DevFSRootDirectoryInode::DevFSRootDirectoryInode(DevFS& fs) - : DevFSDirectoryInode(fs) +DevTmpFSRootDirectoryInode::DevTmpFSRootDirectoryInode(DevTmpFS& fs) + : DevTmpFSDirectoryInode(fs) { } -KResult DevFSRootDirectoryInode::traverse_as_directory(Function callback) const +KResult DevTmpFSRootDirectoryInode::traverse_as_directory(Function callback) const { MutexLocker locker(fs().m_lock); callback({ ".", identifier(), 0 }); @@ -185,7 +185,7 @@ KResult DevFSRootDirectoryInode::traverse_as_directory(Function> DevFSRootDirectoryInode::lookup(StringView name) +KResultOr> DevTmpFSRootDirectoryInode::lookup(StringView name) { MutexLocker locker(fs().m_lock); for (auto& node : m_nodes) { @@ -195,7 +195,7 @@ KResultOr> DevFSRootDirectoryInode::lookup(StringView name) return ENOENT; } -KResult DevFSRootDirectoryInode::remove_child(const StringView& name) +KResult DevTmpFSRootDirectoryInode::remove_child(const StringView& name) { MutexLocker locker(fs().m_lock); for (auto& node : m_nodes) { @@ -206,7 +206,8 @@ KResult DevFSRootDirectoryInode::remove_child(const StringView& name) } return KResult(ENOENT); } -KResultOr> DevFSRootDirectoryInode::create_child(StringView name, mode_t mode, dev_t device_mode, UserID, GroupID) + +KResultOr> DevTmpFSRootDirectoryInode::create_child(StringView name, mode_t mode, dev_t device_mode, UserID, GroupID) { MutexLocker locker(fs().m_lock); @@ -220,7 +221,7 @@ KResultOr> DevFSRootDirectoryInode::create_child(StringView if (metadata.is_directory()) { if (name != "pts") return EROFS; - auto new_directory_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSPtsDirectoryInode(fs()))); + auto new_directory_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFSPtsDirectoryInode(fs()))); m_nodes.append(*new_directory_inode); return new_directory_inode; } @@ -228,24 +229,24 @@ KResultOr> DevFSRootDirectoryInode::create_child(StringView auto name_kstring = TRY(KString::try_create(name)); unsigned major = major_from_encoded_device(device_mode); unsigned minor = minor_from_encoded_device(device_mode); - auto new_device_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSDeviceInode(fs(), major, minor, is_block_device(mode), move(name_kstring)))); + auto new_device_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFSDeviceInode(fs(), major, minor, is_block_device(mode), move(name_kstring)))); TRY(new_device_inode->chmod(mode)); m_nodes.append(*new_device_inode); return new_device_inode; } if (metadata.is_symlink()) { auto name_kstring = TRY(KString::try_create(name)); - auto new_link_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevFSLinkInode(fs(), move(name_kstring)))); + auto new_link_inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevTmpFSLinkInode(fs(), move(name_kstring)))); m_nodes.append(*new_link_inode); return new_link_inode; } return EROFS; } -DevFSRootDirectoryInode::~DevFSRootDirectoryInode() +DevTmpFSRootDirectoryInode::~DevTmpFSRootDirectoryInode() { } -InodeMetadata DevFSRootDirectoryInode::metadata() const +InodeMetadata DevTmpFSRootDirectoryInode::metadata() const { InodeMetadata metadata; metadata.inode = { fsid(), 1 }; @@ -257,8 +258,8 @@ InodeMetadata DevFSRootDirectoryInode::metadata() const return metadata; } -DevFSDeviceInode::DevFSDeviceInode(DevFS& fs, unsigned major_number, unsigned minor_number, bool block_device, NonnullOwnPtr name) - : DevFSInode(fs) +DevTmpFSDeviceInode::DevTmpFSDeviceInode(DevTmpFS& fs, unsigned major_number, unsigned minor_number, bool block_device, NonnullOwnPtr name) + : DevTmpFSInode(fs) , m_name(move(name)) , m_major_number(major_number) , m_minor_number(minor_number) @@ -266,11 +267,11 @@ DevFSDeviceInode::DevFSDeviceInode(DevFS& fs, unsigned major_number, unsigned mi { } -DevFSDeviceInode::~DevFSDeviceInode() +DevTmpFSDeviceInode::~DevTmpFSDeviceInode() { } -KResult DevFSDeviceInode::chown(UserID uid, GroupID gid) +KResult DevTmpFSDeviceInode::chown(UserID uid, GroupID gid) { MutexLocker locker(m_inode_lock); m_uid = uid; @@ -278,7 +279,7 @@ KResult DevFSDeviceInode::chown(UserID uid, GroupID gid) return KSuccess; } -KResult DevFSDeviceInode::chmod(mode_t mode) +KResult DevTmpFSDeviceInode::chmod(mode_t mode) { MutexLocker locker(m_inode_lock); mode &= 0777; @@ -288,12 +289,12 @@ KResult DevFSDeviceInode::chmod(mode_t mode) return KSuccess; } -StringView DevFSDeviceInode::name() const +StringView DevTmpFSDeviceInode::name() const { return m_name->view(); } -KResultOr DevFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const +KResultOr DevTmpFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const { MutexLocker locker(m_inode_lock); VERIFY(!!description); @@ -308,7 +309,7 @@ KResultOr DevFSDeviceInode::read_bytes(off_t offset, size_t count, UserO return result.value(); } -InodeMetadata DevFSDeviceInode::metadata() const +InodeMetadata DevTmpFSDeviceInode::metadata() const { MutexLocker locker(m_inode_lock); InodeMetadata metadata; @@ -322,7 +323,7 @@ InodeMetadata DevFSDeviceInode::metadata() const metadata.minor_device = m_minor_number; return metadata; } -KResultOr DevFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* description) +KResultOr DevTmpFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* description) { MutexLocker locker(m_inode_lock); VERIFY(!!description); @@ -337,11 +338,11 @@ KResultOr DevFSDeviceInode::write_bytes(off_t offset, size_t count, cons return result.value(); } -DevFSPtsDirectoryInode::DevFSPtsDirectoryInode(DevFS& fs) - : DevFSDirectoryInode(fs) +DevTmpFSPtsDirectoryInode::DevTmpFSPtsDirectoryInode(DevTmpFS& fs) + : DevTmpFSDirectoryInode(fs) { } -KResult DevFSPtsDirectoryInode::traverse_as_directory(Function callback) const +KResult DevTmpFSPtsDirectoryInode::traverse_as_directory(Function callback) const { MutexLocker locker(m_inode_lock); callback({ ".", identifier(), 0 }); @@ -349,15 +350,15 @@ KResult DevFSPtsDirectoryInode::traverse_as_directory(Function> DevFSPtsDirectoryInode::lookup(StringView) +KResultOr> DevTmpFSPtsDirectoryInode::lookup(StringView) { return ENOENT; } -DevFSPtsDirectoryInode::~DevFSPtsDirectoryInode() +DevTmpFSPtsDirectoryInode::~DevTmpFSPtsDirectoryInode() { } -InodeMetadata DevFSPtsDirectoryInode::metadata() const +InodeMetadata DevTmpFSPtsDirectoryInode::metadata() const { InodeMetadata metadata; metadata.inode = { fsid(), index() }; diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevTmpFS.h similarity index 64% rename from Kernel/FileSystem/DevFS.h rename to Kernel/FileSystem/DevTmpFS.h index 05dbf9025c3..45a5f4b0d4b 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevTmpFS.h @@ -14,39 +14,39 @@ namespace Kernel { -class DevFS final : public FileSystem { - friend class DevFSInode; - friend class DevFSRootDirectoryInode; +class DevTmpFS final : public FileSystem { + friend class DevTmpFSInode; + friend class DevTmpFSRootDirectoryInode; public: - virtual ~DevFS() override; - static KResultOr> try_create(); + virtual ~DevTmpFS() override; + static KResultOr> try_create(); virtual KResult initialize() override; - virtual StringView class_name() const override { return "DevFS"sv; } + virtual StringView class_name() const override { return "DevTmpFS"sv; } virtual Inode& root_inode() override; private: - DevFS(); + DevTmpFS(); size_t allocate_inode_index(); - RefPtr m_root_inode; + RefPtr m_root_inode; InodeIndex m_next_inode_index { 0 }; }; -class DevFSInode : public Inode { - friend class DevFS; - friend class DevFSRootDirectoryInode; - friend class DevFSDirectoryInode; +class DevTmpFSInode : public Inode { + friend class DevTmpFS; + friend class DevTmpFSRootDirectoryInode; + friend class DevTmpFSDirectoryInode; public: virtual StringView name() const = 0; - DevFS& fs() { return static_cast(Inode::fs()); } - DevFS const& fs() const { return static_cast(Inode::fs()); } + DevTmpFS& fs() { return static_cast(Inode::fs()); } + DevTmpFS const& fs() const { return static_cast(Inode::fs()); } protected: - DevFSInode(DevFS&); + DevTmpFSInode(DevTmpFS&); virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual KResult traverse_as_directory(Function) const override; virtual KResultOr> lookup(StringView name) override; @@ -60,19 +60,20 @@ protected: virtual KResult truncate(u64) override; private: - IntrusiveListNode> m_list_node; + IntrusiveListNode> m_list_node; }; -class DevFSDeviceInode : public DevFSInode { - friend class DevFS; - friend class DevFSRootDirectoryInode; +class DevTmpFSDeviceInode : public DevTmpFSInode { + friend class DevTmpFS; + friend class DevTmpFSRootDirectoryInode; + friend class DevTmpFSDirectoryInode; public: virtual StringView name() const override; - virtual ~DevFSDeviceInode() override; + virtual ~DevTmpFSDeviceInode() override; private: - DevFSDeviceInode(DevFS&, unsigned, unsigned, bool, NonnullOwnPtr name); + DevTmpFSDeviceInode(DevTmpFS&, unsigned, unsigned, bool, NonnullOwnPtr name); // ^Inode virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; @@ -89,16 +90,16 @@ private: GroupID m_gid { 0 }; }; -class DevFSLinkInode : public DevFSInode { - friend class DevFS; - friend class DevFSRootDirectoryInode; +class DevTmpFSLinkInode : public DevTmpFSInode { + friend class DevTmpFS; + friend class DevTmpFSRootDirectoryInode; public: virtual StringView name() const override; - virtual ~DevFSLinkInode() override; + virtual ~DevTmpFSLinkInode() override; protected: - DevFSLinkInode(DevFS&, NonnullOwnPtr); + DevTmpFSLinkInode(DevTmpFS&, NonnullOwnPtr); // ^Inode virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; @@ -108,45 +109,45 @@ protected: OwnPtr m_link; }; -class DevFSDirectoryInode : public DevFSInode { - friend class DevFS; - friend class DevFSRootDirectoryInode; +class DevTmpFSDirectoryInode : public DevTmpFSInode { + friend class DevTmpFS; + friend class DevTmpFSRootDirectoryInode; public: - virtual ~DevFSDirectoryInode() override; + virtual ~DevTmpFSDirectoryInode() override; protected: - DevFSDirectoryInode(DevFS&); + DevTmpFSDirectoryInode(DevTmpFS&); // ^Inode virtual InodeMetadata metadata() const override; - IntrusiveList, &DevFSInode::m_list_node> m_nodes; + IntrusiveList, &DevTmpFSInode::m_list_node> m_nodes; }; -class DevFSPtsDirectoryInode final : public DevFSDirectoryInode { - friend class DevFS; - friend class DevFSRootDirectoryInode; +class DevTmpFSPtsDirectoryInode final : public DevTmpFSDirectoryInode { + friend class DevTmpFS; + friend class DevTmpFSRootDirectoryInode; public: - virtual ~DevFSPtsDirectoryInode() override; + virtual ~DevTmpFSPtsDirectoryInode() override; virtual StringView name() const override { return "pts"; }; private: - explicit DevFSPtsDirectoryInode(DevFS&); + explicit DevTmpFSPtsDirectoryInode(DevTmpFS&); virtual KResult traverse_as_directory(Function) const override; virtual KResultOr> lookup(StringView name) override; virtual InodeMetadata metadata() const override; }; -class DevFSRootDirectoryInode final : public DevFSDirectoryInode { - friend class DevFS; +class DevTmpFSRootDirectoryInode final : public DevTmpFSDirectoryInode { + friend class DevTmpFS; public: - virtual ~DevFSRootDirectoryInode() override; + virtual ~DevTmpFSRootDirectoryInode() override; virtual StringView name() const override { return "."; } private: - explicit DevFSRootDirectoryInode(DevFS&); + explicit DevTmpFSRootDirectoryInode(DevTmpFS&); virtual KResultOr> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult traverse_as_directory(Function) const override; virtual KResultOr> lookup(StringView name) override; diff --git a/Kernel/Forward.h b/Kernel/Forward.h index 6a77aa4cdc2..302b5f635ba 100644 --- a/Kernel/Forward.h +++ b/Kernel/Forward.h @@ -15,11 +15,11 @@ class BlockDevice; class CharacterDevice; class Coredump; class Custody; -class DevFSDeviceInode; -class DevFSDirectoryInode; -class DevFSInode; -class DevFSPtsDirectoryInode; -class DevFSRootDirectoryInode; +class DevTmpFSDeviceInode; +class DevTmpFSDirectoryInode; +class DevTmpFSInode; +class DevTmpFSPtsDirectoryInode; +class DevTmpFSRootDirectoryInode; class Device; class DiskCache; class DoubleBuffer; diff --git a/Kernel/Syscalls/mount.cpp b/Kernel/Syscalls/mount.cpp index 2844839ddf7..b0a3709bf38 100644 --- a/Kernel/Syscalls/mount.cpp +++ b/Kernel/Syscalls/mount.cpp @@ -5,8 +5,8 @@ */ #include -#include #include +#include #include #include #include @@ -82,8 +82,8 @@ KResultOr Process::sys$mount(Userspace fs = TRY(ProcFS::try_create()); } else if (fs_type == "devpts"sv || fs_type == "DevPtsFS"sv) { fs = TRY(DevPtsFS::try_create()); - } else if (fs_type == "dev"sv || fs_type == "DevFS"sv) { - fs = TRY(DevFS::try_create()); + } else if (fs_type == "dev"sv || fs_type == "DevTmpFS"sv) { + fs = TRY(DevTmpFS::try_create()); } else if (fs_type == "sys"sv || fs_type == "SysFS"sv) { fs = TRY(SysFS::try_create()); } else if (fs_type == "tmp"sv || fs_type == "TmpFS"sv) {