Repository navigation
Write config files through a temp file and rename (nRF52, STM32) - #3763
Open
marcelverdult wants to merge 1 commit into
Open
marcelverdult wants to merge 1 commit into
marcelverdult wants to merge 1 commit into
Conversation
…rite On littlefs platforms (nRF52, STM32) a power loss between remove() and the end of the rewrite lost the file. AtomicFile::write() writes <file>.tmp, checks its size after close and renames it over the target, so the old file stays until the new one is complete. If the temp copy does not fit it falls back to the old in-place behaviour. Orphaned .tmp files are removed on load. Used by IdentityStore, CommonCLI prefs, ClientACL, RegionMap and the companion DataStore (prefs, contacts, channels). ESP32 and RP2040 are unchanged unless MESH_ATOMIC_FS_WRITES is defined. Not tested on a device.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Identity, prefs, contacts, channels, ACL and regions are saved with
remove(file)followed byopen(FILE_O_WRITE)and a rewrite. If power drops between the remove and the end of the rewrite, the file is gone or short. On a node that runs a battery flat this loses the identity or the contact list.Change
New
AtomicFile::write(). On littlefs platforms (nRF52, STM32) it writes<file>.tmp, closes it, checks that the size on flash matches what was written, and renames it over the target.lfs_rename()replaces an existing target in one commit, so a power loss leaves the old or the new file. Orphaned.tmpfiles are removed when the file is loaded.Used by IdentityStore, CommonCLI prefs, ClientACL, RegionMap and the companion DataStore (prefs, contacts, channels).
MESH_ATOMIC_FS_WRITESto switch them on once rename over an existing file is confirmed there./adv_blobs(changed in place, littlefs is copy on write), the one-time migration, the packet log (append).Testing
native_atomic_file(7 tests, new, with an in-memory LittleFS mock) andnative: all pass.