-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loss of Open Files on Power Loss or Reset #48
Comments
A couple other observations which may or may not be relevant to this ticket. It might be appropriate to create additional issues for these:
|
I think you just need to call |
I added a call to |
I also tried the case of moving the read after the write (and the call to |
are you seeking before reading? What kind of errors are you seeing? |
Yes, I call |
@BrianPugh Any more insight on this issue? |
the |
Were you able to reproduce it with the code snippet I provided above? |
I haven't had a chance to test this, i'll try to when i get a chance. |
@BrianPugh Is this still on your radar? It would be nice if we can get this resolved. Let me know if there's anything I can do to help. |
yeah sorry, been busy with the holidays and work. I'll try and reproduce it this weekend, but not sure if there will be any actionable items. It's PROBABLY an upstream issue, but i'll try and verify that its not something wrong with my port. |
@BrianPugh I'm also interested in this topic. Any insight or pointers you can provide? Based on littlefs documentation, I wasn't expecting this behavior but I may be misunderstanding something. |
Note that we were eventually able to work around this issue by using file pointers instead of streams. Using |
During extensive testing I recognized sometimes an fsync is not enough to have all data actually written. Because we are working with small blocks of data (64 bytes), I had to artificially flood the buffer when I really want to have all data written: void LOG_QuickSync(bool bFloodBuffer)
{
if (logFileWriteHandle != NULL)
{
if (bFloodBuffer)
{
/* Fill Cache with enough data that definitely all events are written. */
static const uint8_t DataBufferFiller[CONFIG_LITTLEFS_WRITE_SIZE] = {0};
fwrite((void *) DataBufferFiller, sizeof(uint8_t), sizeof(DataBufferFiller), logFileWriteHandle);
ESP_LOGI(TAG, "Forced quick sync for up-to-date log done!");
}
fsync(fileno(logFileWriteHandle));
}
} All tests with different littlefs configurations (changed PAGE, READ, WRITE, LOOKAHEAD and CACHE size) did not help. So I am posting this here that it might resolve the problem for others - or maybe someone comes up with a solution that the workaround is not needed. |
I'm not sure if this is a problem with this project, or with littleFS itself, but I'm going to start here.
The main problem is that I have files open when resetting the device. When I try to open the files again after reboot, the files appear to be empty. It doesn't really matter how much data is written. As long as the file stream isn't closed, the data is lost. Doing the same set of steps with SPIFFS, the data is not lost.
Here's as minimal of a repro as I can get. Run this, then hit the reset on the ESP32. Expected behavior is that the first read would read what was written in the previous run. Actual behavior is that it prints nothing and reports a 0 byte file size.
If you uncomment
// strm.close();
at the end, or remove thevTaskDelay(...)
, this code works as expected.For what it's worth, my real-life use case here is for saving logs to the filesystem. Losing everything that was logged at every reset is no bueno. :-/
The text was updated successfully, but these errors were encountered: