From 2684012ab2a4a1469958bcd26e23a1cfc759d395 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 27 Aug 2023 22:48:51 +0800 Subject: [PATCH 01/18] Initial support for NetBSD. Currently the changes are all copied from shirou/gopsutil#1364 --- cpu/cpu_netbsd.go | 127 ++++++++++++++++++++++++++++++++++++++++ cpu/cpu_netbsd_arm64.go | 10 ++++ 2 files changed, 137 insertions(+) create mode 100644 cpu/cpu_netbsd.go create mode 100644 cpu/cpu_netbsd_arm64.go diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go new file mode 100644 index 000000000..a728f67a6 --- /dev/null +++ b/cpu/cpu_netbsd.go @@ -0,0 +1,127 @@ +//go:build openbsd +// +build openbsd + +package cpu + +import ( + "context" + "fmt" + "runtime" + "unsafe" + + "github.com/shirou/gopsutil/v3/internal/common" + "github.com/tklauser/go-sysconf" + "golang.org/x/sys/unix" +) + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Intr uint64 + Idle uint64 +} + +const ( + // sys/sysctl.h + ctlKern = 1 // "high kernel": proc, limits + ctlHw = 6 // CTL_HW + kernCpTime = 51 // KERN_CPTIME +) + +var ClocksPerSec = float64(100) + +func init() { + clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) + // ignore errors + if err == nil { + ClocksPerSec = float64(clkTck) + } +} + +func Times(percpu bool) ([]TimesStat, error) { + return TimesWithContext(context.Background(), percpu) +} + +func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err error) { + if !percpu { + mib := []int32{ctlKern, kernCpTime} + buf, _, err := common.CallSyscall(mib) + if err != nil { + return ret, err + } + times := (*cpuTimes)(unsafe.Pointer(&buf[0])) + stat := TimesStat{ + CPU: "cpu-total", + User: float64(times.User), + Nice: float64(times.Nice), + System: float64(times.Sys), + Idle: float64(times.Idle), + Irq: float64(times.Intr), + } + return []TimesStat{stat}, nil + } + + ncpu, err := unix.SysctlUint32("hw.ncpu") + if err != nil { + return + } + + var i uint32 + for i = 0; i < ncpu; i++ { + mib := []int32{ctlKern, kernCpTime, int32(i)} + buf, _, err := common.CallSyscall(mib) + if err != nil { + return ret, err + } + + stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) + ret = append(ret, TimesStat{ + CPU: fmt.Sprintf("cpu%d", i), + User: float64(stats.User), + Nice: float64(stats.Nice), + System: float64(stats.Sys), + Idle: float64(stats.Idle), + Irq: float64(stats.Intr), + }) + } + + return ret, nil +} + +// Returns only one (minimal) CPUInfoStat on OpenBSD +func Info() ([]InfoStat, error) { + return InfoWithContext(context.Background()) +} + +func InfoWithContext(ctx context.Context) ([]InfoStat, error) { + var ret []InfoStat + var err error + + c := InfoStat{} + + mhz, err := unix.Sysctl("machdep.dmi.processor-frequency") + if err != nil { + return nil, err + } + _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) + if err != nil { + return nil, err + } + + ncpu, err := unix.SysctlUint32("hw.ncpuonline") + if err != nil { + return nil, err + } + c.Cores = int32(ncpu) + + if c.ModelName, err = unix.Sysctl("machdep.dmi.processor-version"); err != nil { + return nil, err + } + + return append(ret, c), nil +} + +func CountsWithContext(ctx context.Context, logical bool) (int, error) { + return runtime.NumCPU(), nil +} diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go new file mode 100644 index 000000000..d659058cd --- /dev/null +++ b/cpu/cpu_netbsd_arm64.go @@ -0,0 +1,10 @@ +package cpu + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Spin uint64 + Intr uint64 + Idle uint64 +} From 4e662561c23819a33267e85a64940ed9c3e3b47e Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 2 Sep 2023 22:57:30 +0800 Subject: [PATCH 02/18] mem: Add support for NetBSD --- mem/mem_netbsd.go | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 mem/mem_netbsd.go diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go new file mode 100644 index 000000000..fb6fafecf --- /dev/null +++ b/mem/mem_netbsd.go @@ -0,0 +1,87 @@ +//go:build netbsd +// +build netbsd + +package mem + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func GetPageSize() (uint64, error) { + return GetPageSizeWithContext(context.Background()) +} + +func GetPageSizeWithContext(ctx context.Context) (uint64, error) { + uvmexp, err := unix.SysctlUvmexp("vm.uvmexp2") + if err != nil { + return 0, err + } + return uint64(uvmexp.Pagesize), nil +} + +func VirtualMemory() (*VirtualMemoryStat, error) { + return VirtualMemoryWithContext(context.Background()) +} + +func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { + uvmexp, err := unix.SysctlUvmexp("vm.uvmexp2") + if err != nil { + return nil, err + } + p := uint64(uvmexp.Pagesize) + + ret := &VirtualMemoryStat{ + Total: uint64(uvmexp.Npages) * p, + Free: uint64(uvmexp.Free) * p, + Active: uint64(uvmexp.Active) * p, + Inactive: uint64(uvmexp.Inactive) * p, + Cached: 0, // not available + Wired: uint64(uvmexp.Wired) * p, + } + + ret.Available = ret.Inactive + ret.Cached + ret.Free + ret.Used = ret.Total - ret.Available + ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 + + // Get buffers from vm.bufmem sysctl + ret.Buffers = unix.SysctlUint64("vm.bufmem") + + return ret, nil +} + +// Return swapctl summary info +func SwapMemory() (*SwapMemoryStat, error) { + return SwapMemoryWithContext(context.Background()) +} + +func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { + out, err := invoke.CommandWithContext(ctx, "swapctl", "-sk") + if err != nil { + return &SwapMemoryStat{}, nil + } + + line := string(out) + var total, used, free uint64 + + _, err = fmt.Sscanf(line, + "total: %d 1K-blocks allocated, %d used, %d available", + &total, &used, &free) + if err != nil { + return nil, errors.New("failed to parse swapctl output") + } + + percent := float64(used) / float64(total) * 100 + return &SwapMemoryStat{ + Total: total * 1024, + Used: used * 1024, + Free: free * 1024, + UsedPercent: percent, + }, nil +} From 6a4ec32f3b549c7d2ead06b627b035dea1268968 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 2 Sep 2023 23:01:23 +0800 Subject: [PATCH 03/18] cpu: remove wrong info copied from openbsd --- cpu/cpu_netbsd.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index a728f67a6..facc4237a 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -1,5 +1,5 @@ -//go:build openbsd -// +build openbsd +//go:build netbsd +// +build netbsd package cpu @@ -89,7 +89,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er return ret, nil } -// Returns only one (minimal) CPUInfoStat on OpenBSD +// Returns only one (minimal) CPUInfoStat on NetBSD func Info() ([]InfoStat, error) { return InfoWithContext(context.Background()) } From 302751d509e23cd4c8bdca1de9c58e407af6b11f Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 3 Sep 2023 23:08:54 +0800 Subject: [PATCH 04/18] disk: start porting to NetBSD, far from complete --- disk/disk_netbsd.go | 130 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 disk/disk_netbsd.go diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go new file mode 100644 index 000000000..6f1ba3ff5 --- /dev/null +++ b/disk/disk_netbsd.go @@ -0,0 +1,130 @@ +//go:build openbsd +// +build openbsd + +package disk + +import ( + "bytes" + "context" + "encoding/binary" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { + var ret []PartitionStat + + // get required buffer size + r, _, err = unix.Syscall6( + 483, // SYS___getvfsstat90 syscall + nil, + 0, + 1, // ST_WAIT/MNT_WAIT, see sys/fstypes.h + ) + if err != nil { + return ret, err + } + mountedFsCount := uint64(r) + + d := PartitionStat{ + Device: common.ByteToString(stat.F_mntfromname[:]), + Mountpoint: common.ByteToString(stat.F_mntonname[:]), + Fstype: common.ByteToString(stat.F_fstypename[:]), + Opts: opts, + } + + ret = append(ret, d) + } + + return ret, nil +} + +func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { + ret := make(map[string]IOCountersStat) + + r, err := unix.SysctlRaw("hw.diskstats") + if err != nil { + return nil, err + } + buf := []byte(r) + length := len(buf) + + count := int(uint64(length) / uint64(sizeOfDiskstats)) + + // parse buf to Diskstats + for i := 0; i < count; i++ { + b := buf[i*sizeOfDiskstats : i*sizeOfDiskstats+sizeOfDiskstats] + d, err := parseDiskstats(b) + if err != nil { + continue + } + name := common.IntToString(d.Name[:]) + + if len(names) > 0 && !common.StringsHas(names, name) { + continue + } + + ds := IOCountersStat{ + ReadCount: d.Rxfer, + WriteCount: d.Wxfer, + ReadBytes: d.Rbytes, + WriteBytes: d.Wbytes, + Name: name, + } + ret[name] = ds + } + + return ret, nil +} + +// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) + +func parseDiskstats(buf []byte) (Diskstats, error) { + var ds Diskstats + br := bytes.NewReader(buf) + // err := binary.Read(br, binary.LittleEndian, &ds) + err := common.Read(br, binary.LittleEndian, &ds) + if err != nil { + return ds, err + } + + return ds, nil +} + +func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { + stat := unix.Statfs_t{} + err := unix.Statfs(path, &stat) + if err != nil { + return nil, err + } + bsize := stat.F_bsize + + ret := &UsageStat{ + Path: path, + Fstype: getFsType(stat), + Total: (uint64(stat.F_blocks) * uint64(bsize)), + Free: (uint64(stat.F_bavail) * uint64(bsize)), + InodesTotal: (uint64(stat.F_files)), + InodesFree: (uint64(stat.F_ffree)), + } + + ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) + ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 + ret.Used = (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(bsize) + ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + + return ret, nil +} + +func getFsType(stat unix.Statfs_t) string { + return common.ByteToString(stat.F_fstypename[:]) +} + +func SerialNumberWithContext(ctx context.Context, name string) (string, error) { + return "", common.ErrNotImplementedError +} + +func LabelWithContext(ctx context.Context, name string) (string, error) { + return "", common.ErrNotImplementedError +} From 7df86f0f6aef333f3b875c64f280e56b88cec950 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 17:47:44 +0800 Subject: [PATCH 05/18] Add disk partitions support for NetBSD --- disk/disk_netbsd.go | 26 ++++++++++++++++++++++---- disk/disk_netbsd_arm64.go | 38 ++++++++++++++++++++++++++++++++++++++ disk/types_netbsd.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 disk/disk_netbsd_arm64.go create mode 100644 disk/types_netbsd.go diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 6f1ba3ff5..062d77399 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -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, } diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go new file mode 100644 index 000000000..9d364d4f2 --- /dev/null +++ b/disk/disk_netbsd_arm64.go @@ -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 + } +) diff --git a/disk/types_netbsd.go b/disk/types_netbsd.go new file mode 100644 index 000000000..25217a08b --- /dev/null +++ b/disk/types_netbsd.go @@ -0,0 +1,30 @@ +//go:build ignore +// +build ignore + +// Hand writing: _Ctype_struct_statvfs + +/* +Input to cgo -godefs. +*/ + +package disk + +/* +#include +#include +#include +#include +#include +#include +#include +#include +*/ +import "C" + +const ( + sizeOfStatvfs = C.sizeof_struct_statvfs +) + +type ( + Statvfs C.struct_statvfs +) From b6a10e04e7a1c2d09252d1f96c6f020ddf0dad72 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 20:32:59 +0800 Subject: [PATCH 06/18] disk: Implement Usage for NetBSD --- disk/disk_netbsd.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 062d77399..32f4319d1 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -111,32 +111,40 @@ func parseDiskstats(buf []byte) (Diskstats, error) { } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { - stat := unix.Statfs_t{} - err := unix.Statfs(path, &stat) - if err != nil { - return nil, err - } - bsize := stat.F_bsize + stat := Statvfs{} + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + + // request agian to get desired mount data + ret, _, err = unix.Syscall6( + 485, // SYS___fstatvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(&path)), + uintptr(unsafe.Pointer(&stat)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != nil { + return ret, err + } + bsize := stat.Bsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), - Total: (uint64(stat.F_blocks) * uint64(bsize)), - Free: (uint64(stat.F_bavail) * uint64(bsize)), - InodesTotal: (uint64(stat.F_files)), - InodesFree: (uint64(stat.F_ffree)), + Total: (uint64(stat.Blocks) * uint64(bsize)), + Free: (uint64(stat.Bavail) * uint64(bsize)), + InodesTotal: (uint64(stat.Files)), + InodesFree: (uint64(stat.Ffree)), } ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 - ret.Used = (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(bsize) + ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize) ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 return ret, nil } -func getFsType(stat unix.Statfs_t) string { - return common.ByteToString(stat.F_fstypename[:]) +func getFsType(stat Statvfs) string { + return common.ByteToString(stat.Fstypename[:]) } func SerialNumberWithContext(ctx context.Context, name string) (string, error) { From e82d2e4ca8868c2f3db2a7b61945a0f796167089 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 21:25:51 +0800 Subject: [PATCH 07/18] host: enable uptime for NetBSD --- host/host_bsd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/host_bsd.go b/host/host_bsd.go index 4dc2bba58..67ae900bc 100644 --- a/host/host_bsd.go +++ b/host/host_bsd.go @@ -1,5 +1,5 @@ -//go:build darwin || freebsd || openbsd -// +build darwin freebsd openbsd +//go:build darwin || freebsd || openbsd || netbsd +// +build darwin freebsd openbsd netbsd package host From 6100e33de2789668fac4d9290cdd13f52ea2673c Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 02:31:10 +0800 Subject: [PATCH 08/18] mem: code cleanup --- mem/mem_fallback.go | 4 ++-- mem/mem_netbsd.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mem/mem_fallback.go b/mem/mem_fallback.go index 0b6c528f2..697fd8709 100644 --- a/mem/mem_fallback.go +++ b/mem/mem_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !plan9 && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!plan9,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !plan9 && !aix && !netbsd +// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!plan9,!aix,!netbsd package mem diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go index fb6fafecf..6e2be3fa1 100644 --- a/mem/mem_netbsd.go +++ b/mem/mem_netbsd.go @@ -4,13 +4,10 @@ package mem import ( - "bytes" "context" - "encoding/binary" "errors" "fmt" - "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) @@ -51,7 +48,10 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 // Get buffers from vm.bufmem sysctl - ret.Buffers = unix.SysctlUint64("vm.bufmem") + ret.Buffers, err = unix.SysctlUint64("vm.bufmem") + if err != nil { + return nil, err + } return ret, nil } From caafa49ed19251151a646a94ade123c34d37844f Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 02:40:14 +0800 Subject: [PATCH 09/18] disk: code cleanup --- disk/disk_netbsd.go | 49 +-------------------------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 32f4319d1..2f9a39a11 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -60,54 +60,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { ret := make(map[string]IOCountersStat) - - r, err := unix.SysctlRaw("hw.diskstats") - if err != nil { - return nil, err - } - buf := []byte(r) - length := len(buf) - - count := int(uint64(length) / uint64(sizeOfDiskstats)) - - // parse buf to Diskstats - for i := 0; i < count; i++ { - b := buf[i*sizeOfDiskstats : i*sizeOfDiskstats+sizeOfDiskstats] - d, err := parseDiskstats(b) - if err != nil { - continue - } - name := common.IntToString(d.Name[:]) - - if len(names) > 0 && !common.StringsHas(names, name) { - continue - } - - ds := IOCountersStat{ - ReadCount: d.Rxfer, - WriteCount: d.Wxfer, - ReadBytes: d.Rbytes, - WriteBytes: d.Wbytes, - Name: name, - } - ret[name] = ds - } - - return ret, nil -} - -// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) - -func parseDiskstats(buf []byte) (Diskstats, error) { - var ds Diskstats - br := bytes.NewReader(buf) - // err := binary.Read(br, binary.LittleEndian, &ds) - err := common.Read(br, binary.LittleEndian, &ds) - if err != nil { - return ds, err - } - - return ds, nil + return ret, common.ErrNotImplementedError } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { From ec817bfa68866cbd5d6f8e70cc9a2761c2e16b09 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 23:33:42 +0800 Subject: [PATCH 10/18] disk: code cleanup (not finish yet) --- disk/disk_fallback.go | 4 +-- disk/disk_netbsd.go | 59 ++++++++++++++++++++++++++++++++------- disk/disk_netbsd_arm64.go | 7 +++++ disk/types_netbsd.go | 4 +-- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/disk/disk_fallback.go b/disk/disk_fallback.go index 476873340..36525f694 100644 --- a/disk/disk_fallback.go +++ b/disk/disk_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !windows && !solaris && !aix +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!windows,!solaris,!aix package disk diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 2f9a39a11..94ff76eb8 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -1,5 +1,5 @@ -//go:build openbsd -// +build openbsd +//go:build netbsd +// +build netbsd package disk @@ -7,24 +7,37 @@ import ( "bytes" "context" "encoding/binary" + "unsafe" "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) +const ( + // see sys/fstypes.h and `man 5 statvfs` + MNT_RDONLY = 0x00000001 /* read only filesystem */ + MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ + MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ + MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ + MNT_NODEV = 0x00000010 /* don't interpret special files */ + MNT_ASYNC = 0x00000040 /* file system written asynchronously */ + MNT_NOATIME = 0x04000000 /* Never update access times in fs */ + MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ +) + 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( + r, _, err := unix.Syscall( 483, // SYS___getvfsstat90 syscall - nil, 0, - uintptr(unsafe.Pointer(&flag)), + 0, + uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } mountedFsCount := uint64(r) @@ -34,17 +47,43 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro buf := make([]Statvfs, bufSize) // request agian to get desired mount data - _, _, err = unix.Syscall6( + _, _, err = unix.Syscall( 483, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } for _, stat := range buf { + opts := []string{"rw"} + if stat.Flag&MNT_RDONLY != 0 { + opts = []string{"rw"} + } + if stat.Flag&MNT_SYNCHRONOUS != 0 { + opts = append(opts, "sync") + } + if stat.Flag&MNT_NOEXEC != 0 { + opts = append(opts, "noexec") + } + if stat.Flag&MNT_NOSUID != 0 { + opts = append(opts, "nosuid") + } + if stat.Flag&MNT_NODEV != 0 { + opts = append(opts, "nodev") + } + if stat.Flag&MNT_ASYNC != 0 { + opts = append(opts, "async") + } + if stat.Flag&MNT_SOFTDEP != 0 { + opts = append(opts, "softdep") + } + if stat.Flag&MNT_NOATIME != 0 { + opts = append(opts, "noatime") + } + d := PartitionStat{ Device: common.ByteToString([]byte(stat.Mntfromname[:])), Mountpoint: common.ByteToString([]byte(stat.Mntonname[:])), @@ -68,13 +107,13 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // request agian to get desired mount data - ret, _, err = unix.Syscall6( + ret, _, err := unix.Syscall( 485, // SYS___fstatvfs190, see sys/syscall.h uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index 9d364d4f2..c98be60e3 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -1,3 +1,6 @@ +//go:build netbsd && arm64 +// +build netbsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs types_netbsd.go @@ -36,3 +39,7 @@ type ( Mntfromlabel [1024]uint8 } ) + +type _Ctype_struct___0 struct { + FsidVal [32]int32 +} diff --git a/disk/types_netbsd.go b/disk/types_netbsd.go index 25217a08b..c0326f5c2 100644 --- a/disk/types_netbsd.go +++ b/disk/types_netbsd.go @@ -1,7 +1,7 @@ //go:build ignore // +build ignore -// Hand writing: _Ctype_struct_statvfs +// Hand writing: _Ctype_struct___0 /* Input to cgo -godefs. @@ -17,7 +17,7 @@ package disk #include #include #include -#include + */ import "C" From 1136aa25dac981a7abf8e12c1921b8e54bc1be86 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 23:37:30 +0800 Subject: [PATCH 11/18] disk: code can be compiled now, but test still failed though --- disk/disk_netbsd.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 94ff76eb8..09432d6bf 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -4,9 +4,7 @@ package disk import ( - "bytes" "context" - "encoding/binary" "unsafe" "github.com/shirou/gopsutil/v3/internal/common" @@ -106,15 +104,14 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := Statvfs{} flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h - // request agian to get desired mount data - ret, _, err := unix.Syscall( + _, _, err := unix.Syscall( 485, // SYS___fstatvfs190, see sys/syscall.h uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), ) if err != 0 { - return ret, err + return nil, err } bsize := stat.Bsize From 319f5ea6e5393d415e3b95fab8737bac85109bec Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Tue, 12 Sep 2023 00:16:22 +0800 Subject: [PATCH 12/18] disk: small improvement, but still doesn't work --- disk/disk_netbsd.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 09432d6bf..c3459e15b 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -26,13 +26,15 @@ 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( - 483, // SYS___getvfsstat90 syscall - 0, - 0, + uintptr(unsafe.Pointer(&trap)), + uintptr(unsafe.Pointer(nil)), + uintptr(unsafe.Pointer(&emptyBufSize)), uintptr(unsafe.Pointer(&flag)), ) if err != 0 { @@ -46,7 +48,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // request agian to get desired mount data _, _, err = unix.Syscall( - 483, + uintptr(unsafe.Pointer(&flag)), uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&flag)), @@ -102,10 +104,11 @@ 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 _, _, err := unix.Syscall( - 485, // SYS___fstatvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(&trap)), uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), From dd0253b0ec811dd1f7cf419e244ebe0a328ff0d1 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 04:03:33 +0800 Subject: [PATCH 13/18] disk: fix various bugs --- disk/disk_netbsd.go | 17 ++++++++++------- disk/disk_netbsd_arm64.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index c3459e15b..8973ec516 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -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)), ) diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index c98be60e3..a2e806226 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -41,5 +41,5 @@ type ( ) type _Ctype_struct___0 struct { - FsidVal [32]int32 + FsidVal [2]int32 } From 734a7a6e5532143f572ecdaf3269dd1447e40ade Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 15:49:22 +0800 Subject: [PATCH 14/18] disk: we should use frsize as the real block size --- disk/disk_netbsd.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 8973ec516..d737d3142 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -111,7 +111,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { } _, _, err := unix.Syscall( - 484, // SYS___fstatvfs190, see sys/syscall.h + 484, // SYS___statvfs190, see sys/syscall.h uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), @@ -120,7 +120,8 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { return nil, err } - bsize := stat.Bsize + // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 + bsize := stat.Frsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), From 4a46201e00ab39278656b0e9727a1b9167312e5c Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 17:44:58 +0800 Subject: [PATCH 15/18] cpu && host: fix compile time errors --- cpu/cpu_fallback.go | 4 +- cpu/cpu_netbsd.go | 8 ---- cpu/cpu_netbsd_arm64.go | 5 +-- host/host_fallback.go | 4 +- host/host_netbsd.go | 55 ++++++++++++++++++++++++++ host/host_posix.go | 4 +- internal/common/common_netbsd.go | 66 ++++++++++++++++++++++++++++++++ 7 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 host/host_netbsd.go create mode 100644 internal/common/common_netbsd.go diff --git a/cpu/cpu_fallback.go b/cpu/cpu_fallback.go index 6d7007ff9..089f603c8 100644 --- a/cpu/cpu_fallback.go +++ b/cpu/cpu_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !dragonfly && !plan9 && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows && !dragonfly && !plan9 && !aix +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows,!dragonfly,!plan9,!aix package cpu diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index facc4237a..519ffdb25 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -14,14 +14,6 @@ import ( "golang.org/x/sys/unix" ) -type cpuTimes struct { - User uint64 - Nice uint64 - Sys uint64 - Intr uint64 - Idle uint64 -} - const ( // sys/sysctl.h ctlKern = 1 // "high kernel": proc, limits diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go index d659058cd..8d5cfd9eb 100644 --- a/cpu/cpu_netbsd_arm64.go +++ b/cpu/cpu_netbsd_arm64.go @@ -1,10 +1,9 @@ package cpu type cpuTimes struct { - User uint64 + User uint64 Nice uint64 Sys uint64 - Spin uint64 - Intr uint64 + Intr uint64 Idle uint64 } diff --git a/host/host_fallback.go b/host/host_fallback.go index 585250f9a..a393ca15d 100644 --- a/host/host_fallback.go +++ b/host/host_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows package host diff --git a/host/host_netbsd.go b/host/host_netbsd.go new file mode 100644 index 000000000..488f1dfc2 --- /dev/null +++ b/host/host_netbsd.go @@ -0,0 +1,55 @@ +//go:build netbsd +// +build netbsd + +package host + +import ( + "context" + "strings" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func HostIDWithContext(ctx context.Context) (string, error) { + return "", common.ErrNotImplementedError +} + +func numProcs(ctx context.Context) (uint64, error) { + return 0, common.ErrNotImplementedError +} + +func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { + platform := "" + family := "" + version := "" + + p, err := unix.Sysctl("kern.ostype") + if err == nil { + platform = strings.ToLower(p) + } + v, err := unix.Sysctl("kern.osrelease") + if err == nil { + version = strings.ToLower(v) + } + + return platform, family, version, nil +} + +func VirtualizationWithContext(ctx context.Context) (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func UsersWithContext(ctx context.Context) ([]UserStat, error) { + var ret []UserStat + return ret, common.ErrNotImplementedError +} + +func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) { + return []TemperatureStat{}, common.ErrNotImplementedError +} + +func KernelVersionWithContext(ctx context.Context) (string, error) { + _, _, version, err := PlatformInformationWithContext(ctx) + return version, err +} diff --git a/host/host_posix.go b/host/host_posix.go index 24529f19f..e7e0d837f 100644 --- a/host/host_posix.go +++ b/host/host_posix.go @@ -1,5 +1,5 @@ -//go:build linux || freebsd || openbsd || darwin || solaris -// +build linux freebsd openbsd darwin solaris +//go:build linux || freebsd || openbsd || netbsd || darwin || solaris +// +build linux freebsd openbsd netbsd darwin solaris package host diff --git a/internal/common/common_netbsd.go b/internal/common/common_netbsd.go new file mode 100644 index 000000000..efbc710a5 --- /dev/null +++ b/internal/common/common_netbsd.go @@ -0,0 +1,66 @@ +//go:build netbsd +// +build netbsd + +package common + +import ( + "os" + "os/exec" + "strings" + "unsafe" + + "golang.org/x/sys/unix" +) + +func DoSysctrl(mib string) ([]string, error) { + cmd := exec.Command("sysctl", "-n", mib) + cmd.Env = getSysctrlEnv(os.Environ()) + out, err := cmd.Output() + if err != nil { + return []string{}, err + } + v := strings.Replace(string(out), "{ ", "", 1) + v = strings.Replace(string(v), " }", "", 1) + values := strings.Fields(string(v)) + + return values, nil +} + +func CallSyscall(mib []int32) ([]byte, uint64, error) { + mibptr := unsafe.Pointer(&mib[0]) + miblen := uint64(len(mib)) + + // get required buffer size + length := uint64(0) + _, _, err := unix.Syscall6( + unix.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + 0, + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + var b []byte + return b, length, err + } + if length == 0 { + var b []byte + return b, length, err + } + // get proc info itself + buf := make([]byte, length) + _, _, err = unix.Syscall6( + unix.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + return buf, length, err + } + + return buf, length, nil +} From def3572629f18c1dae4789ff8ddce716078697ed Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 17 Sep 2023 01:43:13 +0800 Subject: [PATCH 16/18] format the code --- cpu/cpu_netbsd.go | 10 +-- cpu/cpu_netbsd_arm64.go | 4 +- disk/disk_netbsd.go | 124 +++++++++++++++++++------------------- disk/disk_netbsd_arm64.go | 52 ++++++++-------- mem/mem_netbsd.go | 2 +- 5 files changed, 96 insertions(+), 96 deletions(-) diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index 519ffdb25..1f66be342 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -16,9 +16,9 @@ import ( const ( // sys/sysctl.h - ctlKern = 1 // "high kernel": proc, limits - ctlHw = 6 // CTL_HW - kernCpTime = 51 // KERN_CPTIME + ctlKern = 1 // "high kernel": proc, limits + ctlHw = 6 // CTL_HW + kernCpTime = 51 // KERN_CPTIME ) var ClocksPerSec = float64(100) @@ -67,7 +67,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er return ret, err } - stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) + stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) ret = append(ret, TimesStat{ CPU: fmt.Sprintf("cpu%d", i), User: float64(stats.User), @@ -96,7 +96,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if err != nil { return nil, err } - _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) + _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) if err != nil { return nil, err } diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go index 8d5cfd9eb..57e14528d 100644 --- a/cpu/cpu_netbsd_arm64.go +++ b/cpu/cpu_netbsd_arm64.go @@ -1,9 +1,9 @@ package cpu type cpuTimes struct { - User uint64 + User uint64 Nice uint64 Sys uint64 - Intr uint64 + Intr uint64 Idle uint64 } diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index d737d3142..5976efadb 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -5,58 +5,58 @@ package disk import ( "context" - "unsafe" + "unsafe" "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) const ( - // see sys/fstypes.h and `man 5 statvfs` - MNT_RDONLY = 0x00000001 /* read only filesystem */ - MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ - MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ - MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ - MNT_NODEV = 0x00000010 /* don't interpret special files */ - MNT_ASYNC = 0x00000040 /* file system written asynchronously */ - MNT_NOATIME = 0x04000000 /* Never update access times in fs */ - MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ + // see sys/fstypes.h and `man 5 statvfs` + MNT_RDONLY = 0x00000001 /* read only filesystem */ + MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ + MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ + MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ + MNT_NODEV = 0x00000010 /* don't interpret special files */ + MNT_ASYNC = 0x00000040 /* file system written asynchronously */ + MNT_NOATIME = 0x04000000 /* Never update access times in fs */ + MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ ) 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 - emptyBufSize := 0 - r, _, err := unix.Syscall( - 483, // SYS___getvfsstat90 syscall - uintptr(unsafe.Pointer(nil)), - uintptr(unsafe.Pointer(&emptyBufSize)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return ret, err - } - mountedFsCount := uint64(r) - - // calculate the buffer size - bufSize := sizeOfStatvfs * mountedFsCount - buf := make([]Statvfs, mountedFsCount) - - // request agian to get desired mount data - _, _, err = unix.Syscall( - 483, // SYS___getvfsstat90 syscall - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&bufSize)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return ret, err - } - - for _, stat := range buf { + + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + + // get required buffer size + emptyBufSize := 0 + r, _, err := unix.Syscall( + 483, // SYS___getvfsstat90 syscall + uintptr(unsafe.Pointer(nil)), + uintptr(unsafe.Pointer(&emptyBufSize)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return ret, err + } + mountedFsCount := uint64(r) + + // calculate the buffer size + bufSize := sizeOfStatvfs * mountedFsCount + buf := make([]Statvfs, mountedFsCount) + + // request agian to get desired mount data + _, _, err = unix.Syscall( + 483, // SYS___getvfsstat90 syscall + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&bufSize)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return ret, err + } + + for _, stat := range buf { opts := []string{"rw"} if stat.Flag&MNT_RDONLY != 0 { opts = []string{"rw"} @@ -102,26 +102,26 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { - stat := Statvfs{} - 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( - 484, // SYS___statvfs190, see sys/syscall.h - uintptr(unsafe.Pointer(_path)), - uintptr(unsafe.Pointer(&stat)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return nil, err - } - - // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 - bsize := stat.Frsize + stat := Statvfs{} + 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( + 484, // SYS___statvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(_path)), + uintptr(unsafe.Pointer(&stat)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return nil, err + } + + // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 + bsize := stat.Frsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index a2e806226..dfe48f812 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -12,34 +12,34 @@ const ( 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 + 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 } ) type _Ctype_struct___0 struct { - FsidVal [2]int32 + FsidVal [2]int32 } diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go index 6e2be3fa1..d1f54ecaf 100644 --- a/mem/mem_netbsd.go +++ b/mem/mem_netbsd.go @@ -47,7 +47,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { ret.Used = ret.Total - ret.Available ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 - // Get buffers from vm.bufmem sysctl + // Get buffers from vm.bufmem sysctl ret.Buffers, err = unix.SysctlUint64("vm.bufmem") if err != nil { return nil, err From 826037fe4be5cef3c1e693e1f909b7330c8b57cd Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Fri, 29 Sep 2023 16:36:44 +0800 Subject: [PATCH 17/18] Fix build_test on amd64 NetBSD --- Makefile | 96 +++++++++++++++++++-------------------- cpu/cpu_netbsd_amd64.go | 9 ++++ disk/disk_netbsd_amd64.go | 45 ++++++++++++++++++ mem/mem_bsd.go | 4 +- 4 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 cpu/cpu_netbsd_amd64.go create mode 100644 disk/disk_netbsd_amd64.go diff --git a/Makefile b/Makefile index 3f5cd8416..a2cb5afef 100644 --- a/Makefile +++ b/Makefile @@ -13,72 +13,72 @@ check: ## Check BUILD_FAIL_PATTERN=grep -v "exec format error" | grep "build failed" && exit 1 || exit 0 build_test: ## test only buildable # Supported operating systems - GOOS=linux GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=loong64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=riscv64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=s390x go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=windows go120 test ./... | $(BUILD_FAIL_PATTERN) # Operating systems supported for building only (not implemented error if used) - GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=solaris go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=dragonfly go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go120 test ./... | $(BUILD_FAIL_PATTERN) # cross build to OpenBSD not worked since process has "C" -# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=plan9 go test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=openbsd go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=plan9 go120 test ./... | $(BUILD_FAIL_PATTERN) ifeq ($(shell uname -s), Darwin) - CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) endif @echo 'Successfully built on all known operating systems' vet: - GOOS=darwin GOARCH=amd64 go vet ./... - GOOS=darwin GOARCH=arm64 go vet ./... + GOOS=darwin GOARCH=amd64 go120 vet ./... + GOOS=darwin GOARCH=arm64 go120 vet ./... - GOOS=dragonfly GOARCH=amd64 go vet ./... + GOOS=dragonfly GOARCH=amd64 go120 vet ./... - GOOS=freebsd GOARCH=amd64 go vet ./... - GOOS=freebsd GOARCH=386 go vet ./... - GOOS=freebsd GOARCH=arm go vet ./... + GOOS=freebsd GOARCH=amd64 go120 vet ./... + GOOS=freebsd GOARCH=386 go120 vet ./... + GOOS=freebsd GOARCH=arm go120 vet ./... - GOOS=linux GOARCH=386 go vet ./... - GOOS=linux GOARCH=amd64 go vet ./... - GOOS=linux GOARCH=arm64 go vet ./... - GOOS=linux GOARCH=arm go vet ./... - GOOS=linux GOARCH=loong64 go vet ./... - GOOS=linux GOARCH=mips64 go vet ./... - GOOS=linux GOARCH=mips64le go vet ./... - GOOS=linux GOARCH=mips go vet ./... - GOOS=linux GOARCH=mipsle go vet ./... - GOOS=linux GOARCH=ppc64le go vet ./... - GOOS=linux GOARCH=ppc64 go vet ./... - GOOS=linux GOARCH=riscv64 go vet ./... - GOOS=linux GOARCH=s390x go vet ./... + GOOS=linux GOARCH=386 go120 vet ./... + GOOS=linux GOARCH=amd64 go120 vet ./... + GOOS=linux GOARCH=arm64 go120 vet ./... + GOOS=linux GOARCH=arm go120 vet ./... + GOOS=linux GOARCH=loong64 go120 vet ./... + GOOS=linux GOARCH=mips64 go120 vet ./... + GOOS=linux GOARCH=mips64le go120 vet ./... + GOOS=linux GOARCH=mips go120 vet ./... + GOOS=linux GOARCH=mipsle go120 vet ./... + GOOS=linux GOARCH=ppc64le go120 vet ./... + GOOS=linux GOARCH=ppc64 go120 vet ./... + GOOS=linux GOARCH=riscv64 go120 vet ./... + GOOS=linux GOARCH=s390x go120 vet ./... - GOOS=netbsd GOARCH=amd64 go vet ./... + GOOS=netbsd GOARCH=amd64 go120 vet ./... - GOOS=openbsd GOARCH=386 go vet ./... - GOOS=openbsd GOARCH=amd64 go vet ./... + GOOS=openbsd GOARCH=386 go120 vet ./... + GOOS=openbsd GOARCH=amd64 go120 vet ./... - GOOS=solaris GOARCH=amd64 go vet ./... + GOOS=solaris GOARCH=amd64 go120 vet ./... - GOOS=windows GOARCH=amd64 go vet ./... - GOOS=windows GOARCH=386 go vet ./... + GOOS=windows GOARCH=amd64 go120 vet ./... + GOOS=windows GOARCH=386 go120 vet ./... - GOOS=plan9 GOARCH=amd64 go vet ./... - GOOS=plan9 GOARCH=386 go vet ./... + GOOS=plan9 GOARCH=amd64 go120 vet ./... + GOOS=plan9 GOARCH=386 go120 vet ./... macos_test: - CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) init_tools: go get github.com/golang/dep/cmd/dep diff --git a/cpu/cpu_netbsd_amd64.go b/cpu/cpu_netbsd_amd64.go new file mode 100644 index 000000000..57e14528d --- /dev/null +++ b/cpu/cpu_netbsd_amd64.go @@ -0,0 +1,9 @@ +package cpu + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Intr uint64 + Idle uint64 +} diff --git a/disk/disk_netbsd_amd64.go b/disk/disk_netbsd_amd64.go new file mode 100644 index 000000000..c21421cfe --- /dev/null +++ b/disk/disk_netbsd_amd64.go @@ -0,0 +1,45 @@ +//go:build netbsd && amd64 +// +build netbsd,amd64 + +// 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 + } +) + +type _Ctype_struct___0 struct { + FsidVal [2]int32 +} diff --git a/mem/mem_bsd.go b/mem/mem_bsd.go index ce930fbe4..ef867d742 100644 --- a/mem/mem_bsd.go +++ b/mem/mem_bsd.go @@ -1,5 +1,5 @@ -//go:build freebsd || openbsd -// +build freebsd openbsd +//go:build freebsd || openbsd || netbsd +// +build freebsd openbsd netbsd package mem From 66ee833b9ea2277fafc7878aa0f5db1ed2a592d2 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Fri, 29 Sep 2023 16:49:18 +0800 Subject: [PATCH 18/18] Makefile: revert back to original one --- Makefile | 96 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index a2cb5afef..3f5cd8416 100644 --- a/Makefile +++ b/Makefile @@ -13,72 +13,72 @@ check: ## Check BUILD_FAIL_PATTERN=grep -v "exec format error" | grep "build failed" && exit 1 || exit 0 build_test: ## test only buildable # Supported operating systems - GOOS=linux GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=loong64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=riscv64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=s390x go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=windows go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) # Operating systems supported for building only (not implemented error if used) - GOOS=solaris go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=dragonfly go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) # cross build to OpenBSD not worked since process has "C" -# GOOS=openbsd go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=plan9 go120 test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=plan9 go test ./... | $(BUILD_FAIL_PATTERN) ifeq ($(shell uname -s), Darwin) - CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) endif @echo 'Successfully built on all known operating systems' vet: - GOOS=darwin GOARCH=amd64 go120 vet ./... - GOOS=darwin GOARCH=arm64 go120 vet ./... + GOOS=darwin GOARCH=amd64 go vet ./... + GOOS=darwin GOARCH=arm64 go vet ./... - GOOS=dragonfly GOARCH=amd64 go120 vet ./... + GOOS=dragonfly GOARCH=amd64 go vet ./... - GOOS=freebsd GOARCH=amd64 go120 vet ./... - GOOS=freebsd GOARCH=386 go120 vet ./... - GOOS=freebsd GOARCH=arm go120 vet ./... + GOOS=freebsd GOARCH=amd64 go vet ./... + GOOS=freebsd GOARCH=386 go vet ./... + GOOS=freebsd GOARCH=arm go vet ./... - GOOS=linux GOARCH=386 go120 vet ./... - GOOS=linux GOARCH=amd64 go120 vet ./... - GOOS=linux GOARCH=arm64 go120 vet ./... - GOOS=linux GOARCH=arm go120 vet ./... - GOOS=linux GOARCH=loong64 go120 vet ./... - GOOS=linux GOARCH=mips64 go120 vet ./... - GOOS=linux GOARCH=mips64le go120 vet ./... - GOOS=linux GOARCH=mips go120 vet ./... - GOOS=linux GOARCH=mipsle go120 vet ./... - GOOS=linux GOARCH=ppc64le go120 vet ./... - GOOS=linux GOARCH=ppc64 go120 vet ./... - GOOS=linux GOARCH=riscv64 go120 vet ./... - GOOS=linux GOARCH=s390x go120 vet ./... + GOOS=linux GOARCH=386 go vet ./... + GOOS=linux GOARCH=amd64 go vet ./... + GOOS=linux GOARCH=arm64 go vet ./... + GOOS=linux GOARCH=arm go vet ./... + GOOS=linux GOARCH=loong64 go vet ./... + GOOS=linux GOARCH=mips64 go vet ./... + GOOS=linux GOARCH=mips64le go vet ./... + GOOS=linux GOARCH=mips go vet ./... + GOOS=linux GOARCH=mipsle go vet ./... + GOOS=linux GOARCH=ppc64le go vet ./... + GOOS=linux GOARCH=ppc64 go vet ./... + GOOS=linux GOARCH=riscv64 go vet ./... + GOOS=linux GOARCH=s390x go vet ./... - GOOS=netbsd GOARCH=amd64 go120 vet ./... + GOOS=netbsd GOARCH=amd64 go vet ./... - GOOS=openbsd GOARCH=386 go120 vet ./... - GOOS=openbsd GOARCH=amd64 go120 vet ./... + GOOS=openbsd GOARCH=386 go vet ./... + GOOS=openbsd GOARCH=amd64 go vet ./... - GOOS=solaris GOARCH=amd64 go120 vet ./... + GOOS=solaris GOARCH=amd64 go vet ./... - GOOS=windows GOARCH=amd64 go120 vet ./... - GOOS=windows GOARCH=386 go120 vet ./... + GOOS=windows GOARCH=amd64 go vet ./... + GOOS=windows GOARCH=386 go vet ./... - GOOS=plan9 GOARCH=amd64 go120 vet ./... - GOOS=plan9 GOARCH=386 go120 vet ./... + GOOS=plan9 GOARCH=amd64 go vet ./... + GOOS=plan9 GOARCH=386 go vet ./... macos_test: - CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) init_tools: go get github.com/golang/dep/cmd/dep