From 8d591d5bc7cc8a6953459718a4d614c547602815 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 18 Jan 2022 12:57:08 +0900 Subject: [PATCH] fs/smartfs: Fix file size corruption when opening with truncate mode If a existing file is opened with truncate mode e.g. fopen(file, "w+"), the file size will be incorrect after writing any data to the file. Before writing to the first sector, the reading is performed again. As a result, it makes an invalid file size. When a sector buffer is used, it must also write to the first sector. --- fs/smartfs/smartfs_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smartfs/smartfs_utils.c b/fs/smartfs/smartfs_utils.c index b0271653d2..90b3db185e 100644 --- a/fs/smartfs/smartfs_utils.c +++ b/fs/smartfs/smartfs_utils.c @@ -1765,8 +1765,8 @@ int smartfs_shrinkfile(FAR struct smartfs_mountpt_s *fs, remaining = 0; } } - else #endif + /* Are we retaining the sector it its entirety? */ if (remaining >= available)