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+SPRESENSE@users.noreply.github.com>
This commit is contained in:
SPRESENSE
2025-06-12 11:57:06 +09:00
committed by Donny(董九柱)
parent 28b2e01c22
commit 2fa3b72b3c

View File

@@ -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)