1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

Kernel: Stop allowing implicit conversion from KResult to int

This patch removes KResult::operator int() and deals with the fallout.
This forces a lot of code to be more explicit in its handling of errors,
greatly improving readability.
This commit is contained in:
Andreas Kling 2021-08-14 15:15:11 +02:00
parent d30d776ca4
commit 7676edfb9b
14 changed files with 51 additions and 52 deletions

View file

@ -1295,7 +1295,11 @@ bool Ext2FS::write_ext2_inode(InodeIndex inode, const ext2_inode& e2inode)
if (!find_block_containing_inode(inode, block_index, offset))
return false;
auto buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>((const u8*)&e2inode));
return write_block(block_index, buffer, inode_size(), offset) >= 0;
if (auto result = write_block(block_index, buffer, inode_size(), offset); result.is_error()) {
// FIXME: Propagate errors.
return false;
}
return true;
}
auto Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count) -> KResultOr<Vector<BlockIndex>>

View file

@ -237,7 +237,7 @@ KResultOr<size_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_bu
OutputMemoryStream stream { temp_buffer };
auto flush_stream_to_output_buffer = [&error, &stream, &remaining, &output_buffer]() -> bool {
if (error != 0)
if (error.is_error())
return false;
if (stream.size() == 0)
return true;
@ -273,13 +273,12 @@ KResultOr<size_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_bu
// We should only return EFAULT when the userspace buffer is too small,
// so that userspace can reliably use it as a signal to increase its
// buffer size.
VERIFY(result != -EFAULT);
VERIFY(result != EFAULT);
return result;
}
if (error) {
if (error.is_error())
return error;
}
return size - remaining;
}

View file

@ -222,7 +222,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::open(StringView pat
if (custody_or_error.is_error()) {
// NOTE: ENOENT with a non-null parent custody signals us that the immediate parent
// of the file exists, but the file itself does not.
if ((options & O_CREAT) && custody_or_error.error() == -ENOENT && parent_custody)
if ((options & O_CREAT) && custody_or_error.error() == ENOENT && parent_custody)
return create(path, options, mode, *parent_custody, move(owner));
return custody_or_error.error();
}
@ -326,7 +326,7 @@ KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custod
return EEXIST;
if (!parent_custody)
return ENOENT;
if (existing_file_or_error.error() != -ENOENT)
if (existing_file_or_error.error() != ENOENT)
return existing_file_or_error.error();
auto& parent_inode = parent_custody->inode();
auto current_process = Process::current();
@ -401,7 +401,7 @@ KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
else if (!parent_custody)
return result.error();
// NOTE: If resolve_path fails with a non-null parent custody, the error should be ENOENT.
VERIFY(result.error() == -ENOENT);
VERIFY(result.error() == ENOENT);
auto& parent_inode = parent_custody->inode();
auto current_process = Process::current();
@ -491,7 +491,7 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
RefPtr<Custody> new_parent_custody;
auto new_custody_or_error = resolve_path(new_path, base, &new_parent_custody);
if (new_custody_or_error.is_error()) {
if (new_custody_or_error.error() != -ENOENT || !new_parent_custody)
if (new_custody_or_error.error() != ENOENT || !new_parent_custody)
return new_custody_or_error.error();
}
@ -720,7 +720,7 @@ KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custo
return EEXIST;
if (!parent_custody)
return ENOENT;
if (existing_custody_or_error.error() != -ENOENT)
if (existing_custody_or_error.is_error() && existing_custody_or_error.error() != ENOENT)
return existing_custody_or_error.error();
auto& parent_inode = parent_custody->inode();
auto current_process = Process::current();