Esempio n. 1
0
static int
dodefault(const char *propname, int intsz, int numints, void *buf)
{
	zfs_prop_t prop;

	/*
	 * The setonce properties are read-only, BUT they still
	 * have a default value that can be used as the initial
	 * value.
	 */
	if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL ||
	    (zfs_prop_readonly(prop) && !zfs_prop_setonce(prop)))
		return (SET_ERROR(ENOENT));

	if (zfs_prop_get_type(prop) == PROP_TYPE_STRING) {
		if (intsz != 1)
			return (SET_ERROR(EOVERFLOW));
		(void) strncpy(buf, zfs_prop_default_string(prop),
		    numints);
	} else {
		if (intsz != 8 || numints < 1)
			return (SET_ERROR(EOVERFLOW));

		*(uint64_t *)buf = zfs_prop_default_numeric(prop);
	}

	return (0);
}
int
zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *propbuf,
    size_t proplen, zfs_source_t *srctype)
{
	uint64_t value;
	char msg[1024], *strvalue;
	nvlist_t *nvp;
	zfs_source_t src = ZFS_SRC_NONE;

	(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
	    "cannot get property '%s'"), zpool_prop_to_name(prop));

	if (zpool_get_version(zhp) < ZFS_VERSION_BOOTFS) {
		zfs_error_aux(zhp->zpool_hdl,
		    dgettext(TEXT_DOMAIN, "pool must be "
		    "upgraded to support pool properties"));
		return (zfs_error(zhp->zpool_hdl, EZFS_BADVERSION, msg));
	}

	if (zhp->zpool_props == NULL && zpool_get_all_props(zhp))
		return (zfs_error(zhp->zpool_hdl, EZFS_POOLPROPS, msg));

	/*
	 * the "name" property is special cased
	 */
	if (!zfs_prop_valid_for_type(prop, ZFS_TYPE_POOL) &&
	    prop != ZFS_PROP_NAME)
		return (-1);

	switch (prop) {
	case ZFS_PROP_NAME:
		(void) strlcpy(propbuf, zhp->zpool_name, proplen);
		break;

	case ZFS_PROP_BOOTFS:
		if (nvlist_lookup_nvlist(zhp->zpool_props,
		    zpool_prop_to_name(prop), &nvp) != 0) {
			strvalue = (char *)zfs_prop_default_string(prop);
			if (strvalue == NULL)
				strvalue = "-";
			src = ZFS_SRC_DEFAULT;
		} else {
			VERIFY(nvlist_lookup_uint64(nvp,
			    ZFS_PROP_SOURCE, &value) == 0);
			src = value;
			VERIFY(nvlist_lookup_string(nvp, ZFS_PROP_VALUE,
			    &strvalue) == 0);
			if (strlen(strvalue) >= proplen)
				return (-1);
		}
		(void) strcpy(propbuf, strvalue);
		break;

	default:
		return (-1);
	}
	if (srctype)
		*srctype = src;
	return (0);
}