|
|
|
@ -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)),
|
|
|
|
@ -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)),
|
|
|
|
@ -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)),
|
|
|
|
|
)
|
|
|
|
|