diff --git a/common_windows.go b/common_windows.go index 5ba012e..2f981d1 100644 --- a/common_windows.go +++ b/common_windows.go @@ -9,3 +9,8 @@ import ( var ( modKernel32 = syscall.NewLazyDLL("kernel32.dll") ) + +type FILETIME struct { + DwLowDateTime uint32 + DwHighDateTime uint32 +} diff --git a/cpu_windows.go b/cpu_windows.go index 70134c7..c34a116 100644 --- a/cpu_windows.go +++ b/cpu_windows.go @@ -12,11 +12,6 @@ var ( procGetSystemTimes = modkernel32.NewProc("GetSystemTimes") ) -type FILETIME struct { - DwLowDateTime uint32 - DwHighDateTime uint32 -} - func Cpu_times() ([]CPU_TimesStat, error) { ret := make([]CPU_TimesStat, 0) diff --git a/disk_windows.go b/disk_windows.go index 67dd7b4..e7e4f31 100644 --- a/disk_windows.go +++ b/disk_windows.go @@ -20,8 +20,8 @@ var ( FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000 ) -func (d Disk) Disk_usage(path string) (Disk_usage, error) { - ret := Disk_usage{} +func Disk_usage(path string) (Disk_usageStat, error) { + ret := Disk_usageStat{} ret.Path = path lpFreeBytesAvailable := int64(0) @@ -44,8 +44,8 @@ func (d Disk) Disk_usage(path string) (Disk_usage, error) { return ret, nil } -func (d Disk) Disk_partitions() ([]Disk_partition, error) { - ret := make([]Disk_partition, 0) +func Disk_partitions() ([]Disk_partitionStat, error) { + ret := make([]Disk_partitionStat, 0) lpBuffer := make([]byte, 254) diskret, _, err := procGetLogicalDriveStringsW.Call( uintptr(len(lpBuffer)), @@ -93,7 +93,7 @@ func (d Disk) Disk_partitions() ([]Disk_partition, error) { opts += ".compress" } - d := Disk_partition{ + d := Disk_partitionStat{ Mountpoint: path, Device: path, Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), diff --git a/host_windows.go b/host_windows.go index 5c0ec64..45e0d29 100644 --- a/host_windows.go +++ b/host_windows.go @@ -6,6 +6,12 @@ import ( "github.com/mitchellh/go-ps" "os" "syscall" + "unsafe" +) + +var ( + procGetSystemTimeAsFileTime = modKernel32.NewProc("GetSystemTimeAsFileTime") + procGetTickCount = modKernel32.NewProc("GetTickCount") ) func HostInfo() (HostInfoStat, error) { @@ -37,3 +43,30 @@ func HostInfo() (HostInfoStat, error) { return ret, nil } + +func Boot_time() (int64, error) { + var lpSystemTimeAsFileTime FILETIME + + r, _, _ := procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&lpSystemTimeAsFileTime))) + if r == 0 { + return 0, syscall.GetLastError() + } + + // TODO: This calc is wrong. + ll := (uint32(lpSystemTimeAsFileTime.DwHighDateTime))<<32 + lpSystemTimeAsFileTime.DwLowDateTime + pt := (uint64(ll) - 116444736000000000) / 10000000 + + u, _, _ := procGetTickCount.Call() + if u == 0 { + return 0, syscall.GetLastError() + } + uptime := uint64(u) / 1000 + + return int64(pt - uptime), nil +} +func Users() ([]UserStat, error) { + + ret := make([]UserStat, 0) + + return ret, nil +} diff --git a/load_windows.go b/load_windows.go index fc40935..f684ef1 100644 --- a/load_windows.go +++ b/load_windows.go @@ -2,8 +2,8 @@ package gopsutil -func (l Load) LoadAvg() (LoadAvg, error) { - ret := LoadAvg{} +func LoadAvg() (LoadAvgStat, error) { + ret := LoadAvgStat{} return ret, nil } diff --git a/mem_windows.go b/mem_windows.go index de37676..6052136 100644 --- a/mem_windows.go +++ b/mem_windows.go @@ -23,8 +23,8 @@ type MEMORYSTATUSEX struct { ullAvailExtendedVirtual uint64 } -func Virtual_memory() (Virtual_memory, error) { - ret := Virtual_memory{} +func Virtual_memory() (Virtual_memoryStat, error) { + ret := Virtual_memoryStat{} var memInfo MEMORYSTATUSEX memInfo.cbSize = uint32(unsafe.Sizeof(memInfo)) @@ -40,8 +40,8 @@ func Virtual_memory() (Virtual_memory, error) { return ret, nil } -func Swap_memory() (Swap_memory, error) { - ret := Swap_memory{} +func Swap_memory() (Swap_memoryStat, error) { + ret := Swap_memoryStat{} return ret, nil }