littlefs-project / littlefs

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

Overwriting flash Memory and Read Data #841

Open Aravind0812 opened 1 year ago

Aravind0812 commented 1 year ago

Currently, I am working on the W25q128 module. Once storage is filled, I want to overwrite the first block without data corruption for that module. But, I have a problem rewinding the file pointer and erasing the first block but littlefs, Erase the last block. How to erase the block in sequence order after erasing and writing the first block, how to read the data in the correct order?

geky commented 1 year ago

Hi @Aravind0812, sorry if I misunderstand the question.

littlefs doesn't store files on disk in reliable locations. As files are rewritten littlefs moves them around to distribute wear.

Files are also broken up into multiple blocks which get stored in arbitrary locations, and once they are larger enough start containing extra metadata that would mess up most use cases that would rely on this.

Though there is a PR requesting to add a different file type that would accomplish this: https://github.com/littlefs-project/littlefs/pull/692