diff --git a/disk/disk_freebsd.go b/disk/disk_freebsd.go index 24549b7..7380850 100644 --- a/disk/disk_freebsd.go +++ b/disk/disk_freebsd.go @@ -99,14 +99,12 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) { buf := []byte(r) length := len(buf) - ds := Devstat{} - devstatLen := int(unsafe.Sizeof(ds)) - count := int(uint64(length) / uint64(devstatLen)) + count := int(uint64(length) / uint64(sizeOfDevstat)) buf = buf[8:] // devstat.all has version in the head. // parse buf to Devstat for i := 0; i < count; i++ { - b := buf[i*devstatLen : i*devstatLen+devstatLen] + b := buf[i*sizeOfDevstat : i*sizeOfDevstat+sizeOfDevstat] d, err := parseDevstat(b) if err != nil { continue diff --git a/disk/disk_freebsd_amd64.go b/disk/disk_freebsd_amd64.go index bbae159..8579100 100644 --- a/disk/disk_freebsd_amd64.go +++ b/disk/disk_freebsd_amd64.go @@ -39,6 +39,10 @@ const ( MNT_SUSPEND = 4 ) +const ( + sizeOfDevstat = 0x120 +) + type ( _C_short int16 _C_int int32 diff --git a/disk/types_freebsd.go b/disk/types_freebsd.go index 4486904..dd6ddc4 100644 --- a/disk/types_freebsd.go +++ b/disk/types_freebsd.go @@ -65,7 +65,10 @@ const ( MNT_NOWAIT = 2 /* start all I/O, but do not wait for it */ MNT_LAZY = 3 /* push data not written by filesystem syncer */ MNT_SUSPEND = 4 /* Suspend file system after sync */ +) +const ( + sizeOfDevstat = C.sizeof_struct_devstat ) // Basic types