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 */