github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/check/free_space.go (about) 1 package check 2 3 import ( 4 "fmt" 5 "syscall" 6 ) 7 8 // FreeSpaceCheck checks the available disk space on a path 9 type FreeSpaceCheck struct { 10 MinimumBytes uint64 11 Path string 12 } 13 14 // Check returns true if the path has enough free space. Otherwise return false. 15 func (c FreeSpaceCheck) Check() (bool, error) { 16 var stat syscall.Statfs_t 17 if err := syscall.Statfs(c.Path, &stat); err != nil { 18 return false, fmt.Errorf("failed to check free space at path %s: %v", c.Path, err) 19 } 20 // Available blocks * size per block = available space in bytes 21 availableBytes := stat.Bavail * uint64(stat.Bsize) 22 return availableBytes >= c.MinimumBytes, nil 23 }