diskusage_posix.go 539 B

123456789101112131415161718192021222324
  1. // +build !windows,!netbsd,!openbsd,!solaris
  2. package du
  3. import (
  4. "path/filepath"
  5. "syscall"
  6. )
  7. // Get returns the Usage of a given path, or an error if usage data is
  8. // unavailable.
  9. func Get(path string) (Usage, error) {
  10. var stat syscall.Statfs_t
  11. err := syscall.Statfs(filepath.Clean(path), &stat)
  12. if err != nil {
  13. return Usage{}, err
  14. }
  15. u := Usage{
  16. FreeBytes: int64(stat.Bfree) * int64(stat.Bsize),
  17. TotalBytes: int64(stat.Blocks) * int64(stat.Bsize),
  18. AvailBytes: int64(stat.Bavail) * int64(stat.Bsize),
  19. }
  20. return u, nil
  21. }