From db97af8decc10ea21addcf5f6397d75bea2fd27b Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Thu, 6 May 2021 13:16:46 +0200 Subject: [PATCH] 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 --- repos/os/include/os/vfs.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/repos/os/include/os/vfs.h b/repos/os/include/os/vfs.h index 7917c33439..762974de04 100644 --- a/repos/os/include/os/vfs.h +++ b/repos/os/include/os/vfs.h @@ -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(); }