2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 16:53:59 +00:00
restic/internal/fs/preallocate_linux.go

17 lines
300 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 {
if size <= 0 {
return nil
}
// int fallocate(int fd, int mode, off_t offset, off_t len)
// use mode = 0 to also change the file size
return unix.Fallocate(int(wr.Fd()), 0, 0, size)
}