mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 00:25:07 +00:00
Kernel/FileSystem/FATFS: Restrict reads to the size of the file
Resolves issue where empty portions of a sector (or empty sectors in a cluster) would be included with the returned data in a read().
This commit is contained in:
parent
2995ee5858
commit
d6a519e9af
1 changed files with 10 additions and 2 deletions
|
@ -326,9 +326,17 @@ ErrorOr<size_t> FATInode::read_bytes_locked(off_t offset, size_t size, UserOrKer
|
|||
|
||||
// FIXME: Read only the needed blocks instead of the whole file
|
||||
auto blocks = TRY(const_cast<FATInode&>(*this).read_block_list());
|
||||
TRY(buffer.write(blocks->data() + offset, min(size, m_block_list.size() * fs().m_device_block_size - offset)));
|
||||
|
||||
return min(size, m_block_list.size() * fs().m_device_block_size - offset);
|
||||
// Take the minimum of the:
|
||||
// 1. User-specified size parameter
|
||||
// 2. The file size.
|
||||
// 3. The number of blocks returned for reading.
|
||||
size_t read_size = min(
|
||||
min(size, m_metadata.size - offset),
|
||||
(m_block_list.size() * fs().m_device_block_size) - offset);
|
||||
TRY(buffer.write(blocks->data() + offset, read_size));
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
InodeMetadata FATInode::metadata() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue