vfs: fix read of large files in fs_file_systems

For fs_file_systems, reads are limited to the size of the packets from the
File_system session. Hence, we cannot read the large files in one go.

This fix is particularly helpful for fonts_fs, as it enables including font
files from a File_system.

genodelabs/genode#4135
This commit is contained in:
Johannes Schlatow 2021-05-06 13:16:46 +02:00 committed by Christian Helmuth
parent 4daf19ec7e
commit db97af8dec

View File

@ -494,7 +494,21 @@ class Genode::File_content
:
_buffer(alloc, min(dir.file_size(rel_path), (Vfs::file_size)limit.value))
{
if (Readonly_file(dir, rel_path).read(_buffer.ptr, _buffer.size) != _buffer.size)
Readonly_file file {dir, rel_path};
size_t total_read = 0;
while (total_read < _buffer.size) {
size_t read_bytes = file.read(Readonly_file::At{total_read},
_buffer.ptr + total_read,
_buffer.size - total_read);
if (read_bytes == 0)
break;
total_read += read_bytes;
}
if (total_read != _buffer.size)
throw Truncated_during_read();
}