mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
599 B
Go
28 lines
599 B
Go
11 years ago
|
// +build freebsd linux
|
||
|
|
||
|
package main
|
||
|
|
||
|
import "syscall"
|
||
|
|
||
|
func (d Disk) Disk_usage(path string) (Disk_usage, error) {
|
||
|
stat := syscall.Statfs_t{}
|
||
|
err := syscall.Statfs(path, &stat)
|
||
|
if err != nil {
|
||
|
return Disk_usage{Path: path}, err
|
||
|
}
|
||
|
|
||
|
bsize := stat.Bsize / 512
|
||
|
|
||
|
ret := Disk_usage{
|
||
|
Path: path,
|
||
|
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
|
||
|
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
|
||
|
Available: (uint64(stat.Bavail) * uint64(bsize)) >> 1,
|
||
|
}
|
||
|
|
||
|
ret.Used = (ret.Total - ret.Free)
|
||
|
ret.Percent = (float64(ret.Used) / float64(ret.Total)) * 100.0
|
||
|
|
||
|
return ret, nil
|
||
|
}
|