From ac528203fea423731df48861e918a856bc33d78f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 24 Feb 2021 13:26:58 +0800 Subject: [PATCH] fs/lfs: lfs_file_sync() when littlefs_open Signed-off-by: Xiang Xiao Signed-off-by: ligd Change-Id: I8935f7aee414580174141f4b114b5faf03ffafd5 --- fs/littlefs/lfs_vfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index ffaa5a2d3c..4cc41c4ec1 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -55,7 +55,7 @@ struct littlefs_mountpt_s FAR struct inode *drv; struct mtd_geometry_s geo; struct lfs_config cfg; - lfs_t lfs; + struct lfs lfs; }; /**************************************************************************** @@ -279,6 +279,12 @@ static int littlefs_open(FAR struct file *filep, FAR const char *relpath, } } + /* Sync here in case of O_TRUNC haven't actually done immediately, + * e.g. total 8M, fileA 6M, O_TRUNC re-wrting fileA 6M, meet error. + */ + + lfs_file_sync(&fs->lfs, priv); + littlefs_semgive(fs); /* Attach the private date to the struct file instance */