Fixed file buffers falling out-of-date when bypassed during writes
This can happend if we read some data into our buffer (or write+flush+seek in some weird pattern) and then do a bypassing write that overlaps the buffer. The solution here is to make sure the buffer is cleared when doing bypassing writes. In theory, we could be a bit smarter by checking and only clearing when overlap occurs, or even updating the buffer with the new contents like we do in the bd cache layer, but the value would probably be minimal. File writes are already expected to clobber buffered reads.
This commit is contained in:
@@ -10478,7 +10478,13 @@ lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file,
|
||||
// strictly necessary, but enforces a more intuitive write order
|
||||
// and avoids weird cases with low-level write heuristics
|
||||
//
|
||||
// oh, and also avoids issues with out-of-date buffers
|
||||
//
|
||||
if (!unflushed_ && size >= lfs->cfg->cache_size) {
|
||||
// clear buffer to avoid out-of-date data
|
||||
buffer_pos_ = 0;
|
||||
buffer_size_ = 0;
|
||||
|
||||
err = lfsr_ftree_flush(lfs, &file->mdir, &ftree_,
|
||||
pos_, buffer_, size);
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user