summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-16 22:13:58 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-17 01:21:47 +0200
commit0de8c95d49e9c5042c4e4581a2483266586064e9 (patch)
tree18d8faf133d3bce6c9ba81ca7d1c21372671fb36 /Kernel/FileSystem
parent62719b85e0373151b8a62f53da172776d493ebed (diff)
downloadserenity-0de8c95d49e9c5042c4e4581a2483266586064e9.zip
Kernel: Convert SlavePTY all-instances HashTable to an IntrusiveList
This simplifies the DevPtsFS implementation somewhat, as it no longer requires SlavePTY to register itself with it, since it can now simply use the list of SlavePTY instances.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/DevPtsFS.cpp49
-rw-r--r--Kernel/FileSystem/DevPtsFS.h3
2 files changed, 22 insertions, 30 deletions
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp
index 7c84db9f0b..136a39afa2 100644
--- a/Kernel/FileSystem/DevPtsFS.cpp
+++ b/Kernel/FileSystem/DevPtsFS.cpp
@@ -1,11 +1,10 @@
/*
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Singleton.h>
-#include <AK/StringView.h>
#include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/TTY/SlavePTY.h>
@@ -25,8 +24,6 @@ DevPtsFS::~DevPtsFS()
{
}
-static Singleton<HashTable<unsigned>> s_ptys;
-
KResult DevPtsFS::initialize()
{
m_root_inode = adopt_ref_if_nonnull(new (nothrow) DevPtsFSInode(*this, 1, nullptr));
@@ -80,16 +77,6 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
return inode;
}
-void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
-{
- s_ptys->set(slave_pty.index());
-}
-
-void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
-{
- s_ptys->remove(slave_pty.index());
-}
-
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, InodeIndex index, SlavePTY* pty)
: Inode(fs, index)
{
@@ -129,11 +116,13 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::Directory
callback({ ".", identifier(), 0 });
callback({ "..", identifier(), 0 });
- for (unsigned pty_index : *s_ptys) {
- String name = String::number(pty_index);
- InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(pty_index) };
- callback({ name, identifier, 0 });
- }
+ SlavePTY::all_instances().with([&](auto& list) {
+ for (SlavePTY& slave_pty : list) {
+ String name = String::number(slave_pty.index());
+ InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(slave_pty.index()) };
+ callback({ name, identifier, 0 });
+ }
+ });
return KSuccess;
}
@@ -146,14 +135,20 @@ KResultOr<NonnullRefPtr<Inode>> DevPtsFSInode::lookup(StringView name)
return *this;
auto pty_index = name.to_uint();
- if (pty_index.has_value() && s_ptys->contains(pty_index.value())) {
- auto inode = fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
- if (!inode)
- return ENOENT;
- return inode.release_nonnull();
- }
-
- return ENOENT;
+ if (!pty_index.has_value())
+ return ENOENT;
+
+ return SlavePTY::all_instances().with([&](auto& list) -> KResultOr<NonnullRefPtr<Inode>> {
+ for (SlavePTY& slave_pty : list) {
+ if (slave_pty.index() != pty_index.value())
+ continue;
+ auto inode = fs().get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
+ if (!inode)
+ return ENOENT;
+ return inode.release_nonnull();
+ }
+ return ENOENT;
+ });
}
void DevPtsFSInode::flush_metadata()
diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS.h
index 568b2c2ca4..d89ab1dfe4 100644
--- a/Kernel/FileSystem/DevPtsFS.h
+++ b/Kernel/FileSystem/DevPtsFS.h
@@ -27,9 +27,6 @@ public:
virtual Inode& root_inode() override;
- static void register_slave_pty(SlavePTY&);
- static void unregister_slave_pty(SlavePTY&);
-
private:
DevPtsFS();
RefPtr<Inode> get_inode(InodeIdentifier) const;