Example #1
0
// FSInfos return an FSInfo struct per mounted filesystem
// Go equivalent to sg_get_fs_stats
func (s *Stat) FSInfos() []*FSInfos {
	s.Lock()
	defer s.Unlock()
	var fs_size C.size_t
	var cArray *C.sg_fs_stats = C.sg_get_fs_stats(&fs_size)
	length := int(fs_size)
	slice := (*[1 << 16]C.sg_fs_stats)(unsafe.Pointer(cArray))[:length:length]

	var res []*FSInfos

	for _, v := range slice {
		f := &FSInfos{
			DeviceName:      C.GoString(v.device_name),
			FSType:          C.GoString(v.fs_type),
			MountPoint:      C.GoString(v.mnt_point),
			Size:            int(v.size),
			Used:            int(v.used),
			Free:            int(v.free),
			Available:       int(v.avail),
			TotalInodes:     int(v.total_inodes),
			UsedInodes:      int(v.used_inodes),
			FreeInodes:      int(v.free_inodes),
			AvailableInodes: int(v.avail_inodes),
		}
		res = append(res, f)
	}
	return res
}
Example #2
0
// GetFsStats returns information about mounted filesystems; see sg_get_fs_stats(3).
func GetFsStats() ([]*FsStats, error) {
	var ct C.int
	c := C.sg_get_fs_stats(&ct)
	if c == nil {
		return nil, getError()
	}
	return asFsStatsArray(c, int(ct)), nil
}