summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/InodeFile.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-05 16:03:54 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-05 16:25:40 +0200
commitcad78f5904f9fec1ab6794572bb2def69adad9f6 (patch)
treea4af15708cea675b7b274cd4fb514871fc0d13ff /Kernel/FileSystem/InodeFile.cpp
parent29a9f80ecf7907abb3540817ef12147cbdbe904b (diff)
downloadserenity-cad78f5904f9fec1ab6794572bb2def69adad9f6.zip
Kernel: Use TRY() in InodeFile
Diffstat (limited to 'Kernel/FileSystem/InodeFile.cpp')
-rw-r--r--Kernel/FileSystem/InodeFile.cpp24
1 files changed, 6 insertions, 18 deletions
diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp
index 94b8730e50..85c9e38082 100644
--- a/Kernel/FileSystem/InodeFile.cpp
+++ b/Kernel/FileSystem/InodeFile.cpp
@@ -31,10 +31,7 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, u64 offset, User
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
- auto result = m_inode->read_bytes(offset, count, buffer, &description);
- if (result.is_error())
- return result.error();
- auto nread = result.value();
+ auto nread = TRY(m_inode->read_bytes(offset, count, buffer, &description));
if (nread > 0) {
Thread::current()->did_file_read(nread);
evaluate_block_conditions();
@@ -47,11 +44,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, u64 offset, con
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
- auto result = m_inode->write_bytes(offset, count, data, &description);
- if (result.is_error())
- return result.error();
-
- auto nwritten = result.value();
+ auto nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
if (nwritten > 0) {
auto mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds());
Thread::current()->did_file_write(nwritten);
@@ -77,11 +70,8 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa
if (block_number < 0)
return EINVAL;
- auto block_address = inode().get_block_address(block_number);
- if (block_address.is_error())
- return block_address.error();
-
- if (!copy_to_user(user_block_number, &block_address.value()))
+ auto block_address = TRY(inode().get_block_address(block_number));
+ if (!copy_to_user(user_block_number, &block_address))
return EFAULT;
return KSuccess;
@@ -120,10 +110,8 @@ String InodeFile::absolute_path(const FileDescription& description) const
KResult InodeFile::truncate(u64 size)
{
- if (auto result = m_inode->truncate(size); result.is_error())
- return result;
- if (auto result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error())
- return result;
+ TRY(m_inode->truncate(size));
+ TRY(m_inode->set_mtime(kgettimeofday().to_truncated_seconds()));
return KSuccess;
}