func()

in sigar_aix.go [98:189]


func (self *FileSystemList) Get() error {
	var size C.int
	_, err := C.mntctl(C.MCTL_QUERY, C.sizeof_int, (*C.char)(unsafe.Pointer(&size)))
	if err != nil {
		return fmt.Errorf("error while retrieving file system number: %s", err)
	}

	buf := make([]byte, size)
	num, err := C.mntctl(C.MCTL_QUERY, C.ulong(size), (*C.char)(&buf[0]))
	if err != nil {
		return fmt.Errorf("error while retrieving file system list: %s", err)
	}

	// Vmount structure has a fixed size area for common data (type,
	// offsets, etc) and another area with variable length data (devname,
	// options, etc). These data can be accessed based on the offsets
	// stored in an array inside the fixed part. They can be retrieve
	// using index given by C define.
	vmt2data := func(buf []byte, ent *C.struct_vmount, idx int, baseOff int) []byte {
		off := int(ent.vmt_data[idx].vmt_off)
		size := int(ent.vmt_data[idx].vmt_size)
		return buf[baseOff+off : baseOff+off+size]
	}

	entOff := 0

	fslist := make([]FileSystem, num)
	for i := 0; i < int(num); i++ {
		ent := (*C.struct_vmount)(unsafe.Pointer(&buf[entOff]))
		fs := &fslist[i]

		// Correspondances taken for /etc/vfs
		switch ent.vmt_gfstype {
		case C.MNT_AIX:
			fs.SysTypeName = "jfs2"
		case C.MNT_NAMEFS:
			fs.SysTypeName = "namefs"
		case C.MNT_NFS:
			fs.SysTypeName = "nfs"
		case C.MNT_JFS:
			fs.SysTypeName = "jfs"
		case C.MNT_CDROM:
			fs.SysTypeName = "cdrom"
		case C.MNT_PROCFS:
			fs.SysTypeName = "proc"
		case C.MNT_SFS:
			fs.SysTypeName = "sfs"
		case C.MNT_CACHEFS:
			fs.SysTypeName = "cachefs"
		case C.MNT_NFS3:
			fs.SysTypeName = "nfs3"
		case C.MNT_AUTOFS:
			fs.SysTypeName = "autofs"
		case C.MNT_POOLFS:
			fs.SysTypeName = "poolfs"
		case C.MNT_UDF:
			fs.SysTypeName = "udfs"
		case C.MNT_NFS4:
			fs.SysTypeName = "nfs4"
		case C.MNT_CIFS:
			fs.SysTypeName = "cifs"
		case C.MNT_PMEMFS:
			fs.SysTypeName = "pmemfs"
		case C.MNT_AHAFS:
			fs.SysTypeName = "ahafs"
		case C.MNT_STNFS:
			fs.SysTypeName = "stnfs"
		default:
			if ent.vmt_flags&C.MNT_REMOTE != 0 {
				fs.SysTypeName = "network"
			} else {
				fs.SysTypeName = "none"
			}
		}

		fs.DirName = convertBytesToString(vmt2data(buf, ent, C.VMT_STUB, entOff))
		fs.Options = convertBytesToString(vmt2data(buf, ent, C.VMT_ARGS, entOff))
		devname := convertBytesToString(vmt2data(buf, ent, C.VMT_OBJECT, entOff))
		if ent.vmt_flags&C.MNT_REMOTE != 0 {
			hostname := convertBytesToString(vmt2data(buf, ent, C.VMT_OBJECT, entOff))
			fs.DevName = hostname + ":" + devname
		} else {
			fs.DevName = devname
		}

		entOff += int(ent.vmt_length)
	}

	self.List = fslist

	return nil
}