littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.9k stars 771 forks source link

data loss in littlefs #943

Closed Aravind0812 closed 4 months ago

Aravind0812 commented 4 months ago

Hi, I am using w25Q512 flash memory. my cache size is 256 bytes, after filling 256 bytes littlefs writing to Flash is success, but it is not updating on metadata, when I close the file only is updating, otherwise is not updating on metadata. I didn't close the file after i open the file i lost my old data. my question is why is not updating on meta data (or) only file close or file sync only save the and update the value on metadata (or) any other method is available to save without call file-close or file-sync function.

geky commented 4 months ago

Hi @Aravind0812, if I understand correctly, this is just how littlefs works.

In general, it is more efficient to wait as long as possible to update the metadata, because littlefs doesn't know how much data is being written until lfs_file_close.

lfs_file_sync allows you to manually update the metadata if you want to keep the file open. It's ok to call lfs_file_sync after every file write.

Aravind0812 commented 4 months ago

Thank you for the response, Now i understand.