0

What is the meaning of the following statement from the fsync man page

Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed.

Does it mean that fsync won't update the directory metadata when I call fsync on a file?

Another quote for the same problem is(from Robert Love's Book of Linux System Programming):

Neither function guarantees that any updated directory entries containing the file are synchronized to disk. This implies that if a file’s link has recently been updated, the file’s data may successfully reach the disk but not the associated directory entry, rendering the file unreachable.

Why would a file's data need to reach a directory link ? Correct me if I am wrong but the directories only contain the filename and the inode number for that file. The actual data is in the file. What is the meaning of "the data will reach the file but not the directory link"

1

It means:

if a file’s link has recently been updated

the file’s data may successfully reach the disk but

the associated directory entry may not successfully reach the disk

rendering the file unreachable.

Specifically, this could be a concern when creating a new file. I would ignore the generalization to "a files link" unless you know hard links are being created.

Does it mean that fsync won't update the directory metadata when I call fsync on a file?

Yes. Or rather, you can't rely on it. (It's possible some implementations would always update it before fsync returns.)

  • what metadata does the directory other than the name of the file and the inode number? Also does this question of not relying on fync only applicable when creating a file? – ng.newbie Jan 4 '18 at 12:33
  • @ng.newbie it could apply e.g. if you created a second hard-link to a file, and then removed the first hard link. The significant, required metadata is the file name and the inode. I suspect there's nothing mutable in there (apart from the name), because of the possibility of multiple hardlinks. However I believe some filesystems cache more information in there. Specifically, whether the directory entry refers to a directory or a regular file etc. See getdents(). This might allow more efficient implementation of find, for example. – sourcejedi Jan 4 '18 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.