sigar_unix.go 570 B

123456789101112131415161718192021222324252627
  1. // Copyright (c) 2012 VMware, Inc.
  2. // +build darwin freebsd linux netbsd openbsd
  3. package sigar
  4. import "syscall"
  5. func (self *FileSystemUsage) Get(path string) error {
  6. stat := syscall.Statfs_t{}
  7. err := syscall.Statfs(path, &stat)
  8. if err != nil {
  9. return err
  10. }
  11. bsize := stat.Bsize / 512
  12. self.Total = (uint64(stat.Blocks) * uint64(bsize)) >> 1
  13. self.Free = (uint64(stat.Bfree) * uint64(bsize)) >> 1
  14. self.Avail = (uint64(stat.Bavail) * uint64(bsize)) >> 1
  15. self.Used = self.Total - self.Free
  16. self.Files = stat.Files
  17. self.FreeFiles = stat.Ffree
  18. return nil
  19. }