Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2019-05-29 02:16:51 +0300
committerChristopher Haster <chaster@utexas.edu>2019-07-01 23:11:38 +0300
commita9a61a3e7860deaabc8645cbf586ad9ce85de3bc (patch)
treeb8565a91de61e195ef37b21526a0b01dccd1c989
parent36973d8fd56c3bf6bc0002060a45ff2c3c2b48d5 (diff)
Added redundant compaction to lfs_format/lfs_migrate
This ensures that both blocks in the superblock pair are written with the superblock info. While this does use an additional erase cycle, it prevents older versions of littlefs from accidentally being picked up in the case that the disk is mounted on a system that doesn't support the newer version. This does bring back the risk of picking up old littlefs versions on a disk that has been formatted with a filesystem that doesn't use block 2 (such as FAT), but this risk already exists, and moving between versions of littlefs is more likely with the recent v1 -> v2 update. Suggested by rojer
-rw-r--r--lfs.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lfs.c b/lfs.c
index 7bd63e5..8ebf4ed 100644
--- a/lfs.c
+++ b/lfs.c
@@ -3338,6 +3338,14 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
if (err) {
goto cleanup;
}
+
+ // force compaction to prevent accidentally mounting any
+ // older version of littlefs that may live on disk
+ root.erased = false;
+ err = lfs_dir_commit(lfs, &root, NULL, 0);
+ if (err) {
+ goto cleanup;
+ }
}
cleanup:
@@ -4447,6 +4455,13 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) {
if (err) {
goto cleanup;
}
+
+ // force compaction to prevent accidentally mounting v1
+ dir2.erased = false;
+ err = lfs_dir_commit(lfs, &dir2, NULL, 0);
+ if (err) {
+ goto cleanup;
+ }
}
cleanup: