Closed Blueknife-w closed 1 year ago
Note, the subtype I used for the littlefs partition is FAT, not SPIFFS, this should not affect it
I solved this problem using the following two methods:
fsync
command after fflush
Flush file to flash after each write operation
in menucofnig.
I recently ported esp_littlefs to run on esp32, and tried to refer to Easylogger for a program based on file storage logs to record device log information. During the process, I encountered the following problems:
After opening the file, every time a log is written,
fflush
is called to refresh the cache, the file pointer moves, but the file size does not change; and after the device is powered off, the file is still rewritten from the position when it was opened last time data. However, I continue to test and callclose
to close the file immediately after writing a log, and there is no such problem.I am not very familiar with the operation of the file system API, so I am not sure whether this problem is my operation problem or the problem of esp_littlefs or littlefs, hoping to be corrected.
log write function
Traverse directory file information function
Do the following in the main loop
The running log is as follows,and you can see the file pointer is offset, but file size isn't change.
Reset device, the log is as follows, the file is written again from offset 320!