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: