diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-08-01 04:33:06 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-03 18:54:23 +0200 |
commit | a6db2f985a4ee635fa01cf1e649a05a6188888de (patch) | |
tree | 0567605e7a843636b987649b1d532e5880487de8 /Kernel/FileSystem/Ext2FileSystem.cpp | |
parent | 187c086270006318397e6fce7dceb1f0f9e0b591 (diff) | |
download | serenity-a6db2f985a4ee635fa01cf1e649a05a6188888de.zip |
Kernel: Handle OOM in DiskCache when mounting Ext2 filesystems
Create the disk cache up front, so we can verify it succeeds.
Make the KBuffer allocation fail-able, so we can properly handle
failure when the user asks up to mount a Ext2 filesystem under
OOM conditions.
Diffstat (limited to 'Kernel/FileSystem/Ext2FileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 579f5e2f29..2bd8ddb7ce 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -89,6 +89,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const bool Ext2FS::initialize() { MutexLocker locker(m_lock); + VERIFY((sizeof(ext2_super_block) % logical_block_size()) == 0); auto super_block_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&m_super_block); bool success = raw_read_blocks(2, (sizeof(ext2_super_block) / logical_block_size()), super_block_buffer); @@ -115,6 +116,11 @@ bool Ext2FS::initialize() set_block_size(EXT2_BLOCK_SIZE(&super_block)); set_fragment_size(EXT2_FRAG_SIZE(&super_block)); + // Note: This depends on the block size being available. + auto baseclass_result = BlockBasedFileSystem::initialize(); + if (!baseclass_result) + return baseclass_result; + VERIFY(block_size() <= (int)max_block_size); m_block_group_count = ceil_div(super_block.s_blocks_count, super_block.s_blocks_per_group); |