-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
File not truncated to actual size after calling fs_close #24462
Comments
The file system is behaving as it should. Zephyr's file system (and particularly littlefs) follows POSIX file system standards: if you open an existing file, you are positioned at the start, but the existing file content is not removed. So what your example does is:
As an aside this command:
does not change the buffer content (the length to set is zero). Since you don't check the return code from the read you aren't confirming that the file content is correct: a potential (but not present) failure mode would be that the read failed and the buffer content was left unchanged which would be 50 0x55 followed by 50 0xAA. If you add this to step 2 just before the close:
you will discard the remainder of the file. Or you could |
Reading your original comment more completely: Yes, this is compatible with POSIX, given that Zephyr doesn't allow you to provide flags. The open it's simulating acts as though it was given |
Thank you for your answer. I was expecting the behaviour to be more inline with POSIX Just a suggestion, that maybe this should be made explicit in the documentation. Most programmers typically deal with Also, the code that I provided was from memory, to provide a schematic. The memset line was a typo. Thank you for pointing it out. It has has been corrected. |
I see that with POSIX I don't think there's anything to be done here. But thank you for providing a clear example of what you were doing; it did make verifying that littlefs is behaving correctly easier. |
That is true but without flags it is effectively Thank you for answering my question and resolving the issue. |
But And you're welcome. |
TIL! |
Describe the bug
When a file is rewritten with less data and then closed the file is not truncated to the most recent data. The old data is still in the file.
To Reproduce
Expected behavior
When a file is closed, it should be truncated to the current data. Old data should be discarded.
Impact
I can currently work around this by calling
fs_truncate
after callingfs_close
but this is unusual, unexpected behaviour and not consistent with POSIX file operations.Environment
The text was updated successfully, but these errors were encountered: