BAN: Error can now be constructed from c_string or format string

If the resulting string would overflow, we just truncate it to fit
the error message buffer (128) bytes
This commit is contained in:
Bananymous
2023-03-08 17:05:37 +02:00
parent d90aba0963
commit 7458f68c38
8 changed files with 77 additions and 84 deletions

View File

@@ -222,7 +222,7 @@ namespace Kernel
}
}
return BAN::Error::from_string("Inode did not contain enough blocks");
return BAN::Error::from_c_string("Inode did not contain enough blocks");
}
BAN::ErrorOr<BAN::Vector<uint8_t>> Ext2Inode::read_all()
@@ -355,7 +355,7 @@ namespace Kernel
}
if (m_superblock.magic != 0xEF53)
return BAN::Error::from_string("Not a ext2 filesystem");
return BAN::Error::from_c_string("Not a ext2 filesystem");
if (m_superblock.rev_level < 1)
{
@@ -392,7 +392,7 @@ namespace Kernel
uint32_t number_of_block_groups = BAN::Math::div_round_up(m_superblock.inodes_count, m_superblock.inodes_per_group);
uint32_t number_of_block_groups_check = BAN::Math::div_round_up(m_superblock.blocks_count, m_superblock.blocks_per_group);
if (number_of_block_groups != number_of_block_groups_check)
return BAN::Error::from_string("Ambiguous number of blocks");
return BAN::Error::from_c_string("Ambiguous number of blocks");
uint32_t block_group_descriptor_table_block = m_superblock.first_data_block + 1;
uint32_t block_group_descriptor_table_sector_count = BAN::Math::div_round_up(32u * number_of_block_groups, sector_size);

View File

@@ -109,13 +109,13 @@ namespace Kernel
if (m_root_inode)
return {};
return BAN::Error::from_string("Could not locate root partition");
return BAN::Error::from_c_string("Could not locate root partition");
}
BAN::ErrorOr<BAN::RefPtr<Inode>> VirtualFileSystem::from_absolute_path(BAN::StringView path)
{
if (path.front() != '/')
return BAN::Error::from_string("Path must be an absolute path");
return BAN::Error::from_c_string("Path must be an absolute path");
auto inode = root_inode();
auto path_parts = TRY(path.split('/'));