Skip to content
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

Update to LFS v1.7.2 tag - to fix filesystem corruption due to file renames #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

geeksville
Copy link
Contributor

@geeksville geeksville commented Aug 14, 2024

(from meshtastic/firmware#4395 )

Hi @hathach long time no see - I hope all is well for you! I'm back working on Meshtastic again and one of the things in my queue was addressing some problems we've seen in the field with LFS on nrf52. This PR is to address one of those problems - I'm submitting it upstream in hopes that it is useful for other adafruit users and also so we can stop using a temporary fork which contains this change.

Filesystem corruption due to LFS renames

While stress testing (rarely - a couple of times a day on a node repeatedly writing/renaming/rebooting/reading files) filesystem corruption was seen that was not caused due to a reboot while writing.
After some debugging and checking github history, it seems that someone else had already found and fixed this bug:
littlefs-project/littlefs@97d8d5e

As poor luck would have it they fixed it a few days after adafruit forked from the master LFS tree. The version in adafruit was forked on oct 15,2018 f328685. This version is version in framework-arduinoadafruitnrf52 is: commit cb62bf2188854c5b7c44383571ebb19a414e6137 (tag: v1.6.1)

With this fix the 'rename related' corruption no longer occurs.

Since it seemed I needed to update LFS, I went ahead and updated it to the 'final' LFS 1.x release (v1.7.2) so that hopefully this update will be more useful to other adafruit users.

The only other change in in v1.7.2 vs v1.6.1 is a check for 2GB files. which is not a real problem for adafruit obviously - but I included it anyways because tiny and then it will be easy for downstream users to know 'oh the version in adafruit is the final version of LFS 1.x.

I updated lfs.c and lfs.h by first generating a patch file between the old adafruit tree and v1.6.1 of LFS, then copied in the v1.7.2 version of those three files, then reapplied the patch file so that the (small number of) existing adafruit local changes were preserved.

adafruit specific changes to LFS are capured now in this patch file in ~/tmp
diff -crB ~/development/meshtastic/littlefs littlefs > dfile.patch
kevinh@kdesktop:~/.platformio/packages/framework-arduinoadafruitnrf52/libraries/Adafruit_LittleFS/src$ code dfile.patch 
kevinh@kdesktop:~/.platformio/packages/framework-arduinoadafruitnrf52/libraries/Adafruit_LittleFS/src$ mv dfile.patch ~/tmp/lfs-adafruit.patch
apply patch with "patch -p0 --dry-run < dfile.patch"

I wanted to update LFS to pull in a particular fix they made upstream:
littlefs-project/littlefs@97d8d5e

Since I was doing the update anyways (to this old/stable lib) I updated to
the 'highest' LFS version which is still backwards compatible to the
v1.6.1 version which had been used originally to create the adafruit fork.

The other fixes in 1.7.2/1.7.0 (they are identical wrt. lfs.c) IMO are
unlikely to be critical for adafruit but see the full list here:

https://github.com/littlefs-project/littlefs/releases/tag/v1.7.0
@geeksville
Copy link
Contributor Author

btw meshtastic/firmware#4447 might be interesting for you as well. I'm sure you had no other option (given the tiny number of free 4KB flash pages available in the nrf52) and you probably understood the implied risk. But I thought I'd mention it just in case it is useful to you. Keep rocking it!

@geeksville geeksville changed the title Update to LFS v1.7.2 tag - primary to fix filesystem corruption due to file renames Update to LFS v1.7.2 tag - to fix filesystem corruption due to file renames Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant