Rather than just using it on Linux and NetBSD, use fdatasync() based
on whether it's available. i.e it is available in newer versions
of FreeBSD (11.1 and later).This also aligns our code more closely with what is being done in leveldb.
Was pointed out by Luke in #19430.
This is a backport of core#19614