This is an automated email from the ASF dual-hosted git repository. jiuzhudong pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 2fa3b72b3c fs/smartfs: Fix a fatal bug about sector writing after seek 2fa3b72b3c is described below commit 2fa3b72b3cd0f8ff93c673dfde3276985537fa3c Author: SPRESENSE <41312067+sprese...@users.noreply.github.com> AuthorDate: Thu Jun 12 11:57:06 2025 +0900 fs/smartfs: Fix a fatal bug about sector writing after seek When writing to the next sector after the forward position has been written by seek, the old sector buffer is used, which may corrupt the file system. Therefore, the sector buffer must always be updated after a writing by seek. Signed-off-by: SPRESENSE <41312067+sprese...@users.noreply.github.com> --- fs/smartfs/smartfs_smart.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index 2317f967cd..3af3a6341f 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -796,6 +796,28 @@ static ssize_t smartfs_write(FAR struct file *filep, FAR const char *buffer, } } +#ifdef CONFIG_SMARTFS_USE_SECTOR_BUFFER + + /* If data is written to a forward position using seek, the sector + * buffer must be updated because it may be referenced later. + */ + + if (byteswritten > 0) + { + readwrite.logsector = sf->currsector; + readwrite.offset = 0; + readwrite.count = fs->fs_llformat.availbytes; + readwrite.buffer = (FAR uint8_t *)sf->buffer; + ret = FS_IOCTL(fs, BIOC_READSECT, (unsigned long)&readwrite); + if (ret < 0) + { + ferr("ERROR: Error %d reading sector %d\n", ret, sf->currsector); + goto errout_with_lock; + } + } + +#endif /* CONFIG_SMARTFS_USE_SECTOR_BUFFER */ + /* Now append data to end of the file. */ while (buflen > 0)