github.com/decred/dcrlnd@v0.7.6/healthcheck/diskcheck_openbsd.go (about) 1 package healthcheck 2 3 import "golang.org/x/sys/unix" 4 5 // AvailableDiskSpaceRatio returns ratio of available disk space to total 6 // capacity for openbsd. 7 func AvailableDiskSpaceRatio(path string) (float64, error) { 8 s := unix.Statfs_t{} 9 err := unix.Statfs(path, &s) 10 if err != nil { 11 return 0, err 12 } 13 14 // Calculate our free blocks/total blocks to get our total ratio of 15 // free blocks. 16 return float64(s.F_bfree) / float64(s.F_blocks), nil 17 } 18 19 // AvailableDiskSpace returns the available disk space in bytes of the given 20 // file system for openbsd. 21 func AvailableDiskSpace(path string) (uint64, error) { 22 s := unix.Statfs_t{} 23 err := unix.Statfs(path, &s) 24 if err != nil { 25 return 0, err 26 } 27 28 return uint64(s.F_bavail) * uint64(s.F_bsize), nil 29 }