Browse Source
Merge pull request #1341 from ekozlov-search/windows_disk_stat
Discs statistics on Windows platform.
pull/1351/head
Chris Lu
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
47 additions and
1 deletions
-
weed/stats/disk_notsupported.go
-
weed/stats/disk_windows.go
|
|
@ -1,4 +1,4 @@ |
|
|
|
// +build windows openbsd netbsd plan9 solaris
|
|
|
|
// +build openbsd netbsd plan9 solaris
|
|
|
|
|
|
|
|
package stats |
|
|
|
|
|
|
|
|
|
@ -0,0 +1,46 @@ |
|
|
|
package stats |
|
|
|
|
|
|
|
import ( |
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" |
|
|
|
"golang.org/x/sys/windows" |
|
|
|
"syscall" |
|
|
|
"unsafe" |
|
|
|
) |
|
|
|
var ( |
|
|
|
kernel32 = windows.NewLazySystemDLL("Kernel32.dll") |
|
|
|
getDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW") |
|
|
|
) |
|
|
|
|
|
|
|
func fillInDiskStatus(disk *volume_server_pb.DiskStatus) { |
|
|
|
|
|
|
|
ptr, err := syscall.UTF16PtrFromString(disk.Dir) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
var _temp uint64 |
|
|
|
/* #nosec */ |
|
|
|
r, _, e := syscall.Syscall6( |
|
|
|
getDiskFreeSpaceEx.Addr(), |
|
|
|
4, |
|
|
|
uintptr(unsafe.Pointer(ptr)), |
|
|
|
uintptr(unsafe.Pointer(&disk.Free)), |
|
|
|
uintptr(unsafe.Pointer(&disk.All)), |
|
|
|
uintptr(unsafe.Pointer(&_temp)), |
|
|
|
0, |
|
|
|
0, |
|
|
|
) |
|
|
|
|
|
|
|
if r == 0 { |
|
|
|
if e != 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
disk.Used = disk.All - disk.Free |
|
|
|
disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100) |
|
|
|
disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100) |
|
|
|
|
|
|
|
return |
|
|
|
} |