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.
this PR adds a
transactional::Fs
newtype over the existingLittleFs
API.In "transactional" mode, the filesystem only exposes read-only
fs
operations (likeread_dir
and opening, not creating, a file). File writes are also allowed in this mode but they'll be cached to memory. TheFs.sync
method ends the transactional mode by consuming the newtype and returning the originalLittleFs
value;Fs.sync
will commit all pending file writes to the eMMC (*)(*) fine print synchronizing all the files is NOT guaranteed to be atomic: the files will be synchronized to disk one by one. If power is lost during this operation some files may end up updated while others not -- littlefs ensures the files won't be corrupted in this scenario.
Although neither littlefs or the eMMC provides a way to atomically update a group of files (as these may live in different eMMC sectors), it should still be possible to implement such functionality on top of
transactional::Fs
. For instance something like the code below would check whether a group of files has been atomically updated or not.Before reading files a, b or c one would check if
.lock
contains "WIP", which means the atomic file group update failed (e.g. because power was lost before.lock
was updated in the last line of the previous snippet), or "DONE", which means the atomic file group update succeeded.With checked atomic file group updates one could implement a revision, or backup, system for a group of files.
TODO
storage.rs
transactional::File.write
can fail due to the file cache being too small