10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55345Seschrock * Common Development and Distribution License (the "License"). 65345Seschrock * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12967Sgavin.maltby@oracle.com * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_NVPAIR_H 260Sstevel@tonic-gate #define _SYS_NVPAIR_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/errno.h> 300Sstevel@tonic-gate #include <sys/va_list.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_BOOT) 330Sstevel@tonic-gate #include <sys/kmem.h> 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate typedef enum { 410Sstevel@tonic-gate DATA_TYPE_UNKNOWN = 0, 420Sstevel@tonic-gate DATA_TYPE_BOOLEAN, 430Sstevel@tonic-gate DATA_TYPE_BYTE, 440Sstevel@tonic-gate DATA_TYPE_INT16, 450Sstevel@tonic-gate DATA_TYPE_UINT16, 460Sstevel@tonic-gate DATA_TYPE_INT32, 470Sstevel@tonic-gate DATA_TYPE_UINT32, 480Sstevel@tonic-gate DATA_TYPE_INT64, 490Sstevel@tonic-gate DATA_TYPE_UINT64, 500Sstevel@tonic-gate DATA_TYPE_STRING, 510Sstevel@tonic-gate DATA_TYPE_BYTE_ARRAY, 520Sstevel@tonic-gate DATA_TYPE_INT16_ARRAY, 530Sstevel@tonic-gate DATA_TYPE_UINT16_ARRAY, 540Sstevel@tonic-gate DATA_TYPE_INT32_ARRAY, 550Sstevel@tonic-gate DATA_TYPE_UINT32_ARRAY, 560Sstevel@tonic-gate DATA_TYPE_INT64_ARRAY, 570Sstevel@tonic-gate DATA_TYPE_UINT64_ARRAY, 580Sstevel@tonic-gate DATA_TYPE_STRING_ARRAY, 590Sstevel@tonic-gate DATA_TYPE_HRTIME, 600Sstevel@tonic-gate DATA_TYPE_NVLIST, 610Sstevel@tonic-gate DATA_TYPE_NVLIST_ARRAY, 620Sstevel@tonic-gate DATA_TYPE_BOOLEAN_VALUE, 630Sstevel@tonic-gate DATA_TYPE_INT8, 640Sstevel@tonic-gate DATA_TYPE_UINT8, 650Sstevel@tonic-gate DATA_TYPE_BOOLEAN_ARRAY, 660Sstevel@tonic-gate DATA_TYPE_INT8_ARRAY, 677243Srobj #if !defined(_KERNEL) 687243Srobj DATA_TYPE_UINT8_ARRAY, 697243Srobj DATA_TYPE_DOUBLE 707243Srobj #else 710Sstevel@tonic-gate DATA_TYPE_UINT8_ARRAY 727243Srobj #endif 730Sstevel@tonic-gate } data_type_t; 740Sstevel@tonic-gate 750Sstevel@tonic-gate typedef struct nvpair { 760Sstevel@tonic-gate int32_t nvp_size; /* size of this nvpair */ 770Sstevel@tonic-gate int16_t nvp_name_sz; /* length of name string */ 780Sstevel@tonic-gate int16_t nvp_reserve; /* not used */ 790Sstevel@tonic-gate int32_t nvp_value_elem; /* number of elements for array types */ 800Sstevel@tonic-gate data_type_t nvp_type; /* type of value */ 810Sstevel@tonic-gate /* name string */ 820Sstevel@tonic-gate /* aligned ptr array for string arrays */ 830Sstevel@tonic-gate /* aligned array of data for value */ 840Sstevel@tonic-gate } nvpair_t; 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* nvlist header */ 870Sstevel@tonic-gate typedef struct nvlist { 880Sstevel@tonic-gate int32_t nvl_version; 890Sstevel@tonic-gate uint32_t nvl_nvflag; /* persistent flags */ 900Sstevel@tonic-gate uint64_t nvl_priv; /* ptr to private data if not packed */ 910Sstevel@tonic-gate uint32_t nvl_flag; 920Sstevel@tonic-gate int32_t nvl_pad; /* currently not used, for alignment */ 930Sstevel@tonic-gate } nvlist_t; 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* nvp implementation version */ 960Sstevel@tonic-gate #define NV_VERSION 0 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* nvlist pack encoding */ 990Sstevel@tonic-gate #define NV_ENCODE_NATIVE 0 1000Sstevel@tonic-gate #define NV_ENCODE_XDR 1 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* nvlist persistent unique name flags, stored in nvl_nvflags */ 1030Sstevel@tonic-gate #define NV_UNIQUE_NAME 0x1 1040Sstevel@tonic-gate #define NV_UNIQUE_NAME_TYPE 0x2 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* nvlist lookup pairs related flags */ 1070Sstevel@tonic-gate #define NV_FLAG_NOENTOK 0x1 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* convenience macros */ 1100Sstevel@tonic-gate #define NV_ALIGN(x) (((ulong_t)(x) + 7ul) & ~7ul) 1110Sstevel@tonic-gate #define NV_ALIGN4(x) (((x) + 3) & ~3) 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define NVP_SIZE(nvp) ((nvp)->nvp_size) 1140Sstevel@tonic-gate #define NVP_NAME(nvp) ((char *)(nvp) + sizeof (nvpair_t)) 1150Sstevel@tonic-gate #define NVP_TYPE(nvp) ((nvp)->nvp_type) 1160Sstevel@tonic-gate #define NVP_NELEM(nvp) ((nvp)->nvp_value_elem) 1170Sstevel@tonic-gate #define NVP_VALUE(nvp) ((char *)(nvp) + NV_ALIGN(sizeof (nvpair_t) \ 1180Sstevel@tonic-gate + (nvp)->nvp_name_sz)) 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate #define NVL_VERSION(nvl) ((nvl)->nvl_version) 1210Sstevel@tonic-gate #define NVL_SIZE(nvl) ((nvl)->nvl_size) 1220Sstevel@tonic-gate #define NVL_FLAG(nvl) ((nvl)->nvl_flag) 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* NV allocator framework */ 1250Sstevel@tonic-gate typedef struct nv_alloc_ops nv_alloc_ops_t; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate typedef struct nv_alloc { 1280Sstevel@tonic-gate const nv_alloc_ops_t *nva_ops; 1290Sstevel@tonic-gate void *nva_arg; 1300Sstevel@tonic-gate } nv_alloc_t; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate struct nv_alloc_ops { 1330Sstevel@tonic-gate int (*nv_ao_init)(nv_alloc_t *, __va_list); 1340Sstevel@tonic-gate void (*nv_ao_fini)(nv_alloc_t *); 1350Sstevel@tonic-gate void *(*nv_ao_alloc)(nv_alloc_t *, size_t); 1360Sstevel@tonic-gate void (*nv_ao_free)(nv_alloc_t *, void *, size_t); 1370Sstevel@tonic-gate void (*nv_ao_reset)(nv_alloc_t *); 1380Sstevel@tonic-gate }; 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate extern const nv_alloc_ops_t *nv_fixed_ops; 1410Sstevel@tonic-gate extern nv_alloc_t *nv_alloc_nosleep; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_BOOT) 1440Sstevel@tonic-gate extern nv_alloc_t *nv_alloc_sleep; 1450Sstevel@tonic-gate #endif 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate int nv_alloc_init(nv_alloc_t *, const nv_alloc_ops_t *, /* args */ ...); 1480Sstevel@tonic-gate void nv_alloc_reset(nv_alloc_t *); 1490Sstevel@tonic-gate void nv_alloc_fini(nv_alloc_t *); 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* list management */ 1520Sstevel@tonic-gate int nvlist_alloc(nvlist_t **, uint_t, int); 1530Sstevel@tonic-gate void nvlist_free(nvlist_t *); 1540Sstevel@tonic-gate int nvlist_size(nvlist_t *, size_t *, int); 1550Sstevel@tonic-gate int nvlist_pack(nvlist_t *, char **, size_t *, int, int); 1560Sstevel@tonic-gate int nvlist_unpack(char *, size_t, nvlist_t **, int); 1570Sstevel@tonic-gate int nvlist_dup(nvlist_t *, nvlist_t **, int); 1580Sstevel@tonic-gate int nvlist_merge(nvlist_t *, nvlist_t *, int); 1590Sstevel@tonic-gate 160*12967Sgavin.maltby@oracle.com uint_t nvlist_nvflag(nvlist_t *); 161*12967Sgavin.maltby@oracle.com 1620Sstevel@tonic-gate int nvlist_xalloc(nvlist_t **, uint_t, nv_alloc_t *); 1630Sstevel@tonic-gate int nvlist_xpack(nvlist_t *, char **, size_t *, int, nv_alloc_t *); 1640Sstevel@tonic-gate int nvlist_xunpack(char *, size_t, nvlist_t **, nv_alloc_t *); 1650Sstevel@tonic-gate int nvlist_xdup(nvlist_t *, nvlist_t **, nv_alloc_t *); 1660Sstevel@tonic-gate nv_alloc_t *nvlist_lookup_nv_alloc(nvlist_t *); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate int nvlist_add_nvpair(nvlist_t *, nvpair_t *); 1690Sstevel@tonic-gate int nvlist_add_boolean(nvlist_t *, const char *); 1700Sstevel@tonic-gate int nvlist_add_boolean_value(nvlist_t *, const char *, boolean_t); 1710Sstevel@tonic-gate int nvlist_add_byte(nvlist_t *, const char *, uchar_t); 1720Sstevel@tonic-gate int nvlist_add_int8(nvlist_t *, const char *, int8_t); 1730Sstevel@tonic-gate int nvlist_add_uint8(nvlist_t *, const char *, uint8_t); 1740Sstevel@tonic-gate int nvlist_add_int16(nvlist_t *, const char *, int16_t); 1750Sstevel@tonic-gate int nvlist_add_uint16(nvlist_t *, const char *, uint16_t); 1760Sstevel@tonic-gate int nvlist_add_int32(nvlist_t *, const char *, int32_t); 1770Sstevel@tonic-gate int nvlist_add_uint32(nvlist_t *, const char *, uint32_t); 1780Sstevel@tonic-gate int nvlist_add_int64(nvlist_t *, const char *, int64_t); 1790Sstevel@tonic-gate int nvlist_add_uint64(nvlist_t *, const char *, uint64_t); 1800Sstevel@tonic-gate int nvlist_add_string(nvlist_t *, const char *, const char *); 1810Sstevel@tonic-gate int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); 1820Sstevel@tonic-gate int nvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *, uint_t); 1830Sstevel@tonic-gate int nvlist_add_byte_array(nvlist_t *, const char *, uchar_t *, uint_t); 1840Sstevel@tonic-gate int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint_t); 1850Sstevel@tonic-gate int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint_t); 1860Sstevel@tonic-gate int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint_t); 1870Sstevel@tonic-gate int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint_t); 1880Sstevel@tonic-gate int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint_t); 1890Sstevel@tonic-gate int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint_t); 1900Sstevel@tonic-gate int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint_t); 1910Sstevel@tonic-gate int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint_t); 1920Sstevel@tonic-gate int nvlist_add_string_array(nvlist_t *, const char *, char *const *, uint_t); 1930Sstevel@tonic-gate int nvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint_t); 1940Sstevel@tonic-gate int nvlist_add_hrtime(nvlist_t *, const char *, hrtime_t); 1957243Srobj #if !defined(_KERNEL) 1967243Srobj int nvlist_add_double(nvlist_t *, const char *, double); 1977243Srobj #endif 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate int nvlist_remove(nvlist_t *, const char *, data_type_t); 2000Sstevel@tonic-gate int nvlist_remove_all(nvlist_t *, const char *); 20111022STom.Erickson@Sun.COM int nvlist_remove_nvpair(nvlist_t *, nvpair_t *); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate int nvlist_lookup_boolean(nvlist_t *, const char *); 2040Sstevel@tonic-gate int nvlist_lookup_boolean_value(nvlist_t *, const char *, boolean_t *); 2050Sstevel@tonic-gate int nvlist_lookup_byte(nvlist_t *, const char *, uchar_t *); 2060Sstevel@tonic-gate int nvlist_lookup_int8(nvlist_t *, const char *, int8_t *); 2070Sstevel@tonic-gate int nvlist_lookup_uint8(nvlist_t *, const char *, uint8_t *); 2080Sstevel@tonic-gate int nvlist_lookup_int16(nvlist_t *, const char *, int16_t *); 2090Sstevel@tonic-gate int nvlist_lookup_uint16(nvlist_t *, const char *, uint16_t *); 2100Sstevel@tonic-gate int nvlist_lookup_int32(nvlist_t *, const char *, int32_t *); 2110Sstevel@tonic-gate int nvlist_lookup_uint32(nvlist_t *, const char *, uint32_t *); 2120Sstevel@tonic-gate int nvlist_lookup_int64(nvlist_t *, const char *, int64_t *); 2130Sstevel@tonic-gate int nvlist_lookup_uint64(nvlist_t *, const char *, uint64_t *); 2140Sstevel@tonic-gate int nvlist_lookup_string(nvlist_t *, const char *, char **); 2150Sstevel@tonic-gate int nvlist_lookup_nvlist(nvlist_t *, const char *, nvlist_t **); 2160Sstevel@tonic-gate int nvlist_lookup_boolean_array(nvlist_t *, const char *, 2170Sstevel@tonic-gate boolean_t **, uint_t *); 2180Sstevel@tonic-gate int nvlist_lookup_byte_array(nvlist_t *, const char *, uchar_t **, uint_t *); 2190Sstevel@tonic-gate int nvlist_lookup_int8_array(nvlist_t *, const char *, int8_t **, uint_t *); 2200Sstevel@tonic-gate int nvlist_lookup_uint8_array(nvlist_t *, const char *, uint8_t **, uint_t *); 2210Sstevel@tonic-gate int nvlist_lookup_int16_array(nvlist_t *, const char *, int16_t **, uint_t *); 2220Sstevel@tonic-gate int nvlist_lookup_uint16_array(nvlist_t *, const char *, uint16_t **, uint_t *); 2230Sstevel@tonic-gate int nvlist_lookup_int32_array(nvlist_t *, const char *, int32_t **, uint_t *); 2240Sstevel@tonic-gate int nvlist_lookup_uint32_array(nvlist_t *, const char *, uint32_t **, uint_t *); 2250Sstevel@tonic-gate int nvlist_lookup_int64_array(nvlist_t *, const char *, int64_t **, uint_t *); 2260Sstevel@tonic-gate int nvlist_lookup_uint64_array(nvlist_t *, const char *, uint64_t **, uint_t *); 2270Sstevel@tonic-gate int nvlist_lookup_string_array(nvlist_t *, const char *, char ***, uint_t *); 2280Sstevel@tonic-gate int nvlist_lookup_nvlist_array(nvlist_t *, const char *, 2290Sstevel@tonic-gate nvlist_t ***, uint_t *); 2300Sstevel@tonic-gate int nvlist_lookup_hrtime(nvlist_t *, const char *, hrtime_t *); 2316640Scth int nvlist_lookup_pairs(nvlist_t *, int, ...); 2327243Srobj #if !defined(_KERNEL) 2337243Srobj int nvlist_lookup_double(nvlist_t *, const char *, double *); 2347243Srobj #endif 2350Sstevel@tonic-gate 2366640Scth int nvlist_lookup_nvpair(nvlist_t *, const char *, nvpair_t **); 2376640Scth int nvlist_lookup_nvpair_embedded_index(nvlist_t *, const char *, nvpair_t **, 2386640Scth int *, char **); 2396640Scth boolean_t nvlist_exists(nvlist_t *, const char *); 24011022STom.Erickson@Sun.COM boolean_t nvlist_empty(nvlist_t *); 2415345Seschrock 2420Sstevel@tonic-gate /* processing nvpair */ 2436640Scth nvpair_t *nvlist_next_nvpair(nvlist_t *, nvpair_t *); 24411022STom.Erickson@Sun.COM nvpair_t *nvlist_prev_nvpair(nvlist_t *, nvpair_t *); 2450Sstevel@tonic-gate char *nvpair_name(nvpair_t *); 2460Sstevel@tonic-gate data_type_t nvpair_type(nvpair_t *); 2476640Scth int nvpair_type_is_array(nvpair_t *); 2480Sstevel@tonic-gate int nvpair_value_boolean_value(nvpair_t *, boolean_t *); 2490Sstevel@tonic-gate int nvpair_value_byte(nvpair_t *, uchar_t *); 2500Sstevel@tonic-gate int nvpair_value_int8(nvpair_t *, int8_t *); 2510Sstevel@tonic-gate int nvpair_value_uint8(nvpair_t *, uint8_t *); 2520Sstevel@tonic-gate int nvpair_value_int16(nvpair_t *, int16_t *); 2530Sstevel@tonic-gate int nvpair_value_uint16(nvpair_t *, uint16_t *); 2540Sstevel@tonic-gate int nvpair_value_int32(nvpair_t *, int32_t *); 2550Sstevel@tonic-gate int nvpair_value_uint32(nvpair_t *, uint32_t *); 2560Sstevel@tonic-gate int nvpair_value_int64(nvpair_t *, int64_t *); 2570Sstevel@tonic-gate int nvpair_value_uint64(nvpair_t *, uint64_t *); 2580Sstevel@tonic-gate int nvpair_value_string(nvpair_t *, char **); 2590Sstevel@tonic-gate int nvpair_value_nvlist(nvpair_t *, nvlist_t **); 2600Sstevel@tonic-gate int nvpair_value_boolean_array(nvpair_t *, boolean_t **, uint_t *); 2610Sstevel@tonic-gate int nvpair_value_byte_array(nvpair_t *, uchar_t **, uint_t *); 2620Sstevel@tonic-gate int nvpair_value_int8_array(nvpair_t *, int8_t **, uint_t *); 2630Sstevel@tonic-gate int nvpair_value_uint8_array(nvpair_t *, uint8_t **, uint_t *); 2640Sstevel@tonic-gate int nvpair_value_int16_array(nvpair_t *, int16_t **, uint_t *); 2650Sstevel@tonic-gate int nvpair_value_uint16_array(nvpair_t *, uint16_t **, uint_t *); 2660Sstevel@tonic-gate int nvpair_value_int32_array(nvpair_t *, int32_t **, uint_t *); 2670Sstevel@tonic-gate int nvpair_value_uint32_array(nvpair_t *, uint32_t **, uint_t *); 2680Sstevel@tonic-gate int nvpair_value_int64_array(nvpair_t *, int64_t **, uint_t *); 2690Sstevel@tonic-gate int nvpair_value_uint64_array(nvpair_t *, uint64_t **, uint_t *); 2700Sstevel@tonic-gate int nvpair_value_string_array(nvpair_t *, char ***, uint_t *); 2710Sstevel@tonic-gate int nvpair_value_nvlist_array(nvpair_t *, nvlist_t ***, uint_t *); 2720Sstevel@tonic-gate int nvpair_value_hrtime(nvpair_t *, hrtime_t *); 2737243Srobj #if !defined(_KERNEL) 2747243Srobj int nvpair_value_double(nvpair_t *, double *); 2757243Srobj #endif 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate #ifdef __cplusplus 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate #endif 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate #endif /* _SYS_NVPAIR_H */ 282