From 03f088b92c024bd64b2635d3d6896403514fb9b7 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 20 Mar 2022 23:14:34 -0500 Subject: [PATCH] Tweaked lfs_file_flush to still flush caches when build under LFS_READONLY A slight varation to the fix from ondrap --- lfs.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lfs.c b/lfs.c index 351a126f..2da68b56 100644 --- a/lfs.c +++ b/lfs.c @@ -2730,19 +2730,15 @@ static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file) { } #endif -static void lfs_file_invalidate_reading_flag(lfs_t *lfs, lfs_file_t *file) { +static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { if (file->flags & LFS_F_READING) { if (!(file->flags & LFS_F_INLINE)) { lfs_cache_drop(lfs, &file->cache); } file->flags &= ~LFS_F_READING; } -} #ifndef LFS_READONLY -static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { - lfs_file_invalidate_reading_flag(lfs, file); - if (file->flags & LFS_F_WRITING) { lfs_off_t pos = file->pos; @@ -2809,10 +2805,10 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { file->pos = pos; } +#endif return 0; } -#endif #ifndef LFS_READONLY static int lfs_file_rawsync(lfs_t *lfs, lfs_file_t *file) { @@ -3085,17 +3081,11 @@ static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file, return npos; } -#ifndef LFS_READONLY // write out everything beforehand, may be noop if rdonly int err = lfs_file_flush(lfs, file); if (err) { return err; } -#else - // Seek doesn't update cache parameters properly. - // It has to be invalidated otherwise next read will return incorrect values. - lfs_file_invalidate_reading_flag(lfs,file); -#endif // update pos file->pos = npos;