Skip to content

Commit dd0253b

Browse files
committed
disk: fix various bugs
1 parent 319f5ea commit dd0253b

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

disk/disk_netbsd.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ const (
2626
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
2727
var ret []PartitionStat
2828

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

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

4544
// calculate the buffer size
4645
bufSize := sizeOfStatvfs * mountedFsCount
47-
buf := make([]Statvfs, bufSize)
46+
buf := make([]Statvfs, mountedFsCount)
4847

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

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

108+
_path, e := unix.BytePtrFromString(path)
109+
if e != nil {
110+
return nil, e
111+
}
112+
110113
_, _, err := unix.Syscall(
111-
uintptr(unsafe.Pointer(&trap)),
112-
uintptr(unsafe.Pointer(&path)),
114+
484, // SYS___fstatvfs190, see sys/syscall.h
115+
uintptr(unsafe.Pointer(_path)),
113116
uintptr(unsafe.Pointer(&stat)),
114117
uintptr(unsafe.Pointer(&flag)),
115118
)

disk/disk_netbsd_arm64.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)