Merge pull request #948 from littlefs-project/fix-sync-ordering

Fix sync issue where data writes could appear before metadata writes
This commit is contained in:
Christopher Haster
2024-03-08 16:49:59 -06:00
committed by GitHub
10 changed files with 163 additions and 13 deletions

9
lfs.c
View File

@@ -3404,6 +3404,15 @@ static int lfs_file_sync_(lfs_t *lfs, lfs_file_t *file) {
if ((file->flags & LFS_F_DIRTY) &&
!lfs_pair_isnull(file->m.pair)) {
// before we commit metadata, we need sync the disk to make sure
// data writes don't complete after metadata writes
if (!(file->flags & LFS_F_INLINE)) {
err = lfs_bd_sync(lfs, &lfs->pcache, &lfs->rcache, false);
if (err) {
return err;
}
}
// update dir entry
uint16_t type;
const void *buffer;