|
|
|
@ -15,6 +15,7 @@
|
|
|
|
|
package fileutil |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"errors" |
|
|
|
|
"os" |
|
|
|
|
"syscall" |
|
|
|
|
) |
|
|
|
@ -23,10 +24,10 @@ func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|
|
|
|
// use mode = 0 to change size
|
|
|
|
|
err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes) |
|
|
|
|
if err != nil { |
|
|
|
|
errno, ok := err.(syscall.Errno) |
|
|
|
|
var errno syscall.Errno |
|
|
|
|
// not supported; fallback
|
|
|
|
|
// fallocate EINTRs frequently in some environments; fallback
|
|
|
|
|
if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { |
|
|
|
|
if errors.As(err, &errno) && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { |
|
|
|
|
return preallocExtendTrunc(f, sizeInBytes) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -37,9 +38,9 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|
|
|
|
// use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE
|
|
|
|
|
err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes) |
|
|
|
|
if err != nil { |
|
|
|
|
errno, ok := err.(syscall.Errno) |
|
|
|
|
var errno syscall.Errno |
|
|
|
|
// treat not supported as nil error
|
|
|
|
|
if ok && errno == syscall.ENOTSUP { |
|
|
|
|
if errors.As(err, &errno) && errno == syscall.ENOTSUP { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|