Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/fs/fat/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ ssize_t fat_file::read_file_priv(void *_buf, const off_t offset, size_t len) {
if (offset_within_sector == fs_->info().bytes_per_sector) {
offset_within_sector = 0;
// push the iterator forward to next sector
err = fbi.next_sector();
if (err < 0) {
return err;
if (buf_offset < len) {
err = fbi.next_sector();
if (err < 0) {
return err;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/fs/fat/test/mkblk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ for i in blk.bin.*; do
mmd -i $i dir.c
mcopy -i $i hello.txt ::dir.a/long_filename_hello.txt
mcopy -i $i largefile ::largefile
mcopy -i $i test_4kb.bin ::test_4kb.bin
mcopy -i $i test_8kb.bin ::test_8kb.bin

# add a bunch of entries to the root dir that cause it
# to spill over to a few extra sectors
Expand Down
4 changes: 4 additions & 0 deletions lib/fs/fat/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// pull in a few test files into rodata to test against
INCFILE(test_file_hello, test_file_hello_size, LOCAL_DIR "/hello.txt");
INCFILE(test_file_license, test_file_license_size, LOCAL_DIR "/LICENSE");
INCFILE(test_file_4kb, test_file_4kb_size, LOCAL_DIR "/test_4kb.bin");
INCFILE(test_file_8kb, test_file_8kb_size, LOCAL_DIR "/test_8kb.bin");

namespace {

Expand Down Expand Up @@ -171,6 +173,8 @@ bool test_fat_read_file() {
EXPECT_TRUE(test_file_read(test_path "/long_filename_hello.txt", test_file_hello, test_file_hello_size));
EXPECT_TRUE(test_file_read(test_path "/a_very_long_filename_hello_that_uses_at_least_a_few_entries.txt", test_file_hello, test_file_hello_size));
EXPECT_TRUE(test_file_read(test_path "/dir.a/long_filename_hello.txt", test_file_hello, test_file_hello_size));
EXPECT_TRUE(test_file_read(test_path "/test_4kb.bin", test_file_4kb, test_file_4kb_size));
EXPECT_TRUE(test_file_read(test_path "/test_8kb.bin", test_file_8kb, test_file_8kb_size));

// unmount the fs
unmount_cleanup.cancel();
Expand Down
Binary file added lib/fs/fat/test/test_4kb.bin
Binary file not shown.
Binary file added lib/fs/fat/test/test_8kb.bin
Binary file not shown.