Skip to content

Fix rcache data mismatch if lfs->cfg->read() returns an error (non-zero)#1206

Open
simaodangan wants to merge 1 commit intolittlefs-project:masterfrom
simaodangan:master
Open

Fix rcache data mismatch if lfs->cfg->read() returns an error (non-zero)#1206
simaodangan wants to merge 1 commit intolittlefs-project:masterfrom
simaodangan:master

Conversation

@simaodangan
Copy link
Copy Markdown

Description

After a file is successfully opened and written, if the SD card fails (for example, the card is removed), subsequent operations may behave incorrectly.

A simplified example:

file = lfs_open(); // Success

lfs_write(file, "something 1"); // Success

// Simulate SD card removal: lfs->cfg->read() now returns a negative error code

// During the next write, lfs attempts to write to the last block.
// The read operation fails, but rcache still points to the last block.
lfs_write(file, "something 2");   // Fails

// When reading the file and accessing the last block, rcache matches.
// Invalid data is read from rcache, and the return value is "LFS_ERR_OK".
error_code = lfs_read(file, buffer); // Returns "LFS_ERR_OK", but buffer contains invalid data

@geky-bot
Copy link
Copy Markdown
Collaborator

Tests passed ✓, Code: 17208 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 812 B (+0.0%)
Code Stack Structs Coverage
Default 17208 B (+0.0%) 1448 B (+0.0%) 812 B (+0.0%) Lines 2450/2611 lines (-0.0%)
Readonly 6242 B (+0.1%) 448 B (+0.0%) 812 B (+0.0%) Branches 1301/1638 branches (-0.0%)
Threadsafe 18064 B (+0.0%) 1448 B (+0.0%) 820 B (+0.0%) Benchmarks
Multiversion 17280 B (+0.0%) 1448 B (+0.0%) 816 B (+0.0%) Readed 29000746676 B (+0.0%)
Migrate 18872 B (+0.0%) 1752 B (+0.0%) 816 B (+0.0%) Proged 1482895246 B (+0.0%)
Error-asserts 18040 B (+0.0%) 1440 B (+0.0%) 812 B (+0.0%) Erased 1568921600 B (+0.0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants