1 // Copyright 2016 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build darwin 16 // +build darwin 17 18 package fileutil 19 20 import ( 21 "os" 22 23 "golang.org/x/sys/unix" 24 ) 25 26 // Fsync on HFS/OSX flushes the data on to the physical drive but the drive 27 // may not write it to the persistent media for quite sometime and it may be 28 // written in out-of-order sequence. Using F_FULLFSYNC ensures that the 29 // physical drive's buffer will also get flushed to the media. 30 func Fsync(f *os.File) error { 31 _, err := unix.FcntlInt(f.Fd(), unix.F_FULLFSYNC, 0) 32 return err 33 } 34 35 // Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence 36 // on physical drive media. 37 func Fdatasync(f *os.File) error { 38 return Fsync(f) 39 } 40