Kernel/Ext2: Don't rely on block size 512 for superblock offset

This commit is contained in:
kleines Filmröllchen 2023-07-24 22:08:18 +02:00 committed by Jelle Raaijmakers
parent 10ba54a009
commit bf1610d378
Notes: sideshowbarker 2024-07-16 23:34:49 +09:00

View File

@ -29,12 +29,13 @@ Ext2FS::~Ext2FS() = default;
ErrorOr<void> Ext2FS::flush_super_block()
{
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);
auto const superblock_physical_block_count = (sizeof(ext2_super_block) / logical_block_size());
// FIXME: We currently have no ability of writing within a device block, but the ability to do so would allow us to use device block sizes larger than 1024.
VERIFY((sizeof(ext2_super_block) % logical_block_size()) == 0);
// First superblock is always at offset 1024 (physical block index 2).
TRY(raw_write_blocks(2, superblock_physical_block_count, super_block_buffer));
TRY(raw_write_blocks(1024 / logical_block_size(), superblock_physical_block_count, super_block_buffer));
auto is_sparse = has_flag(get_features_readonly(), FeaturesReadOnly::SparseSuperblock);
@ -71,7 +72,7 @@ ErrorOr<void> Ext2FS::initialize_while_locked()
VERIFY((sizeof(ext2_super_block) % logical_block_size()) == 0);
auto super_block_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&m_super_block);
TRY(raw_read_blocks(2, (sizeof(ext2_super_block) / logical_block_size()), super_block_buffer));
TRY(raw_read_blocks(1024 / logical_block_size(), (sizeof(ext2_super_block) / logical_block_size()), super_block_buffer));
auto const& super_block = this->super_block();
if constexpr (EXT2_DEBUG) {