Beispiel #1
0
// Convert property to name
// ( returns built in string representation of property name).
// This is optional, you can represent each property with string
// name of choice.
func DatasetPropertyToName(p ZFSProp) (name string) {
	if p == ZFSNumProps {
		return "numofprops"
	}
	prop := C.zfs_prop_t(p)
	name = C.GoString(C.zfs_prop_to_name(prop))
	return
}
Beispiel #2
0
func toCZFSProperties(props ZFSProperties) (cprops *C.nvlist_t) {
	cprops = nil
	for prop, value := range props {
		name := C.zfs_prop_to_name(C.zfs_prop_t(prop))
		r := C.add_prop_list(name, C.CString(value), &cprops, C.boolean_t(0))
		if r != 0 {
			if cprops != nil {
				C.nvlist_free(cprops)
				cprops = nil
			}
			return
		}
	}
	return
}
Beispiel #3
0
// Set ZFS dataset property to value. Not all properties can be set,
// some can be set only at creation time and some are read only.
// Always check if returned error and its description.
func (d *Dataset) SetProperty(p ZFSProp, value string) (err error) {
	if d.list == nil {
		err = errors.New(msgDatasetIsNil)
		return
	}
	errcode := C.zfs_prop_set(d.list.zh, C.zfs_prop_to_name(
		C.zfs_prop_t(p)), C.CString(value))
	if errcode != 0 {
		err = LastError()
	}
	// Update Properties member with change made
	if _, err = d.GetProperty(p); err != nil {
		return
	}
	return
}
Beispiel #4
0
func datasetPropertiesTo_nvlist(props map[ZFSProp]Property) (
	cprops *C.nvlist_t, err error) {
	// convert properties to nvlist C type
	r := C.nvlist_alloc(&cprops, C.NV_UNIQUE_NAME, 0)
	if r != 0 {
		err = errors.New("Failed to allocate properties")
		return
	}
	for prop, value := range props {
		r := C.nvlist_add_string(
			cprops, C.zfs_prop_to_name(
				C.zfs_prop_t(prop)), C.CString(value.Value))
		if r != 0 {
			err = errors.New("Failed to convert property")
			return
		}
	}
	return
}