From 00409ffa609abd873bd30f673e37b73f65453156 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 13 Jul 2023 10:20:56 +0300 Subject: [PATCH] Kernel: Ext2Inode::create_file actually sets the inode data We used to just create inode without touching its memory. --- kernel/kernel/FS/Ext2.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/kernel/FS/Ext2.cpp b/kernel/kernel/FS/Ext2.cpp index 39b0428b38..d9050c3b45 100644 --- a/kernel/kernel/FS/Ext2.cpp +++ b/kernel/kernel/FS/Ext2.cpp @@ -592,6 +592,21 @@ namespace Kernel bgd.free_inodes_count--; write_block(bgd_location.block, bgd_buffer.span()); + uint32_t inode_table_byte_offset = inode_offset * superblock().inode_size; + BlockLocation inode_location + { + .block = bgd.inode_table + inode_table_byte_offset / block_size, + .offset = inode_table_byte_offset % block_size + }; + + ASSERT(block_size - inode_location.offset >= sizeof(ext2_inode)); + + // NOTE: we don't need bgd_buffer anymore, so we can reuse it to avoid allocations + auto& inode_buffer = bgd_buffer; + read_block(inode_location.block, inode_buffer.span()); + memcpy(inode_buffer.data() + inode_location.offset, &ext2_inode, sizeof(ext2_inode)); + write_block(inode_location.block, inode_buffer.span()); + return group * superblock().inodes_per_group + inode_offset + 1; } }