1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00

Add disk partitions support for NetBSD

This commit is contained in:
Justin Yang 2023-09-09 17:47:44 +08:00
parent 302751d509
commit 7df86f0f6a
3 changed files with 90 additions and 4 deletions

View File

@ -14,23 +14,41 @@ import (
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
var ret []PartitionStat
flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h
// get required buffer size
r, _, err = unix.Syscall6(
483, // SYS___getvfsstat90 syscall
nil,
0,
1, // ST_WAIT/MNT_WAIT, see sys/fstypes.h
uintptr(unsafe.Pointer(&flag)),
)
if err != nil {
return ret, err
}
mountedFsCount := uint64(r)
// calculate the buffer size
bufSize := sizeOfStatvfs * mountedFsCount
buf := make([]Statvfs, bufSize)
// request agian to get desired mount data
_, _, err = unix.Syscall6(
483,
uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(&bufSize)),
uintptr(unsafe.Pointer(&flag)),
)
if err != nil {
return ret, err
}
for _, stat := range buf {
d := PartitionStat{
Device: common.ByteToString(stat.F_mntfromname[:]),
Mountpoint: common.ByteToString(stat.F_mntonname[:]),
Fstype: common.ByteToString(stat.F_fstypename[:]),
Device: common.ByteToString([]byte(stat.Mntfromname[:])),
Mountpoint: common.ByteToString([]byte(stat.Mntonname[:])),
Fstype: common.ByteToString([]byte(stat.Fstypename[:])),
Opts: opts,
}

38
disk/disk_netbsd_arm64.go Normal file
View File

@ -0,0 +1,38 @@
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs types_netbsd.go
package disk
const (
sizeOfStatvfs = 0xce0
)
type (
Statvfs struct {
Flag uint64
Bsize uint64
Frsize uint64
Iosize uint64
Blocks uint64
Bfree uint64
Bavail uint64
Bresvd uint64
Files uint64
Ffree uint64
Favail uint64
Fresvd uint64
Syncreads uint64
Syncwrites uint64
Asyncreads uint64
Asyncwrites uint64
Fsidx _Ctype_struct___0
Fsid uint64
Namemax uint64
Owner uint32
Spare [4]uint64
Fstypename [32]uint8
Mntonname [1024]uint8
Mntfromname [1024]uint8
Mntfromlabel [1024]uint8
}
)

30
disk/types_netbsd.go Normal file
View File

@ -0,0 +1,30 @@
//go:build ignore
// +build ignore
// Hand writing: _Ctype_struct_statvfs
/*
Input to cgo -godefs.
*/
package disk
/*
#include <sys/types.h>
#include <sys/statvfs.h>
#include <sys/cdefs.h>
#include <sys/featuretest.h>
#include <sys/stdint.h>
#include <machine/ansi.h>
#include <sys/ansi.h>
#include <sys/fstypes.h>
*/
import "C"
const (
sizeOfStatvfs = C.sizeof_struct_statvfs
)
type (
Statvfs C.struct_statvfs
)