Use F_FULLFSYNC on macOS with fallback to fsync for full barrier durability

This commit is contained in:
Andrea Mazzoleni 2026-09-05 09:51:38 +02:00
parent b5a8ef7c33
commit 8ed0224e41
3 changed files with 49 additions and 2 deletions

View file

@ -835,7 +835,21 @@ int ssync(STREAM* s)
unsigned i;
for (i = 0; i < s->handle_size; ++i) {
if (fsync(s->handle[i].f) != 0) {
int ret;
/*
* On macOS, standard fsync() only pushes data from kernel buffers to the
* drive's volatile cache without requesting a physical media flush. F_FULLFSYNC
* forces the drive controller to commit all cached data to permanent storage.
*/
#if defined(__APPLE__) && defined(F_FULLFSYNC)
ret = fcntl(s->handle[i].f, F_FULLFSYNC);
if (ret != 0 && (errno == ENOTSUP || errno == EINVAL))
ret = fsync(s->handle[i].f);
#else
ret = fsync(s->handle[i].f);
#endif
if (ret != 0) {
/* LCOV_EXCL_START */
s->state = STREAM_STATE_ERROR;
s->state_index = i;