I have a ubifs device (EdgerouterX) and a daemon that edits a configuration file on first startup. I kept noticing that this file, as well as other files I edited on the Edgerouter would become corrupt on a power failure and reboot.
Files that where edited get filled with this
No new lines, and in proportion to the length of the original file.
If I manually run 'sync' at any time then there's no corruption no matter how hard I try (without further editing I mean). But even waiting 10+ minutes the system itself does not run sync. Where can I edit the write back timeout?
Is the daemon calling
fsync(2)? If not it probably should to give a strong hint to the OS to commit the file.
It's a rust program, I tried adding what I'm pretty sure is the fsync call and that doesn't work. I'll dig more on the rust side.
This seems to be evident on devices with ubifs and kernel 4.14.x. I have seen it also on powerpc-based devices, meraki mr24. In my case, I am seeing the files from /rom/etc/config/ that don't change, but are copied to /overlay/upper/etc/config/ corrupted. I am currently chasing this on the #linux-mtd irc channel on irc.oftc.net
This fixes it for me (a little backporting is needed for 4.14): https://patchwork.ozlabs.org/patch/990017/