Flushes buffered data written to the file to permanent storage
| 647 | |
| 648 | //! Flushes buffered data written to the file to permanent storage |
| 649 | inline int data_sync(int fd) |
| 650 | { |
| 651 | #if defined(BOOST_FILESYSTEM_HAS_FDATASYNC) && !(defined(__APPLE__) && defined(__MACH__) && defined(F_FULLFSYNC)) |
| 652 | while (true) |
| 653 | { |
| 654 | int err = ::fdatasync(fd); |
| 655 | if (BOOST_UNLIKELY(err != 0)) |
| 656 | { |
| 657 | err = errno; |
| 658 | // POSIX says fsync can return EINTR (https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html). |
| 659 | // It doesn't say so for fdatasync, but it is reasonable to expect it as well. |
| 660 | if (err == EINTR) |
| 661 | continue; |
| 662 | |
| 663 | return err; |
| 664 | } |
| 665 | |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | return 0; |
| 670 | #else |
| 671 | return full_sync(fd); |
| 672 | #endif |
| 673 | } |
| 674 | |
| 675 | //! Hints the filesystem to opportunistically preallocate storage for a file |
| 676 | inline int preallocate_storage(int file, uintmax_t size) |