SPIFFS good practices, error or corruption

FoxTerrier
Posts: 3
Joined: Tue Sep 22, 2020 12:43 pm

SPIFFS good practices, error or corruption

Postby FoxTerrier » Fri Oct 09, 2020 1:31 pm

Hello,
in my actual project, i use spiffs 2MB partition (on 16MB esp32) to create a text log file each boot, incrementing name. (find first free name).
when wifi is available, system upload/chack validity then DEL spiffs file. for each present log file.
it work fine, BUT...
After 100 or more create/del, system really slow down when he must creat file, write to file, read file, ..... i presume it caused by all "deleted" files, just tagged as deleted, but present. system has to manage dir with (example) 250 deleted files a 2 presents.
that's first problem.
not possible to find how to force a check FS, a clean FS (garbage collection ?)... only way i found : reformat SPIFFS partition. no so good solution, but work fast again directly.
WHAT YOUR ADVICE ?
another problem is corrupted file : given as (example) 4720 bytes, bhen open to send, NOTHING (0 bytes) as answer. nothing in file.
how to avoid ? how to repair ?
to avoid to leave opened file, or open at each log line added to log, i created a 4K ram buffer to put new log lines.
every 3 sec, if ram buffer >100 bytes, it flush this buffer to spiffs (open/append/close). it enable a flag to stop "all other tasks" in my app during write to spiffs.... all of this minimize also risk to crash if poweroff occur there... (i readed in doc : spiffs mark block as good/bad/... to avoid power failure causing crashes)..... but in my case, some files are corrupted... then ? why ? how ?
i also limited to 1 file acces at time to be shure no problem due to more then 1 file opened (setting max file=5 in my project)
i tried to "mkspiffs -i" a grub of spiffs, i got some infos like this (see attachements), but found nowhere to explain how to "read/understand" it....
Someone to help/advice me ?
Thanks a lot !
Attachments
Screenshot from 2020-10-09 15-27-19.png
Screenshot from 2020-10-09 15-27-19.png (15.26 KiB) Viewed 3218 times
Screenshot from 2020-10-09 15-27-04.png
Screenshot from 2020-10-09 15-27-04.png (18.74 KiB) Viewed 3218 times

Who is online

Users browsing this forum: No registered users and 61 guests