Lines Matching full:value

60 static void	*bhnd_nvram_val_alloc_bytes(bhnd_nvram_val *value, size_t ilen,
62 static int bhnd_nvram_val_set(bhnd_nvram_val *value, const void *inp,
64 static int bhnd_nvram_val_set_inline(bhnd_nvram_val *value,
83 /** Initialize an empty value instance with @p _fmt, @p _storage, and
93 /** Assert that @p value's backing representation state has initialized
97 value->data_storage == BHND_NVRAM_VAL_DATA_NONE && \
98 value->data_len == 0 && \
99 value->data.ptr == NULL, \
100 ("previously initialized value"))
123 bhnd_nvram_val_storage val_storage; /**< value structure storage */
124 const bhnd_nvram_val_fmt *fmt; /**< value format */
129 /* Shared NULL value instance */
213 * @param[in,out] fmt Indirect pointer to the NVRAM value format. If
266 /* Value can be initialized with provided format and input type */ in bhnd_nvram_val_fmt_filter()
273 bhnd_nvram_val_init_common(bhnd_nvram_val *value, in bhnd_nvram_val_init_common() argument
282 /* If the value format is unspecified, we use the default format in bhnd_nvram_val_init_common()
295 /* Value can be initialized with provided input type */ in bhnd_nvram_val_init_common()
299 /* Initialize value instance */ in bhnd_nvram_val_init_common()
300 *value = BHND_NVRAM_VAL_INITIALIZER(fmt, val_storage); in bhnd_nvram_val_init_common()
304 error = bhnd_nvram_val_set(value, inp, ilen, itype, flags); in bhnd_nvram_val_init_common()
317 outp = bhnd_nvram_val_alloc_bytes(value, olen, otype, flags); in bhnd_nvram_val_init_common()
330 * Initialize an externally allocated instance of @p value with @p fmt from the
333 * On success, the caller owns a reference to @p value, and is responsible for
334 * freeing any resources allocated for @p value via bhnd_nvram_val_release().
336 * @param value The externally allocated value instance to be
338 * @param fmt The value's format, or NULL to use the default format
343 * @param flags Value flags (see BHND_NVRAM_VAL_*).
350 * @retval ERANGE If value coercion would overflow (or underflow) the
354 bhnd_nvram_val_init(bhnd_nvram_val *value, const bhnd_nvram_val_fmt *fmt, in bhnd_nvram_val_init() argument
359 error = bhnd_nvram_val_init_common(value, BHND_NVRAM_VAL_STORAGE_AUTO, in bhnd_nvram_val_init()
362 bhnd_nvram_val_release(value); in bhnd_nvram_val_init()
368 * Allocate a value instance with @p fmt, and attempt to initialize its internal
371 * On success, the caller owns a reference to @p value, and is responsible for
372 * freeing any resources allocated for @p value via bhnd_nvram_val_release().
374 * @param[out] value On success, the allocated value instance.
375 * @param fmt The value's format, or NULL to use the default format
380 * @param flags Value flags (see BHND_NVRAM_VAL_*).
387 * @retval ERANGE If value coercion would overflow (or underflow) the
391 bhnd_nvram_val_new(bhnd_nvram_val **value, const bhnd_nvram_val_fmt *fmt, in bhnd_nvram_val_new() argument
397 if ((*value = bhnd_nv_malloc(sizeof(**value))) == NULL) in bhnd_nvram_val_new()
401 error = bhnd_nvram_val_init_common(*value, in bhnd_nvram_val_new()
404 /* Will also free() the value allocation */ in bhnd_nvram_val_new()
405 bhnd_nvram_val_release(*value); in bhnd_nvram_val_new()
414 bhnd_nvram_val_convert_common(bhnd_nvram_val *value, in bhnd_nvram_val_convert_common() argument
424 /* Determine whether direct initialization from the source value's in bhnd_nvram_val_convert_common()
428 /* Adjust value flags based on the source data storage */ in bhnd_nvram_val_convert_common()
446 return (bhnd_nvram_val_init_common(value, val_storage, fmt, inp, in bhnd_nvram_val_convert_common()
450 /* Value must be initialized with the format's native type */ in bhnd_nvram_val_convert_common()
453 /* Initialize value instance */ in bhnd_nvram_val_convert_common()
454 *value = BHND_NVRAM_VAL_INITIALIZER(fmt, val_storage); in bhnd_nvram_val_convert_common()
461 outp = bhnd_nvram_val_alloc_bytes(value, olen, otype, flags); in bhnd_nvram_val_convert_common()
473 * Initialize an externally allocated instance of @p value with @p fmt, and
475 * value.
477 * On success, the caller owns a reference to @p value, and is responsible for
478 * freeing any resources allocated for @p value via bhnd_nvram_val_release().
480 * @param value The externally allocated value instance to be
482 * @param fmt The value's format.
483 * @param src Input value to be converted.
484 * @param flags Value flags (see BHND_NVRAM_VAL_*).
491 * @retval ERANGE If value coercion of @p src would overflow
495 bhnd_nvram_val_convert_init(bhnd_nvram_val *value, in bhnd_nvram_val_convert_init() argument
500 error = bhnd_nvram_val_convert_common(value, in bhnd_nvram_val_convert_init()
503 bhnd_nvram_val_release(value); in bhnd_nvram_val_convert_init()
509 * Allocate a value instance with @p fmt, and attempt to initialize its internal
510 * representation from the given @p src value.
512 * On success, the caller owns a reference to @p value, and is responsible for
513 * freeing any resources allocated for @p value via bhnd_nvram_val_release().
515 * @param[out] value On success, the allocated value instance.
516 * @param fmt The value's format.
517 * @param src Input value to be converted.
518 * @param flags Value flags (see BHND_NVRAM_VAL_*).
525 * @retval ERANGE If value coercion of @p src would overflow
529 bhnd_nvram_val_convert_new(bhnd_nvram_val **value, in bhnd_nvram_val_convert_new() argument
535 if ((*value = bhnd_nv_malloc(sizeof(**value))) == NULL) in bhnd_nvram_val_convert_new()
539 error = bhnd_nvram_val_convert_common(*value, in bhnd_nvram_val_convert_new()
542 /* Will also free() the value allocation */ in bhnd_nvram_val_convert_new()
543 bhnd_nvram_val_release(*value); in bhnd_nvram_val_convert_new()
550 * Copy or retain a reference to @p value.
555 * @param value The value to be copied (or retained).
557 * @retval bhnd_nvram_val if @p value was successfully copied or retained.
561 bhnd_nvram_val_copy(bhnd_nvram_val *value) in bhnd_nvram_val_copy() argument
570 switch (value->val_storage) { in bhnd_nvram_val_copy()
573 return (value); in bhnd_nvram_val_copy()
576 if (!BHND_NVRAM_VAL_NEED_COPY(value)) { in bhnd_nvram_val_copy()
577 refcount_acquire(&value->refs); in bhnd_nvram_val_copy()
578 return (value); in bhnd_nvram_val_copy()
585 BHND_NV_ASSERT(value->refs == 1, ("non-allocated value has " in bhnd_nvram_val_copy()
586 "active refcount (%u)", value->refs)); in bhnd_nvram_val_copy()
592 /* Compute the new value's flags based on the source value */ in bhnd_nvram_val_copy()
593 switch (value->data_storage) { in bhnd_nvram_val_copy()
599 * value cannot be represented inline */ in bhnd_nvram_val_copy()
606 BHND_NV_PANIC("invalid storage type: %d", value->data_storage); in bhnd_nvram_val_copy()
609 /* Allocate new value copy */ in bhnd_nvram_val_copy()
610 bytes = bhnd_nvram_val_bytes(value, &len, &type); in bhnd_nvram_val_copy()
611 error = bhnd_nvram_val_new(&result, value->fmt, bytes, len, type, in bhnd_nvram_val_copy()
622 * Release a reference to @p value.
626 * @param value The value to be released.
629 bhnd_nvram_val_release(bhnd_nvram_val *value) in bhnd_nvram_val_release() argument
631 BHND_NV_ASSERT(value->refs >= 1, ("value over-released")); in bhnd_nvram_val_release()
633 /* Skip if value is static */ in bhnd_nvram_val_release()
634 if (value->val_storage == BHND_NVRAM_VAL_STORAGE_STATIC) in bhnd_nvram_val_release()
638 if (!refcount_release(&value->refs)) in bhnd_nvram_val_release()
642 switch (value->data_storage) { in bhnd_nvram_val_release()
644 bhnd_nv_free(__DECONST(void *, value->data.ptr)); in bhnd_nvram_val_release()
655 if (value->val_storage == BHND_NVRAM_VAL_STORAGE_DYNAMIC) in bhnd_nvram_val_release()
656 bhnd_nv_free(value); in bhnd_nvram_val_release()
682 /* Can be directly encoded as a zero-length NULL value */ in bhnd_nvram_val_encode_null()
729 /* Fetch (and normalize) boolean value */ in bhnd_nvram_val_encode_bool()
735 /* False can be directly encoded as a zero-length NULL value */ in bhnd_nvram_val_encode_bool()
848 /* Only an empty string may be represented as a NULL value */ in bhnd_nvram_val_encode_string()
995 /* Try to parse the integer value */ in bhnd_nvram_val_encode_string()
1007 "integer value; trailing garbage '%.*s'\n", in bhnd_nvram_val_encode_string()
1072 * Promote integer value to a common 64-bit representation. in bhnd_nvram_val_encode_int()
1146 /* Can't represent negative value */ in bhnd_nvram_val_encode_int()
1159 /* Can't represent positive value */ in bhnd_nvram_val_encode_int()
1172 /* Cannot encode an integer value as NULL */ in bhnd_nvram_val_encode_int()
1309 * Encode the given @p value as @p otype, writing the result to @p outp.
1311 * @param value The value to be encoded.
1312 * @param[out] outp On success, the value will be written to this
1313 * buffer. This argment may be NULL if the value is
1316 * to the actual size of the requested value.
1321 * is too small to hold the encoded value.
1322 * @retval EFTYPE If value coercion from @p value to @p otype is
1324 * @retval ERANGE If value coercion would overflow (or underflow) the
1328 bhnd_nvram_val_encode(bhnd_nvram_val *value, void *outp, size_t *olen, in bhnd_nvram_val_encode() argument
1332 if (value->fmt->op_encode != NULL) in bhnd_nvram_val_encode()
1333 return (value->fmt->op_encode(value, outp, olen, otype)); in bhnd_nvram_val_encode()
1335 return (bhnd_nvram_val_generic_encode(value, outp, olen, otype)); in bhnd_nvram_val_encode()
1339 * Encode the given @p value's element as @p otype, writing the result to
1342 * @param inp The element to be encoded. Must be a value
1347 * @param[out] outp On success, the value will be written to this
1348 * buffer. This argment may be NULL if the value is
1351 * to the actual size of the requested value.
1356 * is too small to hold the encoded value.
1357 * @retval EFTYPE If value coercion from @p value to @p otype is
1359 * @retval ERANGE If value coercion would overflow (or underflow) the
1363 bhnd_nvram_val_encode_elem(bhnd_nvram_val *value, const void *inp, in bhnd_nvram_val_encode_elem() argument
1367 if (value->fmt->op_encode_elem != NULL) { in bhnd_nvram_val_encode_elem()
1368 return (value->fmt->op_encode_elem(value, inp, ilen, outp, in bhnd_nvram_val_encode_elem()
1372 return (bhnd_nvram_val_generic_encode_elem(value, inp, ilen, outp, in bhnd_nvram_val_encode_elem()
1378 * of @p value.
1380 * @param value The value to be queried.
1385 bhnd_nvram_val_bytes(bhnd_nvram_val *value, size_t *olen, in bhnd_nvram_val_bytes() argument
1389 *otype = value->data_type; in bhnd_nvram_val_bytes()
1390 *olen = value->data_len; in bhnd_nvram_val_bytes()
1392 switch (value->data_storage) { in bhnd_nvram_val_bytes()
1397 return (value->data.ptr); in bhnd_nvram_val_bytes()
1401 return (&value->data); in bhnd_nvram_val_bytes()
1404 BHND_NV_PANIC("uninitialized value"); in bhnd_nvram_val_bytes()
1407 BHND_NV_PANIC("unknown storage type: %d", value->data_storage); in bhnd_nvram_val_bytes()
1411 * Iterate over all array elements in @p value.
1413 * @param value The value to be iterated
1414 * @param prev A value pointer previously returned by
1427 bhnd_nvram_val_next(bhnd_nvram_val *value, const void *prev, size_t *olen) in bhnd_nvram_val_next() argument
1430 if (value->fmt->op_next != NULL) in bhnd_nvram_val_next()
1431 return (value->fmt->op_next(value, prev, olen)); in bhnd_nvram_val_next()
1433 return (bhnd_nvram_val_generic_next(value, prev, olen)); in bhnd_nvram_val_next()
1437 * Return the value's data type.
1439 * @param value The value to be queried.
1442 bhnd_nvram_val_type(bhnd_nvram_val *value) in bhnd_nvram_val_type() argument
1444 return (value->data_type); in bhnd_nvram_val_type()
1448 * Return value's element data type.
1450 * @param value The value to be queried.
1453 bhnd_nvram_val_elem_type(bhnd_nvram_val *value) in bhnd_nvram_val_elem_type() argument
1455 return (bhnd_nvram_base_type(value->data_type)); in bhnd_nvram_val_elem_type()
1459 * Return the total number of elements represented by @p value.
1462 bhnd_nvram_val_nelem(bhnd_nvram_val *value) in bhnd_nvram_val_nelem() argument
1470 if (value->fmt->op_nelem != NULL) in bhnd_nvram_val_nelem()
1471 return (value->fmt->op_nelem(value)); in bhnd_nvram_val_nelem()
1481 if (value->fmt->op_next != NULL) { in bhnd_nvram_val_nelem()
1486 while ((next = bhnd_nvram_val_next(value, next, &len)) != NULL) in bhnd_nvram_val_nelem()
1493 bytes = bhnd_nvram_val_bytes(value, &len, &type); in bhnd_nvram_val_nelem()
1509 bhnd_nvram_val_generic_encode(bhnd_nvram_val *value, void *outp, size_t *olen, in bhnd_nvram_val_generic_encode() argument
1524 inp = bhnd_nvram_val_bytes(value, &ilen, &itype); in bhnd_nvram_val_generic_encode()
1543 return (bhnd_nvram_val_encode_elem(value, inp, ilen, outp, olen, in bhnd_nvram_val_generic_encode()
1556 return (bhnd_nvram_val_encode_elem(value, inp, ilen, outp, olen, in bhnd_nvram_val_generic_encode()
1569 while ((next = bhnd_nvram_val_next(value, next, &next_len))) { in bhnd_nvram_val_generic_encode()
1590 error = bhnd_nvram_val_encode_elem(value, next, next_len, in bhnd_nvram_val_generic_encode()
1625 bhnd_nvram_val_generic_encode_elem(bhnd_nvram_val *value, const void *inp, in bhnd_nvram_val_generic_encode_elem() argument
1630 itype = bhnd_nvram_val_elem_type(value); in bhnd_nvram_val_generic_encode_elem()
1669 bhnd_nvram_val_generic_next(bhnd_nvram_val *value, const void *prev, in bhnd_nvram_val_generic_next() argument
1677 inp = bhnd_nvram_val_bytes(value, &ilen, &itype); in bhnd_nvram_val_generic_next()
1682 * Initialize the representation of @p value with @p ptr.
1684 * @param value The value to be initialized.
1688 * @param flags Value flags.
1698 bhnd_nvram_val_set(bhnd_nvram_val *value, const void *inp, size_t ilen, in bhnd_nvram_val_set() argument
1704 BHND_NVRAM_VAL_ASSERT_EMPTY(value); in bhnd_nvram_val_set()
1715 value->data_storage = BHND_NVRAM_VAL_DATA_EXT_STATIC; in bhnd_nvram_val_set()
1717 value->data_storage = BHND_NVRAM_VAL_DATA_EXT_WEAK; in bhnd_nvram_val_set()
1719 value->data.ptr = inp; in bhnd_nvram_val_set()
1720 value->data_type = itype; in bhnd_nvram_val_set()
1721 value->data_len = ilen; in bhnd_nvram_val_set()
1726 bytes = bhnd_nvram_val_alloc_bytes(value, ilen, itype, flags); in bhnd_nvram_val_set()
1737 * Initialize the internal inline representation of @p value with a copy of
1743 * @param value The value to be initialized.
1756 bhnd_nvram_val_set_inline(bhnd_nvram_val *value, const void *inp, size_t ilen, in bhnd_nvram_val_set_inline() argument
1759 BHND_NVRAM_VAL_ASSERT_EMPTY(value); in bhnd_nvram_val_set_inline()
1762 value->data_len = ilen; \ in bhnd_nvram_val_set_inline()
1763 value->data_type = itype; \ in bhnd_nvram_val_set_inline()
1771 value->data._dest[0] = *(const _type *)inp; \ in bhnd_nvram_val_set_inline()
1780 if (ilen > nitems(value->data. _dest)) \ in bhnd_nvram_val_set_inline()
1786 memcpy(&value->data._dest, inp, ilen); \ in bhnd_nvram_val_set_inline()
1788 memcpy(&value->data._dest, inp, ilen); \ in bhnd_nvram_val_set_inline()
1862 if (ilen > sizeof(value->data.ch)) in bhnd_nvram_val_set_inline()
1866 memcpy(&value->data.ch, inp, ilen); in bhnd_nvram_val_set_inline()
1881 * Initialize the internal representation of @p value with a buffer allocation
1888 * @param value The value to be initialized.
1891 * @param flags Value flags.
1895 * @retval NULL If @p value is an externally allocated instance.
1898 bhnd_nvram_val_alloc_bytes(bhnd_nvram_val *value, size_t ilen, in bhnd_nvram_val_alloc_bytes() argument
1903 BHND_NVRAM_VAL_ASSERT_EMPTY(value); in bhnd_nvram_val_alloc_bytes()
1906 if (bhnd_nvram_val_set_inline(value, NULL, ilen, itype) == 0) { in bhnd_nvram_val_alloc_bytes()
1907 BHND_NV_ASSERT(sizeof(value->data) >= ilen, in bhnd_nvram_val_alloc_bytes()
1910 value->data_type = itype; in bhnd_nvram_val_alloc_bytes()
1911 value->data_len = ilen; in bhnd_nvram_val_alloc_bytes()
1912 value->data_storage = BHND_NVRAM_VAL_DATA_INLINE; in bhnd_nvram_val_alloc_bytes()
1913 return (&value->data); in bhnd_nvram_val_alloc_bytes()
1924 value->data.ptr = ptr; in bhnd_nvram_val_alloc_bytes()
1925 value->data_len = ilen; in bhnd_nvram_val_alloc_bytes()
1926 value->data_type = itype; in bhnd_nvram_val_alloc_bytes()
1927 value->data_storage = BHND_NVRAM_VAL_DATA_EXT_ALLOC; in bhnd_nvram_val_alloc_bytes()