Skip to content

Commit fb8f348

Browse files
tpwrulesandyp1per
authored andcommitted
AP_Filesystem: littlefs: fix lseek
lseek must return the current file position. Previously, the littlefs version always returned 0, which broke terrain I/O as it checks that the position returned is the one it seeked to. Fix to return the current position, which is correctly returned from littlefs. This problem was originally and incorrectly diagnosed as an issue with littlefs seeking past the end of the file, but this functionality works fine and fixing the incorrect return completely fixes terrain. Terrain functionality was verified using `TERRAIN_DEBUG` on KakuteH7Mini-Nand running sim on HW. Terrain data is correctly downloaded from the GCS and loaded from the filesystem after reboot.
1 parent a23f9cd commit fb8f348

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

libraries/AP_Filesystem/AP_Filesystem_FlashMemory_LittleFS.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,13 @@ int32_t AP_Filesystem_FlashMemory_LittleFS::lseek(int fd, int32_t position, int
230230
break;
231231
}
232232

233-
lfs_soff_t size = lfs_file_size(&fs, &(fp->file));
234-
// emulate SEEK_SET past the end by truncating and filling with zeros
235-
if (position > size && whence == SEEK_SET) {
236-
LFS_CHECK(lfs_file_truncate(&fs, &(fp->file), position));
233+
lfs_soff_t pos = lfs_file_seek(&fs, &(fp->file), position, lfs_whence);
234+
if (pos < 0) {
235+
errno = errno_from_lfs_error(pos);
236+
return -1;
237237
}
238238

239-
LFS_CHECK(lfs_file_seek(&fs, &(fp->file), position, lfs_whence));
240-
return 0;
239+
return pos;
241240
}
242241

243242
int AP_Filesystem_FlashMemory_LittleFS::stat(const char *name, struct stat *buf)

0 commit comments

Comments
 (0)