Ensures that all the caches associated with the given file descriptor's data are flushed all the way to durable media, and can withstand power failures. The path argument is only used to populate the description string in the returned Status if an error occurs.
| 373 | // The path argument is only used to populate the description string in the |
| 374 | // returned Status if an error occurs. |
| 375 | static Status SyncFd(int fd, const std::string& fd_path, bool syncing_dir) { |
| 376 | #if HAVE_FULLFSYNC |
| 377 | // On macOS and iOS, fsync() doesn't guarantee durability past power |
| 378 | // failures. fcntl(F_FULLFSYNC) is required for that purpose. Some |
| 379 | // filesystems don't support fcntl(F_FULLFSYNC), and require a fallback to |
| 380 | // fsync(). |
| 381 | if (::fcntl(fd, F_FULLFSYNC) == 0) { |
| 382 | return Status::OK(); |
| 383 | } |
| 384 | #endif // HAVE_FULLFSYNC |
| 385 | |
| 386 | #if HAVE_FDATASYNC |
| 387 | bool sync_success = ::fdatasync(fd) == 0; |
| 388 | #else |
| 389 | bool sync_success = ::fsync(fd) == 0; |
| 390 | #endif // HAVE_FDATASYNC |
| 391 | |
| 392 | if (sync_success) { |
| 393 | return Status::OK(); |
| 394 | } |
| 395 | // Do not crash if filesystem can't fsync directories |
| 396 | // (see https://github.com/bitcoin/bitcoin/pull/10000) |
| 397 | if (syncing_dir && errno == EINVAL) { |
| 398 | return Status::OK(); |
| 399 | } |
| 400 | return PosixError(fd_path, errno); |
| 401 | } |
| 402 | |
| 403 | // Returns the directory name in a path pointing to a file. |
| 404 | // |
nothing calls this directly
no test coverage detected