littlefs-project / littlefs

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

How do I truncate size file with last data (beginning file) was removed? #889

Open votuananhs opened 8 months ago

votuananhs commented 8 months ago

Hello all, I have logging data file. And I would like to remove in last data in case size file is going to limit size for that. I found lfs_file_truncate() function. But I have tried to run sample code with this function. It will keep data and size after running this command from beginning to size requested. That it doesn't meet my expectation. Do we have any solution for that with littlefs ? Many thanks in advance for your support/answer !

geky commented 8 months ago

Hi @votuananhs, unfortunately this is not provided by littlefs's APIs, and is in general not an operation filesystems support.

The best solution for logging over a filesystem seems to currently be maintaining multiple copies of the log file: https://github.com/littlefs-project/littlefs/issues/104

Though users note that multiple small files may be a better solution: https://github.com/littlefs-project/littlefs/issues/862

geky commented 8 months ago

Though if it's any consolation, I'm currently looking into an API that would provide exactly this. It's very experimental though.