lib/file: make pre-allocate detect disk full errors and return them

This commit is contained in:
Nick Craig-Wood 2021-02-17 13:05:15 +00:00
parent 4fbb50422c
commit 40b58d59ad
3 changed files with 13 additions and 4 deletions

6
lib/file/preallocate.go Normal file
View File

@ -0,0 +1,6 @@
package file
import "errors"
// ErrDiskFull is returned from PreAllocate when it detects disk full
var ErrDiskFull = errors.New("preallocate: file too big for remaining disk space")

View File

@ -42,10 +42,10 @@ again:
goto again
}
// FIXME could be doing something here
// if err == unix.ENOSPC {
// log.Printf("No space")
// }
// Wrap important errors
if err == unix.ENOSPC {
return ErrDiskFull
}
return err
}

View File

@ -76,6 +76,9 @@ func PreAllocate(size int64, out *os.File) error {
uintptr(19), // FileAllocationInformation
)
if e1 != nil && e1 != syscall.Errno(0) {
if e1 == syscall.Errno(windows.ERROR_DISK_FULL) || e1 == syscall.Errno(windows.ERROR_HANDLE_DISK_FULL) {
return ErrDiskFull
}
return errors.Wrap(e1, "preAllocate NtSetInformationFile failed")
}