From 23531be27262f6065cdb46fa4c346b11a8b85a98 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Sat, 10 Apr 2021 16:54:07 +0200 Subject: [PATCH] Use FcntlFstore to preallocate on Mac --- internal/restorer/preallocate_darwin.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/restorer/preallocate_darwin.go b/internal/restorer/preallocate_darwin.go index 73de322dd..ae6e5ee3e 100644 --- a/internal/restorer/preallocate_darwin.go +++ b/internal/restorer/preallocate_darwin.go @@ -2,8 +2,6 @@ package restorer import ( "os" - "runtime" - "unsafe" "golang.org/x/sys/unix" ) @@ -16,7 +14,7 @@ func preallocateFile(wr *os.File, size int64) error { Offset: 0, Length: size, } - _, err := unix.FcntlInt(wr.Fd(), unix.F_PREALLOCATE, int(uintptr(unsafe.Pointer(&fst)))) + err := unix.FcntlFstore(wr.Fd(), unix.F_PREALLOCATE, &fst) if err == nil { return nil @@ -24,10 +22,7 @@ func preallocateFile(wr *os.File, size int64) error { // just take preallocation in any form, but still ask for everything fst.Flags = unix.F_ALLOCATEALL - _, err = unix.FcntlInt(wr.Fd(), unix.F_PREALLOCATE, int(uintptr(unsafe.Pointer(&fst)))) - - // Keep struct alive until fcntl has returned - runtime.KeepAlive(fst) + err = unix.FcntlFstore(wr.Fd(), unix.F_PREALLOCATE, &fst) return err }