Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Questions about data write security #1022

Open
binlaodi opened this issue Sep 6, 2024 · 1 comment
Open

Questions about data write security #1022

binlaodi opened this issue Sep 6, 2024 · 1 comment
Labels

Comments

@binlaodi
Copy link

binlaodi commented Sep 6, 2024

I've taken a look at the littlefs design documentation, and there are some examples of how to identify and deal with bad areas. I wonder if calling lfs_file_write() returns LFS_ERR_OK, does that mean the data was written correctly? Do we also need to customize the contents of the file, such as adding crc, and then reading it out to verify the crc after successful writing?

@geky geky added the question label Sep 20, 2024
@geky
Copy link
Member

geky commented Sep 20, 2024

Hi @binlaodi, thanks for creating an issue, sorry about the late response.

First thing to note is that lfs_file_write caches data and doesn't write it immediately, but you can force pending writes to be written to disk with lfs_file_sync.

Second thing to note is that LFS_ERR_OK indicates the data was written to disk to the best of littlefs's knowledge. The way littlefs works is that on every prog operation, it immediately reads back the data to check that the data read matches the data written. If it doesn't match littlefs move the data to a different block.

But this only happens at write time, and doesn't account for errors that may occur to the data after writing. There are some plans to add data checksumming in the future, but right now any bit errors that develop after writing+verification go undetected.


So you don't need a separate CRC to verify writes, but it may be useful for verifying data at read time.

Alternatively, implementing error correction in the block device layer (some block devices provide this in hardware) can also protect against bit errors, but may require more work to implement.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants