mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
Kernel: Use TRY() in InodeFile
This commit is contained in:
parent
29a9f80ecf
commit
cad78f5904
1 changed files with 6 additions and 18 deletions
|
@ -31,10 +31,7 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, u64 offset, User
|
||||||
if (Checked<off_t>::addition_would_overflow(offset, count))
|
if (Checked<off_t>::addition_would_overflow(offset, count))
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
|
|
||||||
auto result = m_inode->read_bytes(offset, count, buffer, &description);
|
auto nread = TRY(m_inode->read_bytes(offset, count, buffer, &description));
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
auto nread = result.value();
|
|
||||||
if (nread > 0) {
|
if (nread > 0) {
|
||||||
Thread::current()->did_file_read(nread);
|
Thread::current()->did_file_read(nread);
|
||||||
evaluate_block_conditions();
|
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))
|
if (Checked<off_t>::addition_would_overflow(offset, count))
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
|
|
||||||
auto result = m_inode->write_bytes(offset, count, data, &description);
|
auto nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
|
|
||||||
auto nwritten = result.value();
|
|
||||||
if (nwritten > 0) {
|
if (nwritten > 0) {
|
||||||
auto mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds());
|
auto mtime_result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds());
|
||||||
Thread::current()->did_file_write(nwritten);
|
Thread::current()->did_file_write(nwritten);
|
||||||
|
@ -77,11 +70,8 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa
|
||||||
if (block_number < 0)
|
if (block_number < 0)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
auto block_address = inode().get_block_address(block_number);
|
auto block_address = TRY(inode().get_block_address(block_number));
|
||||||
if (block_address.is_error())
|
if (!copy_to_user(user_block_number, &block_address))
|
||||||
return block_address.error();
|
|
||||||
|
|
||||||
if (!copy_to_user(user_block_number, &block_address.value()))
|
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
|
@ -120,10 +110,8 @@ String InodeFile::absolute_path(const FileDescription& description) const
|
||||||
|
|
||||||
KResult InodeFile::truncate(u64 size)
|
KResult InodeFile::truncate(u64 size)
|
||||||
{
|
{
|
||||||
if (auto result = m_inode->truncate(size); result.is_error())
|
TRY(m_inode->truncate(size));
|
||||||
return result;
|
TRY(m_inode->set_mtime(kgettimeofday().to_truncated_seconds()));
|
||||||
if (auto result = m_inode->set_mtime(kgettimeofday().to_truncated_seconds()); result.is_error())
|
|
||||||
return result;
|
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue