package disk
import "syscall"
//空间使用结构体
type DiskStatus struct {
Size uint64
Used uint64
Free uint64
}
//空间使用情况
func DiskUsage(path string) (disk *DiskStatus, err error) {
fs := new(syscall.Statfs_t)
err = syscall.Statfs(path, fs) //文件基本信息
if err != nil {
return
}
disk = new(DiskStatus)
disk.Size = fs.Blocks * uint64(fs.Bsize)
disk.Free = fs.Bfree * uint64(fs.Bsize)
disk.Used = disk.Size - disk.Free
return
}