From 750ca2190b9fcd42def7e2c933ad7b727a9d5f6c Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 14 Aug 2021 14:13:28 +0300 Subject: [PATCH] Kernel/DevFS: Add the ability to remove device nodes In order to make this kind of operation simpler, we no longer use a Vector to store pointers to DevFSDeviceInode, but an IntrusiveList is used instead. Also, we only allow to remove device nodes for now, but in theory we can allow to remove all kinds of files from the DevFS. --- Kernel/FileSystem/DevFS.cpp | 12 ++++++++++++ Kernel/FileSystem/DevFS.h | 1 + 2 files changed, 13 insertions(+) diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 882c5e4532..7de9e8b590 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -194,6 +194,18 @@ KResultOr> DevFSRootDirectoryInode::lookup(StringView name) } return ENOENT; } + +KResult DevFSRootDirectoryInode::remove_child(const StringView& name) +{ + MutexLocker locker(fs().m_lock); + for (auto& node : m_nodes) { + if (node.name() == name) { + m_nodes.remove(node); + return KSuccess; + } + } + return KResult(ENOENT); +} KResultOr> DevFSRootDirectoryInode::create_child(StringView name, mode_t mode, dev_t device_mode, UserID, GroupID) { MutexLocker locker(fs().m_lock); diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h index c0860d403d..05dbf9025c 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevFS.h @@ -151,6 +151,7 @@ private: virtual KResult traverse_as_directory(Function) const override; virtual KResultOr> lookup(StringView name) override; virtual InodeMetadata metadata() const override; + virtual KResult remove_child(const StringView& name) override; }; }