Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions du/diskusage.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
//go:build !windows
// +build !windows

package du

import "syscall"
import (
"golang.org/x/sys/unix"
)

// DiskUsage contains usage data and provides user-friendly access methods
type DiskUsage struct {
stat *syscall.Statfs_t
stat *unix.Statfs_t
}

// NewDiskUsages returns an object holding the disk usage of volumePath
// or nil in case of error (invalid path, etc)
func NewDiskUsage(volumePath string) *DiskUsage {

var stat syscall.Statfs_t
syscall.Statfs(volumePath, &stat)
stat := unix.Statfs_t{}
err := unix.Statfs(volumePath, &stat)
if err != nil {
return nil
}
return &DiskUsage{&stat}
}

Expand Down
8 changes: 4 additions & 4 deletions du/diskusage_windows.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package du

import (
"syscall"
"unsafe"

"golang.org/x/sys/windows"
)

type DiskUsage struct {
Expand All @@ -14,14 +15,13 @@ type DiskUsage struct {
// NewDiskUsages returns an object holding the disk usage of volumePath
// or nil in case of error (invalid path, etc)
func NewDiskUsage(volumePath string) *DiskUsage {

h := syscall.MustLoadDLL("kernel32.dll")
h := windows.MustLoadDLL("kernel32.dll")
c := h.MustFindProc("GetDiskFreeSpaceExW")

du := &DiskUsage{}

c.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(volumePath))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(volumePath))),
uintptr(unsafe.Pointer(&du.freeBytes)),
uintptr(unsafe.Pointer(&du.totalBytes)),
uintptr(unsafe.Pointer(&du.availBytes)))
Expand Down