mirror of
https://github.com/apache/nuttx.git
synced 2025-12-10 12:14:36 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user