diskcheck_openbsd.go 748 B

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