2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-30 13:40:36 +00:00
restic/internal/fs/preallocate_darwin.go

29 lines
549 B
Go
Raw Normal View History

2021-02-02 14:43:40 +00:00
package fs
import (
"os"
"golang.org/x/sys/unix"
)
2021-02-02 14:43:40 +00:00
func PreallocateFile(wr *os.File, size int64) error {
// try contiguous first
fst := unix.Fstore_t{
Flags: unix.F_ALLOCATECONTIG | unix.F_ALLOCATEALL,
Posmode: unix.F_PEOFPOSMODE,
Offset: 0,
Length: size,
}
2021-04-10 14:54:07 +00:00
err := unix.FcntlFstore(wr.Fd(), unix.F_PREALLOCATE, &fst)
if err == nil {
return nil
}
// just take preallocation in any form, but still ask for everything
fst.Flags = unix.F_ALLOCATEALL
2021-04-10 14:54:07 +00:00
err = unix.FcntlFstore(wr.Fd(), unix.F_PREALLOCATE, &fst)
return err
}