From 1a037fddb1c230424bd212147b83df4a29ebfc06 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 27 Aug 2015 09:51:03 -0600 Subject: [PATCH] Fix disk usage stats for windows --- disk/disk_windows.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index b8de918..8656e44 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -26,10 +26,9 @@ var ( const WaitMSec = 500 -func DiskUsage(path string) (DiskUsageStat, error) { +func DiskUsage(path string) (*DiskUsageStat, error) { ret := DiskUsageStat{} - ret.Path = path lpFreeBytesAvailable := int64(0) lpTotalNumberOfBytes := int64(0) lpTotalNumberOfFreeBytes := int64(0) @@ -39,19 +38,19 @@ func DiskUsage(path string) (DiskUsageStat, error) { uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)), uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes))) if diskret == 0 { - return ret, err + return nil, err + } + ret := &DiskUsageStat{ + Path: path, + Total: uint64(lpTotalNumberOfBytes), + Free: uint64(lpTotalNumberOfFreeBytes), + // Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes) + // UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100 + // InodesTotal: 0, + // InodesFree: 0, + // InodesUsed: 0, + // InodesUsedPercent: 0, } - ret.Total = uint64(lpTotalNumberOfBytes) - // ret.Free = uint64(lpFreeBytesAvailable) // python psutil does not use this - ret.Free = uint64(lpTotalNumberOfFreeBytes) - ret.Used = ret.Total - ret.Free - ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 - - //TODO: implement inodes stat - ret.InodesTotal = 0 - ret.InodesUsed = 0 - ret.InodesFree = 0 - ret.InodesUsedPercent = 0.0 return ret, nil }