Kernel: Ext2 directory functions now fail on invalid blocks

Invalid blocks should only happen while writing to a file and
I think in that case we should just bail out instead of giving
you incomlete inode list or search result.
This commit is contained in:
Bananymous 2023-03-21 19:24:53 +02:00
parent a083e588ba
commit a8e3ee6f19
1 changed files with 7 additions and 17 deletions

View File

@ -217,6 +217,8 @@ namespace Kernel
BAN::ErrorOr<size_t> Ext2Inode::read(size_t offset, void* buffer, size_t count) BAN::ErrorOr<size_t> Ext2Inode::read(size_t offset, void* buffer, size_t count)
{ {
// FIXME: update atime if needed
if (ifdir()) if (ifdir())
return BAN::Error::from_errno(EISDIR); return BAN::Error::from_errno(EISDIR);
@ -257,14 +259,8 @@ namespace Kernel
for (uint32_t i = 0; i < data_block_count; i++) for (uint32_t i = 0; i < data_block_count; i++)
{ {
auto data_block_index_or_error = data_block_index(i); uint32_t block_index = TRY(data_block_index(i));
if (data_block_index_or_error.is_error()) auto block_data = TRY(m_fs.read_block(block_index));
{
dprintln("{}", data_block_index_or_error.error());
continue;
}
auto block_data = TRY(m_fs.read_block(data_block_index_or_error.value()));
const uint8_t* block_data_end = block_data.data() + block_data.size(); const uint8_t* block_data_end = block_data.data() + block_data.size();
const uint8_t* entry_addr = block_data.data(); const uint8_t* entry_addr = block_data.data();
@ -293,14 +289,8 @@ namespace Kernel
for (uint32_t i = 0; i < data_block_count; i++) for (uint32_t i = 0; i < data_block_count; i++)
{ {
auto data_block_index_or_error = data_block_index(i); uint32_t block_index = TRY(data_block_index(i));
if (data_block_index_or_error.is_error()) auto block_data = TRY(m_fs.read_block(block_index));
{
dprintln("{}", data_block_index_or_error.error());
continue;
}
auto block_data = TRY(m_fs.read_block(data_block_index_or_error.value()));
const uint8_t* block_data_end = block_data.data() + block_data.size(); const uint8_t* block_data_end = block_data.data() + block_data.size();
const uint8_t* entry_addr = block_data.data(); const uint8_t* entry_addr = block_data.data();