-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LittleFS unexpected behaviour #7426
Comments
We had this come up before, but on a performance and not functionality level. littlefs-project/littlefs#244 .
Perhaps an even better solution is to truncate and sync immediately on open with |
I think this would be the expected behavior of most users if the "w" or "w+" mode open call performs the truncation and syncing internally ;-) As you said - it would just work! |
@dplasa, your MCVE is not failing for me. I did have to change I set FS=1MB, uploaded, and both writes take ~15000ms for me. No OOS errors, no other problems. I'm running git head, but I don't see any commits since 2.7.1 which would affect this. Can you please double-check your MCVE ASAP? We're really close to 2.7.2, so if you want a fix in, it's gotta be very soon. |
@earlephilhower I've re-run my example (also had to add
|
Upload info
I selected "4MB (1MB FS; OTA ~1019kB)" |
Hmmm..maybe there was something in the 2.7.1->2.7.2 change that affected it as that's my exact config (D1 Minin, FS=1MB, OTA ~1MB). I will check out 2.7.1 and re-run and then 2.7.2 and compare. |
Fixes esp8266#7426 LittleFS doesn't update the on-flash data structures when a file is reopened as O_TRUNC until the file is closed. This means the space of the original, inaccessible file cannot be used, causing OOS errors in cases when a large file is being overwritten. Explicitly call the file sync operation to update the on-flash metadata as soon as a file is opened. For normal files it's a no-op, but for O_TRUNC modes it will free the space, allowing full overwrite of large files.
Able to repro it, now. I had other changes in my repo but a LFS has made some interesting design choices, that's for sure. They did things this way to allow fully atomic file overwrites... |
Thanks for the fix! |
@dplasa, please verify the fix and report back. You can just add the 1 line or do a full git checkout of the PR. Once we get confirmation it can merge, then GH will close this issue. |
@earlephilhower it works! Added the lfs_file_sync(...) line, recompiled example, fixed it!
Looks good in my opinion. |
* Free space of overwritten files in LittleFS Fixes #7426 LittleFS doesn't update the on-flash data structures when a file is reopened as O_TRUNC until the file is closed. This means the space of the original, inaccessible file cannot be used, causing OOS errors in cases when a large file is being overwritten. Explicitly call the file sync operation to update the on-flash metadata as soon as a file is opened. For normal files it's a no-op, but for O_TRUNC modes it will free the space, allowing full overwrite of large files. * Add host test case for change
Basic Infos
Platform
Settings in IDE
Problem Description
When working with big files on LittleFS, overwriting a big file might fail as LittleFS seems to release the previous file contents only after a sync (i.e. close) of that file as it uses a COW strategy (see littlefs-project/littlefs#123)
So if you have a 1MB FS and a file of 512KB you cannot overwrite that file with 512KB of data. This will fail since during that overwrite up to 1024KB need to be in that 1M FS which has less net space.
Remedy: you have to truncate the file by
This should be somehow documented in the docs. It would also be nice to have a call like
LittleFS.sync();
or another flagLittleFS.open(... "ws")
to indicate that writing should be synced. The lower lfs_* calls seem to provide such functionality.MCVE Sketch
Debug Messages
The text was updated successfully, but these errors were encountered: