Specifically, can fdatasync
be used in place of fsync
if I only care about the directory structure and not timestamps or other directory metadata. If it can, does it have any performance advantages?
Does POSIX define this? What do common operating systems, e.g. Linux and FreeBSD, do?
Think of it from the point of view of the VFS API, it's generally implemented as: sync content + optionally metadata. In a directory it means: sync some of children metadata + optionally it's own metadata.
However, ultimately, how to handle it, is up to the file system.
If the attributes metadata is partially decoupled like on unix filesystems, then it's probably not flushed, but on other filesystems it may be stored together, like FAT16 that stores: filename, attributes, timestamps, cluster#
From the point of view of on-disk data structures, in UNIX-like filesystems, e.g. ext4, the entries contain: inode#, entry length, type, and filename. Then it's the inode that actually stores the attributes like permissions, timestamps, etc.
BTRFS, although a lot more convoluted, still is within the tradition of unix filesystems and stores: inode key, name, and type, while the inode item stores permissions, timestamps, etc.
In this tradition also are:
Alternative implementations:
But even with unix filesystems which metadata gets flushed depends heavily on the implementation and only to a lesser extent in the underlying on-disk format considerations.