github.com/pingcap/badger@v1.5.1-0.20230103063557-828f39b09b6d/fileutil/preallocate_linux.go (about) 1 // +build linux 2 3 package fileutil 4 5 import ( 6 "os" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 func preallocate(f *os.File, size int64) error { 12 err := unix.Fallocate(int(f.Fd()), 0, 0, size) 13 if err != nil { 14 errno, ok := err.(unix.Errno) 15 if ok && (errno == unix.ENOTSUP || errno == unix.EINTR) { 16 return preallocateTrunc(f, size) 17 } 18 } 19 return err 20 }