summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-18 13:18:47 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-18 19:22:26 +0100
commit47da86d13646e202a71b985c536dc101c9706f59 (patch)
tree7a5eaaef6b60134a9b2cd7d52a3938c53f8ca35d /Kernel
parent8cde8ba511eaa0678b23cb7fdad25091bd219030 (diff)
downloadserenity-47da86d13646e202a71b985c536dc101c9706f59.zip
Ext2FS: Fail the mount if BGD table cache allocation fails
Instead of asserting if we can't allocate enough memory for a BGD table cache, just fail the mount instead.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp8
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h6
2 files changed, 9 insertions, 5 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 26767b31ad..41d0dcd39f 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -141,8 +141,12 @@ bool Ext2FS::initialize()
unsigned blocks_to_read = ceil_div(m_block_group_count * sizeof(ext2_group_desc), block_size());
BlockIndex first_block_of_bgdt = block_size() == 1024 ? 2 : 1;
- m_cached_group_descriptor_table = KBuffer::create_with_size(block_size() * blocks_to_read, Region::Access::Read | Region::Access::Write, "Ext2FS: Block group descriptors");
- auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table.value().data());
+ m_cached_group_descriptor_table = KBuffer::try_create_with_size(block_size() * blocks_to_read, Region::Access::Read | Region::Access::Write, "Ext2FS: Block group descriptors");
+ if (!m_cached_group_descriptor_table) {
+ dbgln("Ext2FS: Failed to allocate memory for group descriptor table");
+ return false;
+ }
+ auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table->data());
read_blocks(first_block_of_bgdt, blocks_to_read, buffer);
#ifdef EXT2_DEBUG
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index d274fb082e..d811ca0f8a 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -120,8 +120,8 @@ private:
const ext2_super_block& super_block() const { return m_super_block; }
const ext2_group_desc& group_descriptor(GroupIndex) const;
- ext2_group_desc* block_group_descriptors() { return (ext2_group_desc*)m_cached_group_descriptor_table.value().data(); }
- const ext2_group_desc* block_group_descriptors() const { return (const ext2_group_desc*)m_cached_group_descriptor_table.value().data(); }
+ ext2_group_desc* block_group_descriptors() { return (ext2_group_desc*)m_cached_group_descriptor_table->data(); }
+ const ext2_group_desc* block_group_descriptors() const { return (const ext2_group_desc*)m_cached_group_descriptor_table->data(); }
void flush_block_group_descriptor_table();
unsigned inodes_per_block() const;
unsigned inodes_per_group() const;
@@ -170,7 +170,7 @@ private:
unsigned m_block_group_count { 0 };
mutable ext2_super_block m_super_block;
- mutable Optional<KBuffer> m_cached_group_descriptor_table;
+ mutable OwnPtr<KBuffer> m_cached_group_descriptor_table;
mutable HashMap<InodeIndex, RefPtr<Ext2FSInode>> m_inode_cache;