mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
Kernel: Implement pread syscall
The OpenFileDescription class already offers the necessary functionlity, so implementing this was only a matter of following the structure for `read` while handling the additional `offset` argument.
This commit is contained in:
parent
8936b111a7
commit
e1093c3403
3 changed files with 23 additions and 0 deletions
|
@ -91,4 +91,25 @@ KResultOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size)
|
|||
return TRY(description->read(user_buffer.value(), size));
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$pread(int fd, Userspace<u8*> buffer, size_t size, off_t offset)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
if (size == 0)
|
||||
return 0;
|
||||
if (size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
if (offset < 0)
|
||||
return EINVAL;
|
||||
dbgln_if(IO_DEBUG, "sys$pread({}, {}, {}, {})", fd, buffer.ptr(), size, offset);
|
||||
auto description = TRY(open_readable_file_description(fds(), fd));
|
||||
if (!description->file().is_seekable())
|
||||
return EINVAL;
|
||||
TRY(check_blocked_read(description));
|
||||
auto user_buffer = UserOrKernelBuffer::for_user_buffer(buffer, size);
|
||||
if (!user_buffer.has_value())
|
||||
return EFAULT;
|
||||
return TRY(description->read(user_buffer.value(), offset, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue