-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Append to file on SPIFFS does not return actual bytes writen #5987
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
Comments
The SPIFFS may become fragmented, so it is possible a file cannot be appended to even though there is room on the file system. So there has to be a proper check to see if writing fails and also delete oldest file(s) when needed + call to the garbage collector. See also esp8266/Arduino#5987
If this is the case, then there is an intenal SPIFFS filesystem issue and there's not much we can do about it.
I doubt we can do much here about it. |
What happens if you close/reopen the file and check its size ? |
@d-a-v I will try to make a build using debugging. (would be nice if that could be done using a simple define in PlatformIO, is that possible?) As you can see in my example code, the file is not closed, nor do I call a flush to the filesystem. The filesize is just checked right after the write command. Even then it is already visible no data has been appended. |
Just a quick analysis of the write code in the SPIFFS library: We have several scenarios:
|
Closing as a won't-fix since SPIFFS is being deprecated. LittleFS has its own issues, sometimes, but will be the actively supported FS for now. |
Basic Infos
Platform
Settings in IDE
Problem Description
I know that SPIFFS may get fragmented, therefore I have a check to see if the
write
to a file (append mode) on SPIFFS may return less than the number of bytes I want to write to it.However, this check was never hit in my sketch.
I now have a check for file size before and after the write and this does show the bytes are not appended to my file when the SPIFFS is out of free sectors to write to.
N.B.
fw
is aFile fw;
This does result in errors like:
I guess the
write
function should return the actual number of bytes written.But on the other hand it may be that we're looking at some cache layer here?
Also replacement of data in a file will not result in a bigger file, but it may go unnoticed if the write was unsuccessful.
The text was updated successfully, but these errors were encountered: