1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 20:12:11 +00:00

Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr

Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
This commit is contained in:
Sam Atkins 2022-01-20 17:47:39 +00:00 committed by Andreas Kling
parent 140f1d9e55
commit 45cf40653a
79 changed files with 202 additions and 274 deletions

View file

@ -201,10 +201,7 @@ ErrorOr<void> Ext2FSInode::write_indirect_block(BlockBasedFileSystem::BlockIndex
const auto entries_per_block = EXT2_ADDR_PER_BLOCK(&fs().super_block());
VERIFY(blocks_indices.size() <= entries_per_block);
auto block_contents_result = ByteBuffer::create_uninitialized(fs().block_size());
if (!block_contents_result.has_value())
return ENOMEM;
auto block_contents = block_contents_result.release_value();
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
OutputMemoryStream stream { block_contents };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data());
@ -226,10 +223,7 @@ ErrorOr<void> Ext2FSInode::grow_doubly_indirect_block(BlockBasedFileSystem::Bloc
VERIFY(blocks_indices.size() > old_blocks_length);
VERIFY(blocks_indices.size() <= entries_per_doubly_indirect_block);
auto block_contents_result = ByteBuffer::create_uninitialized(fs().block_size());
if (!block_contents_result.has_value())
return ENOMEM;
auto block_contents = block_contents_result.release_value();
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
OutputMemoryStream stream { block_contents };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data());
@ -269,10 +263,7 @@ ErrorOr<void> Ext2FSInode::shrink_doubly_indirect_block(BlockBasedFileSystem::Bl
VERIFY(old_blocks_length >= new_blocks_length);
VERIFY(new_blocks_length <= entries_per_doubly_indirect_block);
auto block_contents_result = ByteBuffer::create_uninitialized(fs().block_size());
if (!block_contents_result.has_value())
return ENOMEM;
auto block_contents = block_contents_result.release_value();
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers));
TRY(fs().read_block(block, &buffer, fs().block_size()));
@ -305,10 +296,7 @@ ErrorOr<void> Ext2FSInode::grow_triply_indirect_block(BlockBasedFileSystem::Bloc
VERIFY(blocks_indices.size() > old_blocks_length);
VERIFY(blocks_indices.size() <= entries_per_triply_indirect_block);
auto block_contents_result = ByteBuffer::create_uninitialized(fs().block_size());
if (!block_contents_result.has_value())
return ENOMEM;
auto block_contents = block_contents_result.release_value();
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
OutputMemoryStream stream { block_contents };
auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data());
@ -351,10 +339,7 @@ ErrorOr<void> Ext2FSInode::shrink_triply_indirect_block(BlockBasedFileSystem::Bl
VERIFY(old_blocks_length >= new_blocks_length);
VERIFY(new_blocks_length <= entries_per_triply_indirect_block);
auto block_contents_result = ByteBuffer::create_uninitialized(fs().block_size());
if (!block_contents_result.has_value())
return ENOMEM;
auto block_contents = block_contents_result.release_value();
auto block_contents = TRY(ByteBuffer::create_uninitialized(fs().block_size()));
auto* block_as_pointers = (unsigned*)block_contents.data();
auto buffer = UserOrKernelBuffer::for_kernel_buffer(reinterpret_cast<u8*>(block_as_pointers));
TRY(fs().read_block(block, &buffer, fs().block_size()));
@ -587,10 +572,7 @@ ErrorOr<Vector<Ext2FS::BlockIndex>> Ext2FSInode::compute_block_list_impl_interna
if (!count)
return {};
size_t read_size = count * sizeof(u32);
auto maybe_array_storage = ByteBuffer::create_uninitialized(read_size);
if (!maybe_array_storage.has_value())
return ENOMEM;
auto array_storage = maybe_array_storage.release_value();
auto array_storage = TRY(ByteBuffer::create_uninitialized(read_size));
auto* array = (u32*)array_storage.data();
auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)array);
TRY(fs().read_block(array_block_index, &buffer, read_size, 0));
@ -1111,10 +1093,7 @@ ErrorOr<void> Ext2FSInode::write_directory(Vector<Ext2FSDirectoryEntry>& entries
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::write_directory(): New directory contents to write (size {}):", identifier(), directory_size);
auto directory_data_result = ByteBuffer::create_uninitialized(directory_size);
if (!directory_data_result.has_value())
return ENOMEM;
auto directory_data = directory_data_result.release_value();
auto directory_data = TRY(ByteBuffer::create_uninitialized(directory_size));
OutputMemoryStream stream { directory_data };
for (auto& entry : entries) {