Here's the typical and well-known approach for atomic file updates:
fd = open(“foo.new”, O_WRONLY);
write(fd, buf, bufsize);
fsync(fd);
close(fd);
rename(“foo.new”, “foo”);
In general, if we also want durability (i.e. a guarantee that the new version of the file will be available if there is a crash), then we also need to call fsync
on the parent directory.
Question: Is this also needed for UBIFS? The documentation says:
fsync() may be called for directories - it synchronizes the directory inode meta-data. [...]
The fdatasync() call for directories is "no-op" in UBIFS and all UBIFS operations which change directory entries are synchronous.
If I am reading correctly, the latter ("all UBIFS operations which change directory entries are synchronous") seems to imply that calling fsync
on the parent dir would not be necessary. However my tests seem to indicate otherwise. Am I misreading the docs, or is this information outdated?
I asked on the MTD mailing list; seems that the documentation is ambiguous, and that calling fsync
on the parent dir is necessary as in other file systems.