Currently I am writing an Android application which needs to work with lot of files at native side.
Recently I ran into several data loss or inconsistency problems while updating or renaming these files. (All these files are stored within several sub-directories from a common parent/root directory.)
After reading several articles about fsync(), I decided to use it. However I had one thing unclear:
Does calling fsync() on a parent directory guarantee synchronization of meta data of all sub directories, recursively?
That is, lets say I do a lot of rename operations of several files in different sub-directories within a common parent directory.
Then should I call fsync() on each sub-directory separately or calling fsync() on my parent directory is enough to make sure the meta data of all sub-directories (and their child directories recursively) are synchronized with the physical device?
Basically the idea is to save time by avoiding multiple fsync() calls. Or would it take more time for fsync() on a top level directory compared to fsync() on each individual sub-directories? (Assuming fysnc() on top level directory synchronizes all sub-directory meta data)