From 872faecf9660cc2469aa5586f81639f7986b6b8f Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 21 May 2021 17:41:06 +0200 Subject: Add fs_read and fs_write functions and some testing --- src/filesystem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/filesystem.c') diff --git a/src/filesystem.c b/src/filesystem.c index 2da77be..1521d69 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -116,3 +116,18 @@ fs_write(u8 *src, size_t n_bytes, u16 file_index, u16 offset, bool append) { return n_bytes; } + +int +fs_read(u8 *dst, size_t n_bytes, u16 file_index, u16 offset) { + File *file = &filesystem.files[file_index]; + + // Check if the offset is within limits. + if (offset + n_bytes >= FILE_MAX_SIZE) { + return -1; + } + + // Copy n_bytes to destination. + _fs_read(dst, FILE_DATA_OFFSET + FILE_MAX_SIZE * file_index + offset, n_bytes); + + return n_bytes; +} -- cgit v1.2.1