diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index 2317f967cd5..3af3a6341fe 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)