O_DSYNC
O_DSYNC is an open-file status flag requiring write operations to complete with synchronized I/O data integrity, covering data and the metadata needed to retrieve it.
A file-length extension is retrieval-critical; a timestamp-only update is not. Linux compares O_DSYNC write completion to a write followed by fdatasync, not to a metadata-free write. [1] Handle a short write using its returned byte count; the flag does not promise that one call transfers the entire requested application record. [2] Like fdatasync, it is not a replacement for the containing directory's synchronization when name persistence matters. [3]
Configuration: Linux F_SETFL leaves O_SYNC and O_DSYNC unchanged, even when fcntl returns success. Choose the required mode when opening the file, then inspect it with F_GETFL. The Linux v6.12 setfl implementation preserves these bits outside its mutable-flag mask. [5] [6]
Per-write option: pwritev2 RWF_SYNC and RWF_DSYNC request the corresponding synchronized completion for the written range, without changing the descriptor's mode. Check returned bytes and errors; neither flag supplies failure atomicity. [8]
Relations
- related
- O_SYNC, fdatasync, fsync, Directory fsync, Direct I/O, Short write, RWF_ATOMIC, Open file description, RWF_DSYNC, O_RSYNC
Advantages
- Can avoid synchronization of metadata not required for data retrieval.
Limitations
- Does not guarantee lower latency than O_SYNC on every filesystem.
- Does not provide crash-atomic writes or a multi-file transaction.
- Does not imply direct I/O or page-cache bypass.
Citations
- Linux man-pages 6.19: open(2), O_SYNC and O_DSYNC
- POSIX.1-2024: write(), synchronized I/O and partial writes
- Linux man-pages 6.19: fsync(2), metadata and directory synchronization
- Linux man-pages 6.19: F_GETFL and F_SETFL, unchanged synchronization flags
- Linux v6.12: fs/fcntl.c, SETFL_MASK and setfl()
- Linux man-pages 6.19: pwritev2(), per-write synchronization flags