3 ms·
For Linux, but it's not portable across all Unixes. fsync is allowed to do nothing (1) and does not need to work on directories (2). On Mac OSX, fsync will not
by kr7 10y ago
For Linux, but it's not portable across all Unixes. fsync is allowed to do nothing (1) and does not need to work on directories (2). On Mac OSX, fsync will not flush the disk cache, which can lead to data loss (3).
(1) http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/fs...
(2) http://austingroupbugs.net/view.php?id=672 http://austingroupbugs.net/view.php?id=672
(3) https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fsync.2.html https://developer.apple.com/library/mac/documentation/Darwin...
- valleyer 10y agofsync(2) on OS X and other Darwins also does not sync metadata. You need to use fcntl(2) with F_FULLFSYNC for that.
- ryao 10y agoIt looks like doing `sysctl -w kern.always_do_fullfsync=1` Will produce a sane behavior: https://opensource.apple.com/source/xnu/xnu-2422.1.72/bsd/hfs/hfs_vnops.c https://opensource.apple.com/source/xnu/xnu-2422.1.72/bsd/hf... Alternatively, you could just use the ZFS driver for Mac OS X. It will do fsync properly.