Files

23 lines
491 B
Go

//go:build !windows
package store
import (
"errors"
"math"
"syscall"
)
func filesystemFreeBytes(path string) (uint64, error) {
var status syscall.Statfs_t
if err := syscall.Statfs(path, &status); err != nil {
return 0, err
}
blockSize := uint64(status.Bsize)
availableBlocks := uint64(status.Bavail)
if blockSize != 0 && availableBlocks > math.MaxUint64/blockSize {
return 0, errors.New("filesystem free-space value overflowed")
}
return availableBlocks * blockSize, nil
}