From 9b9a6b2cfc1d2e199356c7e37b75df7a15ea4bbd Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 11 Sep 2023 01:20:39 +0300 Subject: [PATCH] Kernel: Fix ext2 file write --- kernel/kernel/FS/Ext2/Inode.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index 236fa6d9ef..022477d7d4 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -227,7 +227,7 @@ namespace Kernel const uint8_t* u8buffer = (const uint8_t*)buffer; - size_t written = 0; + size_t to_write = count; // Write partial block if (offset % block_size) @@ -236,7 +236,7 @@ namespace Kernel uint32_t block_offset = offset % block_size; uint32_t data_block_index = TRY(this->data_block_index(block_index)); - uint32_t to_copy = BAN::Math::min(block_size - block_offset, written); + uint32_t to_copy = BAN::Math::min(block_size - block_offset, to_write); m_fs.read_block(data_block_index, block_buffer.span()); memcpy(block_buffer.data() + block_offset, buffer, to_copy); @@ -244,10 +244,10 @@ namespace Kernel u8buffer += to_copy; offset += to_copy; - written -= to_copy; + to_write -= to_copy; } - while (written >= block_size) + while (to_write >= block_size) { uint32_t data_block_index = TRY(this->data_block_index(offset / block_size)); @@ -255,15 +255,15 @@ namespace Kernel u8buffer += block_size; offset += block_size; - written -= block_size; + to_write -= block_size; } - if (written > 0) + if (to_write > 0) { uint32_t data_block_index = TRY(this->data_block_index(offset / block_size)); m_fs.read_block(data_block_index, block_buffer.span()); - memcpy(block_buffer.data(), u8buffer, written); + memcpy(block_buffer.data(), u8buffer, to_write); m_fs.write_block(data_block_index, block_buffer.span()); }