Print this page
6447 handful of nvpair cleanups


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <unistd.h>
  27 #include <strings.h>
  28 #include <libintl.h>
  29 #include <sys/types.h>
  30 #include <sys/inttypes.h>
  31 #include <stdarg.h>
  32 #include <note.h>
  33 #include "libnvpair.h"
  34 
  35 /*
  36  * libnvpair - A tools library for manipulating <name, value> pairs.
  37  *
  38  *      This library provides routines packing an unpacking nv pairs
  39  *      for transporting data across process boundaries, transporting
  40  *      between kernel and userland, and possibly saving onto disk files.
  41  */
  42 
  43 /*
  44  * Print control structure.
  45  */
  46 
  47 #define DEFINEOP(opname, vtype) \


 194         FILE *fp = pctl->nvprt_fp; \
 195         NOTE(ARGUNUSED(private)) \
 196         NOTE(ARGUNUSED(nvl)) \
 197         indent(pctl, 1); \
 198         (void) fprintf(fp, pctl->nvprt_nmfmt, name); \
 199         (void) fprintf(fp, vfmt, (ptype)value); \
 200         return (1); \
 201 }
 202 
 203 NVLIST_PRTFUNC(boolean, int, int, "%d")
 204 NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
 205 NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
 206 NVLIST_PRTFUNC(int8, int8_t, int, "%d")
 207 NVLIST_PRTFUNC(uint8, uint8_t, uint8_t, "0x%x")
 208 NVLIST_PRTFUNC(int16, int16_t, int16_t, "%d")
 209 NVLIST_PRTFUNC(uint16, uint16_t, uint16_t, "0x%x")
 210 NVLIST_PRTFUNC(int32, int32_t, int32_t, "%d")
 211 NVLIST_PRTFUNC(uint32, uint32_t, uint32_t, "0x%x")
 212 NVLIST_PRTFUNC(int64, int64_t, longlong_t, "%lld")
 213 NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
 214 NVLIST_PRTFUNC(double, double, double, "0x%llf")
 215 NVLIST_PRTFUNC(string, char *, char *, "%s")
 216 NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
 217 
 218 /*
 219  * Generate functions to print array-valued nvlist members.
 220  */
 221 
 222 #define NVLIST_ARRPRTFUNC(type_and_variant, vtype, ptype, vfmt) \
 223 static int \
 224 nvaprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
 225     nvlist_t *nvl, const char *name, vtype *valuep, uint_t count) \
 226 { \
 227         FILE *fp = pctl->nvprt_fp; \
 228         uint_t i; \
 229         NOTE(ARGUNUSED(private)) \
 230         NOTE(ARGUNUSED(nvl)) \
 231         for (i = 0; i < count; i++) { \
 232                 if (i == 0 || pctl->nvprt_btwnarrfmt_nl) { \
 233                         indent(pctl, 1); \
 234                         (void) fprintf(fp, pctl->nvprt_nmfmt, name); \


1212                 sr = sscanf(value, "%"SCNi64, (int64_t *)&val_arg);
1213                 if ((sr == 1) &&
1214                     (nvpair_value_uint64(nvp, &val) == 0) &&
1215                     (val == val_arg))
1216                         return (1);
1217                 break;
1218         }
1219         case DATA_TYPE_UINT64_ARRAY: {
1220                 uint64_t *val_array, val_arg;
1221 
1222                 /* check indexed value of array for match */
1223                 sr = sscanf(value, "%"SCNi64, (int64_t *)&val_arg);
1224                 if ((sr == 1) &&
1225                     (nvpair_value_uint64_array(nvp, &val_array, &a_len) == 0) &&
1226                     (ai < a_len) &&
1227                     (val_array[ai] == val_arg))
1228                         return (1);
1229                 break;
1230         }
1231         case DATA_TYPE_BOOLEAN_VALUE: {
1232                 boolean_t val, val_arg;

1233 
1234                 /* scanf boolean_t from value and check for match */
1235                 sr = sscanf(value, "%"SCNi32, &val_arg);
1236                 if ((sr == 1) &&
1237                     (nvpair_value_boolean_value(nvp, &val) == 0) &&
1238                     (val == val_arg))
1239                         return (1);
1240                 break;
1241         }
1242         case DATA_TYPE_BOOLEAN_ARRAY: {
1243                 boolean_t *val_array, val_arg;

1244 
1245                 /* check indexed value of array for match */
1246                 sr = sscanf(value, "%"SCNi32, &val_arg);
1247                 if ((sr == 1) &&
1248                     (nvpair_value_boolean_array(nvp,
1249                     &val_array, &a_len) == 0) &&
1250                     (ai < a_len) &&
1251                     (val_array[ai] == val_arg))
1252                         return (1);
1253                 break;
1254         }
1255         case DATA_TYPE_HRTIME:
1256         case DATA_TYPE_NVLIST:
1257         case DATA_TYPE_NVLIST_ARRAY:
1258         case DATA_TYPE_BOOLEAN:
1259         case DATA_TYPE_DOUBLE:
1260         case DATA_TYPE_UNKNOWN:
1261         default:
1262                 /*
1263                  * unknown/unsupported data type




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <unistd.h>
  27 #include <string.h>
  28 #include <libintl.h>
  29 #include <sys/types.h>
  30 #include <sys/inttypes.h>
  31 #include <stdarg.h>
  32 #include <note.h>
  33 #include "libnvpair.h"
  34 
  35 /*
  36  * libnvpair - A tools library for manipulating <name, value> pairs.
  37  *
  38  *      This library provides routines packing an unpacking nv pairs
  39  *      for transporting data across process boundaries, transporting
  40  *      between kernel and userland, and possibly saving onto disk files.
  41  */
  42 
  43 /*
  44  * Print control structure.
  45  */
  46 
  47 #define DEFINEOP(opname, vtype) \


 194         FILE *fp = pctl->nvprt_fp; \
 195         NOTE(ARGUNUSED(private)) \
 196         NOTE(ARGUNUSED(nvl)) \
 197         indent(pctl, 1); \
 198         (void) fprintf(fp, pctl->nvprt_nmfmt, name); \
 199         (void) fprintf(fp, vfmt, (ptype)value); \
 200         return (1); \
 201 }
 202 
 203 NVLIST_PRTFUNC(boolean, int, int, "%d")
 204 NVLIST_PRTFUNC(boolean_value, boolean_t, int, "%d")
 205 NVLIST_PRTFUNC(byte, uchar_t, uchar_t, "0x%2.2x")
 206 NVLIST_PRTFUNC(int8, int8_t, int, "%d")
 207 NVLIST_PRTFUNC(uint8, uint8_t, uint8_t, "0x%x")
 208 NVLIST_PRTFUNC(int16, int16_t, int16_t, "%d")
 209 NVLIST_PRTFUNC(uint16, uint16_t, uint16_t, "0x%x")
 210 NVLIST_PRTFUNC(int32, int32_t, int32_t, "%d")
 211 NVLIST_PRTFUNC(uint32, uint32_t, uint32_t, "0x%x")
 212 NVLIST_PRTFUNC(int64, int64_t, longlong_t, "%lld")
 213 NVLIST_PRTFUNC(uint64, uint64_t, u_longlong_t, "0x%llx")
 214 NVLIST_PRTFUNC(double, double, double, "0x%f")
 215 NVLIST_PRTFUNC(string, char *, char *, "%s")
 216 NVLIST_PRTFUNC(hrtime, hrtime_t, hrtime_t, "0x%llx")
 217 
 218 /*
 219  * Generate functions to print array-valued nvlist members.
 220  */
 221 
 222 #define NVLIST_ARRPRTFUNC(type_and_variant, vtype, ptype, vfmt) \
 223 static int \
 224 nvaprint_##type_and_variant(nvlist_prtctl_t pctl, void *private, \
 225     nvlist_t *nvl, const char *name, vtype *valuep, uint_t count) \
 226 { \
 227         FILE *fp = pctl->nvprt_fp; \
 228         uint_t i; \
 229         NOTE(ARGUNUSED(private)) \
 230         NOTE(ARGUNUSED(nvl)) \
 231         for (i = 0; i < count; i++) { \
 232                 if (i == 0 || pctl->nvprt_btwnarrfmt_nl) { \
 233                         indent(pctl, 1); \
 234                         (void) fprintf(fp, pctl->nvprt_nmfmt, name); \


1212                 sr = sscanf(value, "%"SCNi64, (int64_t *)&val_arg);
1213                 if ((sr == 1) &&
1214                     (nvpair_value_uint64(nvp, &val) == 0) &&
1215                     (val == val_arg))
1216                         return (1);
1217                 break;
1218         }
1219         case DATA_TYPE_UINT64_ARRAY: {
1220                 uint64_t *val_array, val_arg;
1221 
1222                 /* check indexed value of array for match */
1223                 sr = sscanf(value, "%"SCNi64, (int64_t *)&val_arg);
1224                 if ((sr == 1) &&
1225                     (nvpair_value_uint64_array(nvp, &val_array, &a_len) == 0) &&
1226                     (ai < a_len) &&
1227                     (val_array[ai] == val_arg))
1228                         return (1);
1229                 break;
1230         }
1231         case DATA_TYPE_BOOLEAN_VALUE: {
1232                 int32_t val_arg;
1233                 boolean_t val;
1234 
1235                 /* scanf boolean_t from value and check for match */
1236                 sr = sscanf(value, "%"SCNi32, &val_arg);
1237                 if ((sr == 1) &&
1238                     (nvpair_value_boolean_value(nvp, &val) == 0) &&
1239                     (val == val_arg))
1240                         return (1);
1241                 break;
1242         }
1243         case DATA_TYPE_BOOLEAN_ARRAY: {
1244                 boolean_t *val_array;
1245                 int32_t val_arg;
1246 
1247                 /* check indexed value of array for match */
1248                 sr = sscanf(value, "%"SCNi32, &val_arg);
1249                 if ((sr == 1) &&
1250                     (nvpair_value_boolean_array(nvp,
1251                     &val_array, &a_len) == 0) &&
1252                     (ai < a_len) &&
1253                     (val_array[ai] == val_arg))
1254                         return (1);
1255                 break;
1256         }
1257         case DATA_TYPE_HRTIME:
1258         case DATA_TYPE_NVLIST:
1259         case DATA_TYPE_NVLIST_ARRAY:
1260         case DATA_TYPE_BOOLEAN:
1261         case DATA_TYPE_DOUBLE:
1262         case DATA_TYPE_UNKNOWN:
1263         default:
1264                 /*
1265                  * unknown/unsupported data type