mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
Kernel+LibC: Implement FIONREAD ioctl
FIONREAD gets the number of bytes availible to read from a file descriptor without blocking. I only implemented it for regular files and sockets
This commit is contained in:
parent
db92e66902
commit
39a77559f1
7 changed files with 38 additions and 4 deletions
|
@ -64,8 +64,6 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, u64 offset, con
|
|||
|
||||
KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg)
|
||||
{
|
||||
(void)description;
|
||||
|
||||
switch (request) {
|
||||
case FIBMAP: {
|
||||
if (!Process::current().is_superuser())
|
||||
|
@ -88,6 +86,13 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa
|
|||
|
||||
return KSuccess;
|
||||
}
|
||||
case FIONREAD: {
|
||||
int remaining_bytes = inode().size() - description.offset();
|
||||
if (!copy_to_user(Userspace<int*>(arg), &remaining_bytes))
|
||||
return EFAULT;
|
||||
|
||||
return KSuccess;
|
||||
}
|
||||
default:
|
||||
return EINVAL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue