From 9b500842a04487dd7f7a0111c4d2cdb346385211 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 21 Mar 2023 19:04:01 +0200 Subject: [PATCH] Kernel: Ext2 can now read from non-block-size aligned offsets --- kernel/kernel/FS/Ext2.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/kernel/FS/Ext2.cpp b/kernel/kernel/FS/Ext2.cpp index 7a415131..c2642056 100644 --- a/kernel/kernel/FS/Ext2.cpp +++ b/kernel/kernel/FS/Ext2.cpp @@ -227,25 +227,25 @@ namespace Kernel const uint32_t block_size = 1024 << m_fs.superblock().log_block_size; - ASSERT(offset % block_size == 0); - const uint32_t first_block = offset / block_size; const uint32_t last_block = BAN::Math::div_round_up(offset + count, block_size); size_t n_read = 0; - + for (uint32_t block = first_block; block < last_block; block++) { - uint32_t data_block = TRY(data_block_index(block)); - auto block_data = TRY(m_fs.read_block(data_block)); + uint32_t block_index = TRY(data_block_index(block)); + auto block_data = TRY(m_fs.read_block(block_index)); + ASSERT(block_data.size() == block_size); - uint32_t to_copy = BAN::Math::min(block_data.size(), count - n_read); + uint32_t copy_offset = (offset + n_read) % block_size; + uint32_t to_copy = BAN::Math::min(block_size - copy_offset, count - n_read); + memcpy((uint8_t*)buffer + n_read, block_data.data() + copy_offset, to_copy); - memcpy((uint8_t*)buffer + n_read, block_data.data(), to_copy); n_read += to_copy; } - return count; + return n_read; } BAN::ErrorOr> Ext2Inode::directory_find_impl(BAN::StringView file_name)