mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05: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;
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
|
||||
ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*);
|
||||
ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const;
|
||||
ErrorOr<size_t> read_until_filled_or_end(off_t, size_t, UserOrKernelBuffer buffer, OpenFileDescription*) const;
|
||||
|
||||
virtual ErrorOr<void> attach(OpenFileDescription&) { return {}; }
|
||||
virtual void detach(OpenFileDescription&) { }
|
||||
|
|
Loading…
Add table
Reference in a new issue