瀏覽代碼

Kernel: Improve some low-memory situations with ext2

Tom 4 年之前
父節點
當前提交
ae956edf6e
共有 2 個文件被更改,包括 9 次插入7 次删除
  1. 8 6
      Kernel/FileSystem/Ext2FileSystem.cpp
  2. 1 1
      Kernel/FileSystem/Ext2FileSystem.h

+ 8 - 6
Kernel/FileSystem/Ext2FileSystem.cpp

@@ -924,7 +924,6 @@ KResult Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntr
 #endif
 #endif
 
 
     auto buffer_or = read_entire();
     auto buffer_or = read_entire();
-    ASSERT(!buffer_or.is_error());
     if (buffer_or.is_error())
     if (buffer_or.is_error())
         return buffer_or.error();
         return buffer_or.error();
 
 
@@ -1537,11 +1536,11 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(InodeIdentifier parent_id,
     return inode.release_nonnull();
     return inode.release_nonnull();
 }
 }
 
 
-void Ext2FSInode::populate_lookup_cache() const
+bool Ext2FSInode::populate_lookup_cache() const
 {
 {
     LOCKER(m_lock);
     LOCKER(m_lock);
     if (!m_lookup_cache.is_empty())
     if (!m_lookup_cache.is_empty())
-        return;
+        return true;
     HashMap<String, unsigned> children;
     HashMap<String, unsigned> children;
 
 
     KResult result = traverse_as_directory([&children](auto& entry) {
     KResult result = traverse_as_directory([&children](auto& entry) {
@@ -1549,17 +1548,20 @@ void Ext2FSInode::populate_lookup_cache() const
         return true;
         return true;
     });
     });
 
 
-    ASSERT(result.is_success());
+    if (!result.is_success())
+        return false;
 
 
     if (!m_lookup_cache.is_empty())
     if (!m_lookup_cache.is_empty())
-        return;
+        return false;
     m_lookup_cache = move(children);
     m_lookup_cache = move(children);
+    return true;
 }
 }
 
 
 RefPtr<Inode> Ext2FSInode::lookup(StringView name)
 RefPtr<Inode> Ext2FSInode::lookup(StringView name)
 {
 {
     ASSERT(is_directory());
     ASSERT(is_directory());
-    populate_lookup_cache();
+    if (!populate_lookup_cache())
+        return {};
     LOCKER(m_lock);
     LOCKER(m_lock);
     auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
     auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
     if (it != m_lookup_cache.end())
     if (it != m_lookup_cache.end())

+ 1 - 1
Kernel/FileSystem/Ext2FileSystem.h

@@ -78,7 +78,7 @@ private:
     virtual KResult truncate(u64) override;
     virtual KResult truncate(u64) override;
 
 
     bool write_directory(const Vector<Ext2FSDirectoryEntry>&);
     bool write_directory(const Vector<Ext2FSDirectoryEntry>&);
-    void populate_lookup_cache() const;
+    bool populate_lookup_cache() const;
     KResult resize(u64);
     KResult resize(u64);
 
 
     static u8 file_type_for_directory_entry(const ext2_dir_entry_2&);
     static u8 file_type_for_directory_entry(const ext2_dir_entry_2&);