diff --git a/bill-of-materials.json b/bill-of-materials.json index 7a233d436de..6eaa854c34c 100644 --- a/bill-of-materials.json +++ b/bill-of-materials.json @@ -369,7 +369,7 @@ ] }, { - "project": "golang.org/x/sys/unix", + "project": "golang.org/x/sys", "licenses": [ { "type": "BSD 3-clause \"New\" or \"Revised\" License", diff --git a/go.mod b/go.mod index 73a1371152b..e585a00193f 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( go.uber.org/zap v1.15.0 golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 + golang.org/x/sys v0.0.0-20200918174421-af09f7315aff golang.org/x/text v0.3.3 // indirect golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 google.golang.org/grpc v1.26.0 diff --git a/go.sum b/go.sum index bbdd94e5751..fbbfa0edea3 100644 --- a/go.sum +++ b/go.sum @@ -185,6 +185,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/pkg/fileutil/preallocate_darwin.go b/pkg/fileutil/preallocate_darwin.go index 5a6dccfa796..6e2e6e905b4 100644 --- a/pkg/fileutil/preallocate_darwin.go +++ b/pkg/fileutil/preallocate_darwin.go @@ -19,7 +19,8 @@ package fileutil import ( "os" "syscall" - "unsafe" + + "golang.org/x/sys/unix" ) func preallocExtend(f *os.File, sizeInBytes int64) error { @@ -32,18 +33,18 @@ func preallocExtend(f *os.File, sizeInBytes int64) error { func preallocFixed(f *os.File, sizeInBytes int64) error { // allocate all requested space or no space at all // TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag - fstore := &syscall.Fstore_t{ - Flags: syscall.F_ALLOCATEALL, - Posmode: syscall.F_PEOFPOSMODE, - Length: sizeInBytes} - p := unsafe.Pointer(fstore) - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p)) - if errno == 0 || errno == syscall.ENOTSUP { + fstore := &unix.Fstore_t{ + Flags: unix.F_ALLOCATEALL, + Posmode: unix.F_PEOFPOSMODE, + Length: sizeInBytes, + } + err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore) + if err == nil || err == unix.ENOTSUP { return nil } // wrong argument to fallocate syscall - if errno == syscall.EINVAL { + if err == unix.EINVAL { // filesystem "st_blocks" are allocated in the units of // "Allocation Block Size" (run "diskutil info /" command) var stat syscall.Stat_t @@ -61,5 +62,5 @@ func preallocFixed(f *os.File, sizeInBytes int64) error { return nil } } - return errno + return err } diff --git a/pkg/fileutil/sync_darwin.go b/pkg/fileutil/sync_darwin.go index c2f39bf204d..5d62fae8cd7 100644 --- a/pkg/fileutil/sync_darwin.go +++ b/pkg/fileutil/sync_darwin.go @@ -18,7 +18,8 @@ package fileutil import ( "os" - "syscall" + + "golang.org/x/sys/unix" ) // Fsync on HFS/OSX flushes the data on to the physical drive but the drive @@ -26,11 +27,8 @@ import ( // written in out-of-order sequence. Using F_FULLFSYNC ensures that the // physical drive's buffer will also get flushed to the media. func Fsync(f *os.File) error { - _, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0)) - if errno == 0 { - return nil - } - return errno + _, err := unix.FcntlInt(f.Fd(), unix.F_FULLFSYNC, 0) + return err } // Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence