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 56640Scth * Common Development and Distribution License (the "License"). 66640Scth * 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 _LIBNVPAIR_H 260Sstevel@tonic-gate #define _LIBNVPAIR_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/nvpair.h> 290Sstevel@tonic-gate #include <stdlib.h> 300Sstevel@tonic-gate #include <stdio.h> 316640Scth #include <regex.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifdef __cplusplus 340Sstevel@tonic-gate extern "C" { 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 37*12967Sgavin.maltby@oracle.com /* 38*12967Sgavin.maltby@oracle.com * All interfaces described in this file are private to Solaris, and 39*12967Sgavin.maltby@oracle.com * are subject to change at any time and without notice. The public 40*12967Sgavin.maltby@oracle.com * nvlist/nvpair interfaces, as documented in manpage sections 3NVPAIR, 41*12967Sgavin.maltby@oracle.com * are all imported from <sys/nvpair.h> included above. 42*12967Sgavin.maltby@oracle.com */ 43*12967Sgavin.maltby@oracle.com 44*12967Sgavin.maltby@oracle.com extern int nvpair_value_match(nvpair_t *, int, char *, char **); 45*12967Sgavin.maltby@oracle.com extern int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *, 46*12967Sgavin.maltby@oracle.com char **); 47*12967Sgavin.maltby@oracle.com 48*12967Sgavin.maltby@oracle.com extern void nvlist_print(FILE *, nvlist_t *); 49*12967Sgavin.maltby@oracle.com extern void dump_nvlist(nvlist_t *, int); 50*12967Sgavin.maltby@oracle.com 51*12967Sgavin.maltby@oracle.com /* 52*12967Sgavin.maltby@oracle.com * Private nvlist printing interface that allows the caller some control 53*12967Sgavin.maltby@oracle.com * over output rendering (as opposed to nvlist_print and dump_nvlist). 54*12967Sgavin.maltby@oracle.com * 55*12967Sgavin.maltby@oracle.com * Obtain an opaque nvlist_prtctl_t cookie using nvlist_prtctl_alloc 56*12967Sgavin.maltby@oracle.com * (NULL on failure); on return the cookie is set up for default formatting 57*12967Sgavin.maltby@oracle.com * and rendering. Quote the cookie in subsequent customisation functions and 58*12967Sgavin.maltby@oracle.com * then pass the cookie to nvlist_prt to render the nvlist. Finally, 59*12967Sgavin.maltby@oracle.com * use nvlist_prtctl_free to release the cookie. 60*12967Sgavin.maltby@oracle.com * 61*12967Sgavin.maltby@oracle.com * For all nvlist_lookup_xxx and nvlist_lookup_xxx_array functions 62*12967Sgavin.maltby@oracle.com * we have a corresponding brace of functions that appoint replacement 63*12967Sgavin.maltby@oracle.com * rendering functions: 64*12967Sgavin.maltby@oracle.com * 65*12967Sgavin.maltby@oracle.com * extern void nvlist_prtctl_xxx(nvlist_prtctl_t, 66*12967Sgavin.maltby@oracle.com * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 67*12967Sgavin.maltby@oracle.com * xxxtype value)) 68*12967Sgavin.maltby@oracle.com * 69*12967Sgavin.maltby@oracle.com * and 70*12967Sgavin.maltby@oracle.com * 71*12967Sgavin.maltby@oracle.com * extern void nvlist_prtctl_xxx_array(nvlist_prtctl_t, 72*12967Sgavin.maltby@oracle.com * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 73*12967Sgavin.maltby@oracle.com * xxxtype value, uint_t count)) 74*12967Sgavin.maltby@oracle.com * 75*12967Sgavin.maltby@oracle.com * where xxxtype is the C datatype corresponding to xxx, eg int8_t for "int8" 76*12967Sgavin.maltby@oracle.com * and char * for "string". The function that is appointed to render the 77*12967Sgavin.maltby@oracle.com * specified datatype receives as arguments the cookie, the nvlist 78*12967Sgavin.maltby@oracle.com * member name, the value of that member (or a pointer for array function), 79*12967Sgavin.maltby@oracle.com * and (for array rendering functions) a count of the number of elements. 80*12967Sgavin.maltby@oracle.com */ 81*12967Sgavin.maltby@oracle.com 82*12967Sgavin.maltby@oracle.com typedef struct nvlist_prtctl *nvlist_prtctl_t; /* opaque */ 83*12967Sgavin.maltby@oracle.com 84*12967Sgavin.maltby@oracle.com enum nvlist_indent_mode { 85*12967Sgavin.maltby@oracle.com NVLIST_INDENT_ABS, /* Absolute indentation */ 86*12967Sgavin.maltby@oracle.com NVLIST_INDENT_TABBED /* Indent with tabstops */ 87*12967Sgavin.maltby@oracle.com }; 88*12967Sgavin.maltby@oracle.com 89*12967Sgavin.maltby@oracle.com extern nvlist_prtctl_t nvlist_prtctl_alloc(void); 90*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_free(nvlist_prtctl_t); 91*12967Sgavin.maltby@oracle.com extern void nvlist_prt(nvlist_t *, nvlist_prtctl_t); 92*12967Sgavin.maltby@oracle.com 93*12967Sgavin.maltby@oracle.com /* Output stream */ 94*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *); 95*12967Sgavin.maltby@oracle.com extern FILE *nvlist_prtctl_getdest(nvlist_prtctl_t); 96*12967Sgavin.maltby@oracle.com 97*12967Sgavin.maltby@oracle.com /* Indentation mode, start indent, indent increment; default tabbed/0/1 */ 98*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_setindent(nvlist_prtctl_t, enum nvlist_indent_mode, 99*12967Sgavin.maltby@oracle.com int, int); 100*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_doindent(nvlist_prtctl_t, int); 101*12967Sgavin.maltby@oracle.com 102*12967Sgavin.maltby@oracle.com enum nvlist_prtctl_fmt { 103*12967Sgavin.maltby@oracle.com NVLIST_FMT_MEMBER_NAME, /* name fmt; default "%s = " */ 104*12967Sgavin.maltby@oracle.com NVLIST_FMT_MEMBER_POSTAMBLE, /* after nvlist member; default "\n" */ 105*12967Sgavin.maltby@oracle.com NVLIST_FMT_BTWN_ARRAY /* between array members; default " " */ 106*12967Sgavin.maltby@oracle.com }; 107*12967Sgavin.maltby@oracle.com 108*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, 109*12967Sgavin.maltby@oracle.com const char *); 110*12967Sgavin.maltby@oracle.com extern void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, ...); 111*12967Sgavin.maltby@oracle.com 112*12967Sgavin.maltby@oracle.com /* 113*12967Sgavin.maltby@oracle.com * Function prototypes for interfaces that appoint a new rendering function 114*12967Sgavin.maltby@oracle.com * for single-valued nvlist members. 115*12967Sgavin.maltby@oracle.com * 116*12967Sgavin.maltby@oracle.com * A replacement function receives arguments as follows: 117*12967Sgavin.maltby@oracle.com * 118*12967Sgavin.maltby@oracle.com * nvlist_prtctl_t Print control structure; do not change preferences 119*12967Sgavin.maltby@oracle.com * for this object from a print callback function. 120*12967Sgavin.maltby@oracle.com * 121*12967Sgavin.maltby@oracle.com * void * The function-private cookie argument registered 122*12967Sgavin.maltby@oracle.com * when the replacement function was appointed. 123*12967Sgavin.maltby@oracle.com * 124*12967Sgavin.maltby@oracle.com * nvlist_t * The full nvlist that is being processed. The 125*12967Sgavin.maltby@oracle.com * rendering function is called to render a single 126*12967Sgavin.maltby@oracle.com * member (name and value passed as below) but it may 127*12967Sgavin.maltby@oracle.com * want to reference or incorporate other aspects of 128*12967Sgavin.maltby@oracle.com * the full nvlist. 129*12967Sgavin.maltby@oracle.com * 130*12967Sgavin.maltby@oracle.com * const char * Member name to render 131*12967Sgavin.maltby@oracle.com * 132*12967Sgavin.maltby@oracle.com * valtype Value of the member to render 133*12967Sgavin.maltby@oracle.com * 134*12967Sgavin.maltby@oracle.com * The function must return non-zero if it has rendered output for this 135*12967Sgavin.maltby@oracle.com * member, or 0 if it wants to default to standard rendering for this 136*12967Sgavin.maltby@oracle.com * one member. 137*12967Sgavin.maltby@oracle.com */ 138*12967Sgavin.maltby@oracle.com 139*12967Sgavin.maltby@oracle.com #define NVLIST_PRINTCTL_SVDECL(funcname, valtype) \ 140*12967Sgavin.maltby@oracle.com extern void funcname(nvlist_prtctl_t, \ 141*12967Sgavin.maltby@oracle.com int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, valtype), \ 142*12967Sgavin.maltby@oracle.com void *) 143*12967Sgavin.maltby@oracle.com 144*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean, int); 145*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean_value, boolean_t); 146*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_byte, uchar_t); 147*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int8, int8_t); 148*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint8, uint8_t); 149*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int16, int16_t); 150*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint16, uint16_t); 151*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int32, int32_t); 152*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint32, uint32_t); 153*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int64, int64_t); 154*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint64, uint64_t); 155*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_double, double); 156*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_string, char *); 157*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_hrtime, hrtime_t); 158*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_nvlist, nvlist_t *); 159*12967Sgavin.maltby@oracle.com 160*12967Sgavin.maltby@oracle.com #undef NVLIST_PRINTCTL_SVDECL /* was just for "clarity" above */ 161*12967Sgavin.maltby@oracle.com 162*12967Sgavin.maltby@oracle.com /* 163*12967Sgavin.maltby@oracle.com * Function prototypes for interfaces that appoint a new rendering function 164*12967Sgavin.maltby@oracle.com * for array-valued nvlist members. 165*12967Sgavin.maltby@oracle.com * 166*12967Sgavin.maltby@oracle.com * One additional argument is taken: uint_t for the number of array elements 167*12967Sgavin.maltby@oracle.com * 168*12967Sgavin.maltby@oracle.com * Return values as above. 169*12967Sgavin.maltby@oracle.com */ 170*12967Sgavin.maltby@oracle.com #define NVLIST_PRINTCTL_AVDECL(funcname, vtype) \ 171*12967Sgavin.maltby@oracle.com extern void funcname(nvlist_prtctl_t, \ 172*12967Sgavin.maltby@oracle.com int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, vtype, uint_t), \ 173*12967Sgavin.maltby@oracle.com void *) 174*12967Sgavin.maltby@oracle.com 175*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_boolean_array, boolean_t *); 176*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_byte_array, uchar_t *); 177*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int8_array, int8_t *); 178*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint8_array, uint8_t *); 179*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int16_array, int16_t *); 180*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint16_array, uint16_t *); 181*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int32_array, int32_t *); 182*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint32_array, uint32_t *); 183*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int64_array, int64_t *); 184*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint64_array, uint64_t *); 185*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_string_array, char **); 186*12967Sgavin.maltby@oracle.com NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_nvlist_array, nvlist_t **); 187*12967Sgavin.maltby@oracle.com 188*12967Sgavin.maltby@oracle.com #undef NVLIST_PRINTCTL_AVDECL /* was just for "clarity" above */ 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate #ifdef __cplusplus 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate #endif 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate #endif /* _LIBNVPAIR_H */ 195