github.com/coocood/badger@v1.5.1-0.20200528065104-c02ac3616d04/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  }