-
Notifications
You must be signed in to change notification settings - Fork 6
fix: add Sync() calls to persist filesystem changes to storage #27
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
base: dev
Are you sure you want to change the base?
Conversation
- Add Sync() after Format, Unmount, Remove, Rename, Mkdir - Add Sync() after File.Close, File.Sync, File.Truncate - Sync on OpenFile with O_CREATE/O_TRUNC flags - Fix cache invalidation in lfs_bd_flush - Add TestDirectoryPersistence and NestedDirectories tests"
Fix filesystem persistence on SD cardsProblemI was working with LittleFS on a Grand Central M4 with an SD card and noticed that directories and files I created weren't surviving a power cycle. I'd run InvestigationI traced the data flow through the code:
The problem: the SD card driver holds writes in a buffer for efficiency. Without explicitly calling Looking at the original code, I noticed that mutating operations just returned after calling the C function—no sync. The block device interface in What I changed
|
| return nil, err | ||
| } | ||
|
|
||
| if flags&(os.O_CREATE|os.O_TRUNC) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it makes sense to call Sync() on an Open().
| if err := errval(C.lfs_file_sync(f.lfs.lfs, f.fileptr())); err != nil { | ||
| return err | ||
| } | ||
| if syncer, ok := f.lfs.dev.(tinyfs.Syncer); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually Sync() on a Sync()? Seems like a yes! 👍
|
Hello @marcelfarres thanks for the code submission. Please see my comments. |
|
I probably did not notice the issue due to using flash pretty much all of the time. |
I was trying to create folders & files in the SD card and it was not working.
This changes seem to make it functional again.
I test it on a M4 Gran Central, and seems to have dir persistent and creation even after mounting/un-moutning the file system.
Not an expert in any extend on TinyGo, hope it helps/you can test it/review it.
Should fix #9