mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
Kernel: Add FileDescription read/write API that bypasses current offset
Forcing users of a FileDescription to seek before they can read/write makes it inherently racy. This patch adds variants of read/write that simply ignore the "current offset" of the description in favor of a caller-supplied offset.
This commit is contained in:
parent
ace8b9a0ee
commit
d1395f2eb9
Notes:
sideshowbarker
2024-07-18 08:57:14 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d1395f2eb94
|
@ -157,6 +157,20 @@ KResultOr<off_t> FileDescription::seek(off_t offset, int whence)
|
|||
return m_current_offset;
|
||||
}
|
||||
|
||||
KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, u64 offset, size_t count)
|
||||
{
|
||||
if (Checked<u64>::addition_would_overflow(offset, count))
|
||||
return EOVERFLOW;
|
||||
return m_file->read(*this, offset, buffer, count);
|
||||
}
|
||||
|
||||
KResultOr<size_t> FileDescription::write(u64 offset, UserOrKernelBuffer const& data, size_t data_size)
|
||||
{
|
||||
if (Checked<u64>::addition_would_overflow(offset, data_size))
|
||||
return EOVERFLOW;
|
||||
return m_file->write(*this, offset, data, data_size);
|
||||
}
|
||||
|
||||
KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, size_t count)
|
||||
{
|
||||
Locker locker(m_lock);
|
||||
|
|
|
@ -51,6 +51,10 @@ public:
|
|||
KResultOr<size_t> write(const UserOrKernelBuffer& data, size_t);
|
||||
KResult stat(::stat&);
|
||||
|
||||
// NOTE: These ignore the current offset of this file description.
|
||||
KResultOr<size_t> read(UserOrKernelBuffer&, u64 offset, size_t);
|
||||
KResultOr<size_t> write(u64 offset, UserOrKernelBuffer const&, size_t);
|
||||
|
||||
KResult chmod(mode_t);
|
||||
|
||||
bool can_read() const;
|
||||
|
|
Loading…
Reference in a new issue