volume_create_linux.go 526 B

12345678910111213141516171819202122
  1. // +build linux
  2. package backend
  3. import (
  4. "os"
  5. "syscall"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. )
  8. func CreateVolumeFile(fileName string, preallocate int64, memoryMapSizeMB uint32) (BackendStorageFile, error) {
  9. file, e := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
  10. if e != nil {
  11. return nil, e
  12. }
  13. if preallocate != 0 {
  14. syscall.Fallocate(int(file.Fd()), 1, 0, preallocate)
  15. glog.V(1).Infof("Preallocated %d bytes disk space for %s", preallocate, fileName)
  16. }
  17. return NewDiskFile(file), nil
  18. }