Files
restic/internal/fileio/preallocate_darwin.go
T
Michael Eischer 4d1b9cef63 internal/fileio: extract low-level file I/O from internal/fs
Move TempFile and PreallocateFile into internal/fileio. internal/fs
primarily focuses on converting between data.Node and the actual
filesystem state. Extract the two methods to not pull in unnecessary
dependencies.
2026-06-20 17:48:35 +02:00

29 lines
553 B
Go

package fileio
import (
"os"
"golang.org/x/sys/unix"
)
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,
}
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
err = unix.FcntlFstore(wr.Fd(), unix.F_PREALLOCATE, &fst)
return err
}