2014-04-18 15:34:47 +08:00
|
|
|
// +build freebsd linux
|
|
|
|
|
2014-04-22 08:44:22 +08:00
|
|
|
package gopsutil
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import "syscall"
|
|
|
|
|
2014-04-22 09:02:01 +08:00
|
|
|
func Disk_usage(path string) (Disk_usageStat, error) {
|
2014-04-18 15:34:47 +08:00
|
|
|
stat := syscall.Statfs_t{}
|
|
|
|
err := syscall.Statfs(path, &stat)
|
|
|
|
if err != nil {
|
2014-04-22 09:02:01 +08:00
|
|
|
return Disk_usageStat{Path: path}, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bsize := stat.Bsize / 512
|
|
|
|
|
2014-04-22 09:02:01 +08:00
|
|
|
ret := Disk_usageStat{
|
2014-04-18 15:34:47 +08:00
|
|
|
Path: path,
|
|
|
|
Total: (uint64(stat.Blocks) * uint64(bsize)) >> 1,
|
|
|
|
Free: (uint64(stat.Bfree) * uint64(bsize)) >> 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.Used = (ret.Total - ret.Free)
|
2014-04-22 08:48:19 +08:00
|
|
|
ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
2014-04-22 08:48:19 +08:00
|
|
|
|
2014-04-22 09:02:01 +08:00
|
|
|
func Disk_partitions() ([]Disk_partitionStat, error) {
|
|
|
|
ret := make([]Disk_partitionStat, 0)
|
2014-04-22 08:48:19 +08:00
|
|
|
return ret, nil
|
|
|
|
}
|