[disk]freebsd: change to use C.sizeof_struct.

This commit is contained in:
WAKAYAMA shirou 2016-03-20 22:47:29 +09:00
parent 1f32ce1bb3
commit dc8b14acd5
3 changed files with 9 additions and 4 deletions

View File

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

View File

@ -39,6 +39,10 @@ const (
MNT_SUSPEND = 4
)
const (
sizeOfDevstat = 0x120
)
type (
_C_short int16
_C_int int32

View File

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