1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

Kernel: Change Inode::{read/write}_bytes interface to KResultOr<ssize_t>

The error handling in all these cases was still using the old style
negative values to indicate errors. We have a nicer solution for this
now with KResultOr<T>. This change switches the interface and then all
implementers to use the new style.
This commit is contained in:
Brian Gianforcaro 2021-05-01 14:29:39 -07:00 committed by Andreas Kling
parent de9b454f89
commit 234c6ae32d
18 changed files with 88 additions and 82 deletions

View file

@ -1222,17 +1222,17 @@ InodeMetadata ProcFSInode::metadata() const
return metadata;
}
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer& buffer, FileDescription* description) const
KResultOr<ssize_t> ProcFSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer& buffer, FileDescription* description) const
{
dbgln_if(PROCFS_DEBUG, "ProcFS: read_bytes offset: {} count: {}", offset, count);
VERIFY(offset >= 0);
VERIFY(buffer.user_or_kernel_ptr());
if (!description)
return -EIO;
return EIO;
if (!description->data()) {
dbgln_if(PROCFS_DEBUG, "ProcFS: Do not have cached data!");
return -EIO;
return EIO;
}
// Be sure to keep a reference to data_buffer while we use it!
@ -1243,7 +1243,7 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer&
ssize_t nread = min(static_cast<off_t>(data_buffer->size() - offset), static_cast<off_t>(count));
if (!buffer.write(data_buffer->data() + offset, nread))
return -EFAULT;
return EFAULT;
return nread;
}
@ -1454,7 +1454,7 @@ void ProcFSInode::flush_metadata()
{
}
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const UserOrKernelBuffer& buffer, FileDescription*)
KResultOr<ssize_t> ProcFSInode::write_bytes(off_t offset, ssize_t size, const UserOrKernelBuffer& buffer, FileDescription*)
{
// For process-specific inodes, hold the process's ptrace lock across the write
// and refuse to write at all data if the process is not dumpable.
@ -1493,10 +1493,10 @@ ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const UserOrKernelB
break;
}
} else
return -EPERM;
return EPERM;
} else {
if (!directory_entry->write_callback)
return -EPERM;
return EPERM;
write_callback = directory_entry->write_callback;
}