Format of SPIFFS vs fopen with truncate

jsam589
Posts: 74
Joined: Sat Aug 17, 2019 9:31 pm

Format of SPIFFS vs fopen with truncate

Postby jsam589 » Tue Dec 10, 2019 4:19 pm

I have implemented a ping-pong log mechanism using two SPIFFS partitions.
Each partition will have just one file.
When the file on one reaches a certain size, I want to first "clean" the other partition so it has a new, empty file on it.
This way, I always have (after some initial period) one full log partition and a partial newer one.

Here is my question:
Currently, I "clean" the partition I am moving to by formatting it, then opening a new file, thus:

Code: Select all

esp_spiffs_format( conf.partition_label );
g_fp_log = fopen( pch, "w" );
The format takes 20 - 25 seconds. What would the drawbacks be to just using fopen() with "w" (which truncates an existing file of same name)? Would I be able to do this say, 50 times over a one year period without the SPIFFS file system becoming "full" or fragmented, etc.?

I have the formatting working successfully with about 20 tasks running in my system, but if a simple file truncate has no drawbacks, that is much faster and has less system impact.

Thanks!

Who is online

Users browsing this forum: Google [Bot], ok-home and 138 guests