Skip to content

Commit

Permalink
disk: fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgeek committed Sep 15, 2023
1 parent 319f5ea commit dd0253b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions disk/disk_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const (
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
var ret []PartitionStat

trap := 483 // SYS___getvfsstat90 syscall
flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h

// get required buffer size
emptyBufSize := 0
r, _, err := unix.Syscall(
uintptr(unsafe.Pointer(&trap)),
483, // SYS___getvfsstat90 syscall
uintptr(unsafe.Pointer(nil)),
uintptr(unsafe.Pointer(&emptyBufSize)),
uintptr(unsafe.Pointer(&flag)),
Expand All @@ -44,11 +43,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro

// calculate the buffer size
bufSize := sizeOfStatvfs * mountedFsCount
buf := make([]Statvfs, bufSize)
buf := make([]Statvfs, mountedFsCount)

// request agian to get desired mount data
_, _, err = unix.Syscall(
uintptr(unsafe.Pointer(&flag)),
483, // SYS___getvfsstat90 syscall
uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(&bufSize)),
uintptr(unsafe.Pointer(&flag)),
Expand Down Expand Up @@ -104,12 +103,16 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC

func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
stat := Statvfs{}
trap := 485 // SYS___fstatvfs190, see sys/syscall.h
flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h

_path, e := unix.BytePtrFromString(path)
if e != nil {
return nil, e
}

_, _, err := unix.Syscall(
uintptr(unsafe.Pointer(&trap)),
uintptr(unsafe.Pointer(&path)),
484, // SYS___fstatvfs190, see sys/syscall.h
uintptr(unsafe.Pointer(_path)),
uintptr(unsafe.Pointer(&stat)),
uintptr(unsafe.Pointer(&flag)),
)
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_netbsd_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd0253b

Please sign in to comment.