|
|
@@ -21,8 +21,22 @@ import (
|
|
|
"syscall"
|
|
|
)
|
|
|
|
|
|
+// Preallocate tries to allocate the space for given
|
|
|
+// file. This operation is only supported on linux by a
|
|
|
+// few filesystems (btrfs, ext4, etc.).
|
|
|
+// If the operation is unsupported, no error will be returned.
|
|
|
+// Otherwise, the error encountered will be returned.
|
|
|
func Preallocate(f *os.File, sizeInBytes int) error {
|
|
|
// use mode = 1 to keep size
|
|
|
// see FALLOC_FL_KEEP_SIZE
|
|
|
- return syscall.Fallocate(int(f.Fd()), 1, 0, int64(sizeInBytes))
|
|
|
+ err := syscall.Fallocate(int(f.Fd()), 1, 0, int64(sizeInBytes))
|
|
|
+ if err != nil {
|
|
|
+ errno, ok := err.(syscall.Errno)
|
|
|
+ // treat not support as nil error
|
|
|
+ if ok && errno == syscall.ENOTSUP {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|