diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp index 6e64359bfa..ed62288c1d 100644 --- a/Kernel/FileSystem/Custody.cpp +++ b/Kernel/FileSystem/Custody.cpp @@ -4,18 +4,18 @@ #include #include -static Lockable>& all_custodies() +static Lockable>& all_custodies() { - static Lockable>* table; - if (!table) - table = new Lockable>; - return *table; + static Lockable>* list; + if (!list) + list = new Lockable>; + return *list; } Custody* Custody::get_if_cached(Custody* parent, const String& name) { LOCKER(all_custodies().lock()); - for (auto& custody : all_custodies().resource()) { + for (auto* custody = all_custodies().resource().head(); custody; custody = custody->next()) { if (custody->is_deleted()) continue; if (custody->is_mounted_on()) @@ -47,7 +47,7 @@ Custody::Custody(Custody* parent, const String& name, Inode& inode) , m_inode(inode) { LOCKER(all_custodies().lock()); - all_custodies().resource().set(this); + all_custodies().resource().append(this); } Custody::~Custody() diff --git a/Kernel/FileSystem/Custody.h b/Kernel/FileSystem/Custody.h index dd6ad7cf32..746b484a05 100644 --- a/Kernel/FileSystem/Custody.h +++ b/Kernel/FileSystem/Custody.h @@ -2,15 +2,17 @@ #include #include -#include +#include #include +#include class Inode; class VFS; // FIXME: Custody needs some locking. -class Custody : public RefCounted { +class Custody : public RefCounted + , public InlineLinkedListNode { public: static Custody* get_if_cached(Custody* parent, const String& name); static NonnullRefPtr get_or_create(Custody* parent, const String& name, Inode&); @@ -35,6 +37,10 @@ public: void did_mount_on(Badge); void did_rename(Badge, const String& name); + // For InlineLinkedListNode. + Custody* m_next { nullptr }; + Custody* m_prev { nullptr }; + private: Custody(Custody* parent, const String& name, Inode&); diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index a028161de4..c2aedebefc 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -5,12 +5,12 @@ #include #include -HashTable& all_inodes() +InlineLinkedList& all_inodes() { - static HashTable* s_inode_set; - if (!s_inode_set) - s_inode_set = new HashTable(); - return *s_inode_set; + static InlineLinkedList* list; + if (!list) + list = new InlineLinkedList; + return *list; } void Inode::sync() @@ -18,7 +18,7 @@ void Inode::sync() NonnullRefPtrVector inodes; { InterruptDisabler disabler; - for (auto* inode : all_inodes()) { + for (auto* inode = all_inodes().head(); inode; inode = inode->next()) { if (inode->is_metadata_dirty()) inodes.append(*inode); } @@ -63,7 +63,7 @@ Inode::Inode(FS& fs, unsigned index) : m_fs(fs) , m_index(index) { - all_inodes().set(this); + all_inodes().append(this); } Inode::~Inode() diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index c17357d454..7153fdd6f7 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -15,7 +16,9 @@ class InodeVMObject; class InodeWatcher; class LocalSocket; -class Inode : public RefCounted, public Weakable { +class Inode : public RefCounted + , public Weakable + , public InlineLinkedListNode { friend class VFS; friend class FS; @@ -77,6 +80,10 @@ public: void register_watcher(Badge, InodeWatcher&); void unregister_watcher(Badge, InodeWatcher&); + // For InlineLinkedListNode. + Inode* m_next { nullptr }; + Inode* m_prev { nullptr }; + protected: Inode(FS& fs, unsigned index); void set_metadata_dirty(bool); diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 8f9713dde7..21b3c6af5a 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -593,11 +593,11 @@ Optional procfs$all(InodeIdentifier) Optional procfs$inodes(InodeIdentifier) { - extern HashTable& all_inodes(); + extern InlineLinkedList& all_inodes(); KBufferBuilder builder; - for (auto it : all_inodes()) { - RefPtr inode = *it; - builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode.ptr(), inode->fsid(), inode->index(), inode->ref_count()); + InterruptDisabler disabler; + for (auto* inode = all_inodes().head(); inode; inode = inode->next()) { + builder.appendf("Inode{K%x} %02u:%08u (%u)\n", inode, inode->fsid(), inode->index(), inode->ref_count()); } return builder.build(); }