From e6a2f55a59058baf751ca8c1823f845d45218a11 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 3 Dec 2024 16:08:59 +0200 Subject: [PATCH] Kernel: Closing file backed mmap wont expand the file size --- kernel/kernel/Memory/FileBackedRegion.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Memory/FileBackedRegion.cpp b/kernel/kernel/Memory/FileBackedRegion.cpp index 6609e72b..3b3eac85 100644 --- a/kernel/kernel/Memory/FileBackedRegion.cpp +++ b/kernel/kernel/Memory/FileBackedRegion.cpp @@ -81,7 +81,8 @@ namespace Kernel memcpy(page_buffer, PageTable::fast_page_as_ptr(), PAGE_SIZE); }); - if (auto ret = inode->write(page_index * PAGE_SIZE, BAN::ConstByteSpan::from(page_buffer)); ret.is_error()) + const size_t write_size = BAN::Math::min(PAGE_SIZE, inode->size() - page_index * PAGE_SIZE); + if (auto ret = inode->write(page_index * PAGE_SIZE, BAN::ConstByteSpan::from(page_buffer).slice(0, write_size)); ret.is_error()) dwarnln("{}", ret.error()); }