mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
Ext2FS: Zero out new space when growing an inode
Before this change, truncating an Ext2FS inode to a larger size than it was before would give you uninitialized on-disk data. Fix this by zeroing out all the new space when doing an inode resize. This is pretty naively implemented via Inode::write_bytes() and there's lots of room for cleverness here in the future.
This commit is contained in:
parent
f0093e5d59
commit
77656aed8e
Notes:
sideshowbarker
2024-07-18 23:58:45 +09:00
Author: https://github.com/awesomekling
Commit: 77656aed8e
1 changed files with 18 additions and 0 deletions
|
@ -804,6 +804,24 @@ KResult Ext2FSInode::resize(u64 new_size)
|
|||
set_metadata_dirty(true);
|
||||
|
||||
m_block_list = move(block_list);
|
||||
|
||||
if (new_size > old_size) {
|
||||
// If we're growing the inode, make sure we zero out all the new space.
|
||||
// FIXME: There are definitely more efficient ways to achieve this.
|
||||
size_t bytes_to_clear = new_size - old_size;
|
||||
size_t clear_from = old_size;
|
||||
u8 zero_buffer[PAGE_SIZE];
|
||||
memset(zero_buffer, 0, sizeof(zero_buffer));
|
||||
while (bytes_to_clear) {
|
||||
auto nwritten = write_bytes(clear_from, min(sizeof(zero_buffer), bytes_to_clear), UserOrKernelBuffer::for_kernel_buffer(zero_buffer), nullptr);
|
||||
if (nwritten < 0)
|
||||
return KResult(-nwritten);
|
||||
ASSERT(nwritten != 0);
|
||||
bytes_to_clear -= nwritten;
|
||||
clear_from += nwritten;
|
||||
}
|
||||
}
|
||||
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue