1// 2// Initially created by 3// cgo -godefs ctypes_solaris.go 4// 5// Now contains edits for documentation. This is considered okay by me 6// because these structs are not exactly likely to change any time 7// soon; that would break API compatibility. 8// 9// This is specific to amd64. It's unlikely that Go will support 10// 32-bit Solaris ('386'), but. 11 12package kstat 13 14// IO represents the entire collection of KStat (disk) IO statistics 15// exposed by an IoStat type KStat. 16// 17// Because IO is an exact copy of the C kstat_io_t structure from the 18// kernel, it does not have a Snaptime or KStat field. You must save 19// that information separately if you need it, perhaps by embedded the 20// IO struct as an anonymous struct in an additional struct of your 21// own. 22type IO struct { 23 Nread uint64 24 Nwritten uint64 25 Reads uint32 26 Writes uint32 27 Wtime int64 28 Wlentime int64 29 Wlastupdate int64 30 Rtime int64 31 Rlentime int64 32 Rlastupdate int64 33 Wcnt uint32 34 Rcnt uint32 35} 36 37// Sysinfo is the data from unix:0:sysinfo, which is a sysinfo_t. 38type Sysinfo struct { 39 Updates uint32 40 Runque uint32 41 Runocc uint32 42 Swpque uint32 43 Swpocc uint32 44 Waiting uint32 45} 46 47// Vminfo is the data from unix:0:vminfo, which is a vminfo_t. 48type Vminfo struct { 49 Freemem uint64 50 Resv uint64 51 Alloc uint64 52 Avail uint64 53 Free uint64 54 Updates uint64 55} 56 57// Var is the data from unix:0:var, which is a 'struct var'. 58type Var struct { 59 Buf int32 60 Call int32 61 Proc int32 62 Maxupttl int32 63 Nglobpris int32 64 Maxsyspri int32 65 Clist int32 66 Maxup int32 67 Hbuf int32 68 Hmask int32 69 Pbuf int32 70 Sptmap int32 71 Maxpmem int32 72 Autoup int32 73 Bufhwm int32 74} 75 76// Mntinfo is the kernel data from nfs:*:mntinfo, which is a 'struct 77// mntinfo_kstat'. Use .Proto() and .Curserver() to get the RProto 78// and RCurserver fields as strings instead of their awkward raw form. 79type Mntinfo struct { 80 RProto [128]int8 81 Vers uint32 82 Flags uint32 83 Secmod uint32 84 Curread uint32 85 Curwrite uint32 86 Timeo int32 87 Retrans int32 88 Acregmin uint32 89 Acregmax uint32 90 Acdirmin uint32 91 Acdirmax uint32 92 Timers [4]struct { 93 Srtt uint32 94 Deviate uint32 95 Rtxcur uint32 96 } 97 Noresponse uint32 98 Failover uint32 99 Remap uint32 100 RCurserver [257]int8 101 pad0 [3]byte 102} 103 104// CFieldString converts a (null-terminated) C string embedded in an 105// []int8 slice to a (Go) string. The []int8 slice is likely to come 106// from an [N]int8 fixed-size field in a statistics struct. If there 107// is no null in the slice, the entire slice is returned. 108// 109// (The no-null behavior is common in C APIs; a string is often allowed 110// to exactly fill the field with no room for a trailing null.) 111func CFieldString(src []int8) string { 112 slen := len(src) 113 buf := make([]byte, slen) 114 for i := 0; i < len(src); i++ { 115 buf[i] = byte(src[i]) 116 if src[i] == 0 { 117 slen = i 118 break 119 } 120 } 121 return string(buf[:slen]) 122} 123 124// Proto returns a Mntinfo RProto as a string. 125func (m Mntinfo) Proto() string { 126 return CFieldString(m.RProto[:]) 127} 128 129// Curserver returns a Mntinfo RCurserver as a string. 130func (m Mntinfo) Curserver() string { 131 return CFieldString(m.RCurserver[:]) 132} 133 134// The Mntinfo type is not an exact conversion as produced by cgo; 135// because the original struct mntinfo_kstat contains an embedded 136// anonymously typed struct, it runs into 137// https://github.com/golang/go/issues/5253. This version is manually 138// produced from a cgo starting point and then verified to be the same 139// size. 140// It also has Proto and Curserver renamed so we can add methods to 141// get them as Go strings. 142