You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/07/22 09:22:30 UTC
[incubator-nuttx] branch master updated: fs/smartfs: Fix file size
corruption when opening with overwriting mode
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 89a79b0 fs/smartfs: Fix file size corruption when opening with overwriting mode
89a79b0 is described below
commit 89a79b03cfcdd07a11b799fd4612e57d35d659f7
Author: SPRESENSE <41...@users.noreply.github.com>
AuthorDate: Wed Jul 22 14:41:40 2020 +0900
fs/smartfs: Fix file size corruption when opening with overwriting mode
If a existing file is opened with overwriting mode e.g. fopen(file, "w+"),
the file size will be incorrect after writing any data to the file.
This bug is caused by previous commit 10903b5, and its changes should be
limited to only O_APPEND mode.
---
fs/smartfs/smartfs_smart.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c
index 60c591b..dca3b8b 100644
--- a/fs/smartfs/smartfs_smart.c
+++ b/fs/smartfs/smartfs_smart.c
@@ -331,10 +331,11 @@ static int smartfs_open(FAR struct file *filep, const char *relpath,
/* When using sector buffering, current sector with its header should
* always be present in sf->buffer. Otherwise data corruption may arise
- * when writing.
+ * when writing. However, this does not apply when overwriting without
+ * append mode.
*/
- if (sf->currsector != SMARTFS_ERASEDSTATE_16BIT)
+ if ((sf->currsector != SMARTFS_ERASEDSTATE_16BIT) && (oflags & O_APPEND))
{
readwrite.logsector = sf->currsector;
readwrite.offset = 0;