Open b-scramps opened 3 years ago
Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers. Internal Jira reference: https://jira.arm.com/browse/IOTOSM-3172
Thanks for the report, we will review.
cc @ARMmbed/mbed-os-core
Description of defect
When opening a file with the mbed C++
File
API using the O_APPEND flag on a littlefs, the behavior is unexpected. Generally (and in the case of opening a file with the FAT filesystem) opening a file with append attributes will seek to the end of the file upon opening, but then respect all seek operations after that.In the case of LittleFS, opening a file with O_APPEND will force-seek the file to the end of the file on every write. This is evident in
lfs.c:lfs_file_write()
, which explicitly setsfile->pos
tofile->size
if the file was opened withO_APPEND
.It is not clear if this is even a "bug" within littlefs, but it definitely is an inconsistency within mbed. Switching from FATFileSystem to LittleFileSystem should be transparent, and the documentation is not clear on this particular nuance.
The "fix" for this is trivial (move the offending code out of
lfs_file_write
and into the init function), but if this is an intentional trait of littlefs, then this bug report should serve as a discussion starter.Target(s) affected by this defect ?
All
Toolchain(s) (name and version) displaying this defect ?
N/A
What version of Mbed-os are you using (tag or sha) ?
5.15, but it appears that the latest versions of littlefs:lfs.c and littlefsv2:lfs.c would have the same problem.
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
Custom cmake build system
How is this defect reproduced ?
Create a littlefs filesystem and open a File with O_APPEND. Write some data, then seek to beginning and write different data. The "different data" will be appended to the end of the file despite the file being seeked to beginning before the write.