mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
Kernel: Add Inode::read_until_filled_or_end
The existing `read_entire` is quite slow due to allocating and copying multiple times, but it is simultaneously quite hard to get rid of in a single step. As a replacement, add a new function that reads as much as possible directly into a user-provided buffer.
This commit is contained in:
parent
c403f8e92c
commit
acd8c8dba4
2 changed files with 16 additions and 0 deletions
|
@ -118,6 +118,21 @@ ErrorOr<size_t> Inode::read_bytes(off_t offset, size_t length, UserOrKernelBuffe
|
|||
return read_bytes_locked(offset, length, buffer, open_description);
|
||||
}
|
||||
|
||||
ErrorOr<size_t> Inode::read_until_filled_or_end(off_t offset, size_t length, UserOrKernelBuffer buffer, OpenFileDescription* open_description) const
|
||||
{
|
||||
auto remaining_length = length;
|
||||
|
||||
while (remaining_length > 0) {
|
||||
auto filled_bytes = TRY(read_bytes(offset, remaining_length, buffer, open_description));
|
||||
if (filled_bytes == 0)
|
||||
break;
|
||||
offset += filled_bytes;
|
||||
remaining_length -= filled_bytes;
|
||||
}
|
||||
|
||||
return length - remaining_length;
|
||||
}
|
||||
|
||||
ErrorOr<void> Inode::update_timestamps([[maybe_unused]] Optional<Time> atime, [[maybe_unused]] Optional<Time> ctime, [[maybe_unused]] Optional<Time> mtime)
|
||||
{
|
||||
return ENOTIMPL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue