17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5602ca9eaScth * Common Development and Distribution License (the "License"). 6602ca9eaScth * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*f6e214c7SGavin Maltby * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _LIBNVPAIR_H 267c478bd9Sstevel@tonic-gate #define _LIBNVPAIR_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/nvpair.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <stdio.h> 31602ca9eaScth #include <regex.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 37*f6e214c7SGavin Maltby /* 38*f6e214c7SGavin Maltby * All interfaces described in this file are private to Solaris, and 39*f6e214c7SGavin Maltby * are subject to change at any time and without notice. The public 40*f6e214c7SGavin Maltby * nvlist/nvpair interfaces, as documented in manpage sections 3NVPAIR, 41*f6e214c7SGavin Maltby * are all imported from <sys/nvpair.h> included above. 42*f6e214c7SGavin Maltby */ 43*f6e214c7SGavin Maltby 44*f6e214c7SGavin Maltby extern int nvpair_value_match(nvpair_t *, int, char *, char **); 45*f6e214c7SGavin Maltby extern int nvpair_value_match_regex(nvpair_t *, int, char *, regex_t *, 46*f6e214c7SGavin Maltby char **); 47*f6e214c7SGavin Maltby 48*f6e214c7SGavin Maltby extern void nvlist_print(FILE *, nvlist_t *); 49*f6e214c7SGavin Maltby extern void dump_nvlist(nvlist_t *, int); 50*f6e214c7SGavin Maltby 51*f6e214c7SGavin Maltby /* 52*f6e214c7SGavin Maltby * Private nvlist printing interface that allows the caller some control 53*f6e214c7SGavin Maltby * over output rendering (as opposed to nvlist_print and dump_nvlist). 54*f6e214c7SGavin Maltby * 55*f6e214c7SGavin Maltby * Obtain an opaque nvlist_prtctl_t cookie using nvlist_prtctl_alloc 56*f6e214c7SGavin Maltby * (NULL on failure); on return the cookie is set up for default formatting 57*f6e214c7SGavin Maltby * and rendering. Quote the cookie in subsequent customisation functions and 58*f6e214c7SGavin Maltby * then pass the cookie to nvlist_prt to render the nvlist. Finally, 59*f6e214c7SGavin Maltby * use nvlist_prtctl_free to release the cookie. 60*f6e214c7SGavin Maltby * 61*f6e214c7SGavin Maltby * For all nvlist_lookup_xxx and nvlist_lookup_xxx_array functions 62*f6e214c7SGavin Maltby * we have a corresponding brace of functions that appoint replacement 63*f6e214c7SGavin Maltby * rendering functions: 64*f6e214c7SGavin Maltby * 65*f6e214c7SGavin Maltby * extern void nvlist_prtctl_xxx(nvlist_prtctl_t, 66*f6e214c7SGavin Maltby * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 67*f6e214c7SGavin Maltby * xxxtype value)) 68*f6e214c7SGavin Maltby * 69*f6e214c7SGavin Maltby * and 70*f6e214c7SGavin Maltby * 71*f6e214c7SGavin Maltby * extern void nvlist_prtctl_xxx_array(nvlist_prtctl_t, 72*f6e214c7SGavin Maltby * void (*)(nvlist_prtctl_t ctl, void *private, const char *name, 73*f6e214c7SGavin Maltby * xxxtype value, uint_t count)) 74*f6e214c7SGavin Maltby * 75*f6e214c7SGavin Maltby * where xxxtype is the C datatype corresponding to xxx, eg int8_t for "int8" 76*f6e214c7SGavin Maltby * and char * for "string". The function that is appointed to render the 77*f6e214c7SGavin Maltby * specified datatype receives as arguments the cookie, the nvlist 78*f6e214c7SGavin Maltby * member name, the value of that member (or a pointer for array function), 79*f6e214c7SGavin Maltby * and (for array rendering functions) a count of the number of elements. 80*f6e214c7SGavin Maltby */ 81*f6e214c7SGavin Maltby 82*f6e214c7SGavin Maltby typedef struct nvlist_prtctl *nvlist_prtctl_t; /* opaque */ 83*f6e214c7SGavin Maltby 84*f6e214c7SGavin Maltby enum nvlist_indent_mode { 85*f6e214c7SGavin Maltby NVLIST_INDENT_ABS, /* Absolute indentation */ 86*f6e214c7SGavin Maltby NVLIST_INDENT_TABBED /* Indent with tabstops */ 87*f6e214c7SGavin Maltby }; 88*f6e214c7SGavin Maltby 89*f6e214c7SGavin Maltby extern nvlist_prtctl_t nvlist_prtctl_alloc(void); 90*f6e214c7SGavin Maltby extern void nvlist_prtctl_free(nvlist_prtctl_t); 91*f6e214c7SGavin Maltby extern void nvlist_prt(nvlist_t *, nvlist_prtctl_t); 92*f6e214c7SGavin Maltby 93*f6e214c7SGavin Maltby /* Output stream */ 94*f6e214c7SGavin Maltby extern void nvlist_prtctl_setdest(nvlist_prtctl_t, FILE *); 95*f6e214c7SGavin Maltby extern FILE *nvlist_prtctl_getdest(nvlist_prtctl_t); 96*f6e214c7SGavin Maltby 97*f6e214c7SGavin Maltby /* Indentation mode, start indent, indent increment; default tabbed/0/1 */ 98*f6e214c7SGavin Maltby extern void nvlist_prtctl_setindent(nvlist_prtctl_t, enum nvlist_indent_mode, 99*f6e214c7SGavin Maltby int, int); 100*f6e214c7SGavin Maltby extern void nvlist_prtctl_doindent(nvlist_prtctl_t, int); 101*f6e214c7SGavin Maltby 102*f6e214c7SGavin Maltby enum nvlist_prtctl_fmt { 103*f6e214c7SGavin Maltby NVLIST_FMT_MEMBER_NAME, /* name fmt; default "%s = " */ 104*f6e214c7SGavin Maltby NVLIST_FMT_MEMBER_POSTAMBLE, /* after nvlist member; default "\n" */ 105*f6e214c7SGavin Maltby NVLIST_FMT_BTWN_ARRAY /* between array members; default " " */ 106*f6e214c7SGavin Maltby }; 107*f6e214c7SGavin Maltby 108*f6e214c7SGavin Maltby extern void nvlist_prtctl_setfmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, 109*f6e214c7SGavin Maltby const char *); 110*f6e214c7SGavin Maltby extern void nvlist_prtctl_dofmt(nvlist_prtctl_t, enum nvlist_prtctl_fmt, ...); 111*f6e214c7SGavin Maltby 112*f6e214c7SGavin Maltby /* 113*f6e214c7SGavin Maltby * Function prototypes for interfaces that appoint a new rendering function 114*f6e214c7SGavin Maltby * for single-valued nvlist members. 115*f6e214c7SGavin Maltby * 116*f6e214c7SGavin Maltby * A replacement function receives arguments as follows: 117*f6e214c7SGavin Maltby * 118*f6e214c7SGavin Maltby * nvlist_prtctl_t Print control structure; do not change preferences 119*f6e214c7SGavin Maltby * for this object from a print callback function. 120*f6e214c7SGavin Maltby * 121*f6e214c7SGavin Maltby * void * The function-private cookie argument registered 122*f6e214c7SGavin Maltby * when the replacement function was appointed. 123*f6e214c7SGavin Maltby * 124*f6e214c7SGavin Maltby * nvlist_t * The full nvlist that is being processed. The 125*f6e214c7SGavin Maltby * rendering function is called to render a single 126*f6e214c7SGavin Maltby * member (name and value passed as below) but it may 127*f6e214c7SGavin Maltby * want to reference or incorporate other aspects of 128*f6e214c7SGavin Maltby * the full nvlist. 129*f6e214c7SGavin Maltby * 130*f6e214c7SGavin Maltby * const char * Member name to render 131*f6e214c7SGavin Maltby * 132*f6e214c7SGavin Maltby * valtype Value of the member to render 133*f6e214c7SGavin Maltby * 134*f6e214c7SGavin Maltby * The function must return non-zero if it has rendered output for this 135*f6e214c7SGavin Maltby * member, or 0 if it wants to default to standard rendering for this 136*f6e214c7SGavin Maltby * one member. 137*f6e214c7SGavin Maltby */ 138*f6e214c7SGavin Maltby 139*f6e214c7SGavin Maltby #define NVLIST_PRINTCTL_SVDECL(funcname, valtype) \ 140*f6e214c7SGavin Maltby extern void funcname(nvlist_prtctl_t, \ 141*f6e214c7SGavin Maltby int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, valtype), \ 142*f6e214c7SGavin Maltby void *) 143*f6e214c7SGavin Maltby 144*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean, int); 145*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_boolean_value, boolean_t); 146*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_byte, uchar_t); 147*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int8, int8_t); 148*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint8, uint8_t); 149*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int16, int16_t); 150*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint16, uint16_t); 151*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int32, int32_t); 152*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint32, uint32_t); 153*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_int64, int64_t); 154*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_uint64, uint64_t); 155*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_double, double); 156*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_string, char *); 157*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_hrtime, hrtime_t); 158*f6e214c7SGavin Maltby NVLIST_PRINTCTL_SVDECL(nvlist_prtctlop_nvlist, nvlist_t *); 159*f6e214c7SGavin Maltby 160*f6e214c7SGavin Maltby #undef NVLIST_PRINTCTL_SVDECL /* was just for "clarity" above */ 161*f6e214c7SGavin Maltby 162*f6e214c7SGavin Maltby /* 163*f6e214c7SGavin Maltby * Function prototypes for interfaces that appoint a new rendering function 164*f6e214c7SGavin Maltby * for array-valued nvlist members. 165*f6e214c7SGavin Maltby * 166*f6e214c7SGavin Maltby * One additional argument is taken: uint_t for the number of array elements 167*f6e214c7SGavin Maltby * 168*f6e214c7SGavin Maltby * Return values as above. 169*f6e214c7SGavin Maltby */ 170*f6e214c7SGavin Maltby #define NVLIST_PRINTCTL_AVDECL(funcname, vtype) \ 171*f6e214c7SGavin Maltby extern void funcname(nvlist_prtctl_t, \ 172*f6e214c7SGavin Maltby int (*)(nvlist_prtctl_t, void *, nvlist_t *, const char *, vtype, uint_t), \ 173*f6e214c7SGavin Maltby void *) 174*f6e214c7SGavin Maltby 175*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_boolean_array, boolean_t *); 176*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_byte_array, uchar_t *); 177*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int8_array, int8_t *); 178*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint8_array, uint8_t *); 179*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int16_array, int16_t *); 180*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint16_array, uint16_t *); 181*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int32_array, int32_t *); 182*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint32_array, uint32_t *); 183*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_int64_array, int64_t *); 184*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_uint64_array, uint64_t *); 185*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_string_array, char **); 186*f6e214c7SGavin Maltby NVLIST_PRINTCTL_AVDECL(nvlist_prtctlop_nvlist_array, nvlist_t **); 187*f6e214c7SGavin Maltby 188*f6e214c7SGavin Maltby #undef NVLIST_PRINTCTL_AVDECL /* was just for "clarity" above */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate #endif 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #endif /* _LIBNVPAIR_H */ 195