nv.h revision 204076
1204076Spjd/*- 2204076Spjd * Copyright (c) 2009-2010 The FreeBSD Foundation 3204076Spjd * All rights reserved. 4204076Spjd * 5204076Spjd * This software was developed by Pawel Jakub Dawidek under sponsorship from 6204076Spjd * the FreeBSD Foundation. 7204076Spjd * 8204076Spjd * Redistribution and use in source and binary forms, with or without 9204076Spjd * modification, are permitted provided that the following conditions 10204076Spjd * are met: 11204076Spjd * 1. Redistributions of source code must retain the above copyright 12204076Spjd * notice, this list of conditions and the following disclaimer. 13204076Spjd * 2. Redistributions in binary form must reproduce the above copyright 14204076Spjd * notice, this list of conditions and the following disclaimer in the 15204076Spjd * documentation and/or other materials provided with the distribution. 16204076Spjd * 17204076Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 18204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20204076Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 21204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24204076Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27204076Spjd * SUCH DAMAGE. 28204076Spjd * 29204076Spjd * $FreeBSD: head/sbin/hastd/nv.h 204076 2010-02-18 23:16:19Z pjd $ 30204076Spjd */ 31204076Spjd 32204076Spjd#ifndef _NV_H_ 33204076Spjd#define _NV_H_ 34204076Spjd 35204076Spjd#include <sys/cdefs.h> 36204076Spjd 37204076Spjd#include <stdarg.h> 38204076Spjd#include <stdbool.h> 39204076Spjd#include <stdint.h> 40204076Spjd#include <stdio.h> 41204076Spjd 42204076Spjd#include <ebuf.h> 43204076Spjd 44204076Spjd#define NV_TYPE_INT8 1 45204076Spjd#define NV_TYPE_UINT8 2 46204076Spjd#define NV_TYPE_INT16 3 47204076Spjd#define NV_TYPE_UINT16 4 48204076Spjd#define NV_TYPE_INT32 5 49204076Spjd#define NV_TYPE_UINT32 6 50204076Spjd#define NV_TYPE_INT64 7 51204076Spjd#define NV_TYPE_UINT64 8 52204076Spjd#define NV_TYPE_INT8_ARRAY 9 53204076Spjd#define NV_TYPE_UINT8_ARRAY 10 54204076Spjd#define NV_TYPE_INT16_ARRAY 11 55204076Spjd#define NV_TYPE_UINT16_ARRAY 12 56204076Spjd#define NV_TYPE_INT32_ARRAY 13 57204076Spjd#define NV_TYPE_UINT32_ARRAY 14 58204076Spjd#define NV_TYPE_INT64_ARRAY 15 59204076Spjd#define NV_TYPE_UINT64_ARRAY 16 60204076Spjd#define NV_TYPE_STRING 17 61204076Spjd 62204076Spjd#define NV_TYPE_MASK 0x7f 63204076Spjd#define NV_TYPE_FIRST NV_TYPE_INT8 64204076Spjd#define NV_TYPE_LAST NV_TYPE_STRING 65204076Spjd 66204076Spjd#define NV_ORDER_NETWORK 0x00 67204076Spjd#define NV_ORDER_HOST 0x80 68204076Spjd 69204076Spjd#define NV_ORDER_MASK 0x80 70204076Spjd 71204076Spjdstruct nv; 72204076Spjd 73204076Spjdstruct nv *nv_alloc(void); 74204076Spjdvoid nv_free(struct nv *nv); 75204076Spjdint nv_error(const struct nv *nv); 76204076Spjdint nv_set_error(struct nv *nv, int error); 77204076Spjdint nv_validate(struct nv *nv, size_t *extrap); 78204076Spjd 79204076Spjdstruct ebuf *nv_hton(struct nv *nv); 80204076Spjdstruct nv *nv_ntoh(struct ebuf *eb); 81204076Spjd 82204076Spjdvoid nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...) 83204076Spjd __printflike(3, 4); 84204076Spjdvoid nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...) 85204076Spjd __printflike(3, 4); 86204076Spjdvoid nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...) 87204076Spjd __printflike(3, 4); 88204076Spjdvoid nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...) 89204076Spjd __printflike(3, 4); 90204076Spjdvoid nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...) 91204076Spjd __printflike(3, 4); 92204076Spjdvoid nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...) 93204076Spjd __printflike(3, 4); 94204076Spjdvoid nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...) 95204076Spjd __printflike(3, 4); 96204076Spjdvoid nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...) 97204076Spjd __printflike(3, 4); 98204076Spjdvoid nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size, 99204076Spjd const char *namefmt, ...) __printflike(4, 5); 100204076Spjdvoid nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size, 101204076Spjd const char *namefmt, ...) __printflike(4, 5); 102204076Spjdvoid nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size, 103204076Spjd const char *namefmt, ...) __printflike(4, 5); 104204076Spjdvoid nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size, 105204076Spjd const char *namefmt, ...) __printflike(4, 5); 106204076Spjdvoid nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size, 107204076Spjd const char *namefmt, ...) __printflike(4, 5); 108204076Spjdvoid nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size, 109204076Spjd const char *namefmt, ...) __printflike(4, 5); 110204076Spjdvoid nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size, 111204076Spjd const char *namefmt, ...) __printflike(4, 5); 112204076Spjdvoid nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size, 113204076Spjd const char *namefmt, ...) __printflike(4, 5); 114204076Spjdvoid nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...) 115204076Spjd __printflike(3, 4); 116204076Spjdvoid nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...) 117204076Spjd __printflike(3, 4); 118204076Spjdvoid nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt, 119204076Spjd va_list valueap) __printflike(3, 0); 120204076Spjd 121204076Spjdint8_t nv_get_int8(struct nv *nv, const char *namefmt, ...) 122204076Spjd __printflike(2, 3); 123204076Spjduint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...) 124204076Spjd __printflike(2, 3); 125204076Spjdint16_t nv_get_int16(struct nv *nv, const char *namefmt, ...) 126204076Spjd __printflike(2, 3); 127204076Spjduint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...) 128204076Spjd __printflike(2, 3); 129204076Spjdint32_t nv_get_int32(struct nv *nv, const char *namefmt, ...) 130204076Spjd __printflike(2, 3); 131204076Spjduint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...) 132204076Spjd __printflike(2, 3); 133204076Spjdint64_t nv_get_int64(struct nv *nv, const char *namefmt, ...) 134204076Spjd __printflike(2, 3); 135204076Spjduint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...) 136204076Spjd __printflike(2, 3); 137204076Spjdconst int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep, 138204076Spjd const char *namefmt, ...) __printflike(3, 4); 139204076Spjdconst uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep, 140204076Spjd const char *namefmt, ...) __printflike(3, 4); 141204076Spjdconst int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep, 142204076Spjd const char *namefmt, ...) __printflike(3, 4); 143204076Spjdconst uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep, 144204076Spjd const char *namefmt, ...) __printflike(3, 4); 145204076Spjdconst int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep, 146204076Spjd const char *namefmt, ...) __printflike(3, 4); 147204076Spjdconst uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep, 148204076Spjd const char *namefmt, ...) __printflike(3, 4); 149204076Spjdconst int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep, 150204076Spjd const char *namefmt, ...) __printflike(3, 4); 151204076Spjdconst uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep, 152204076Spjd const char *namefmt, ...) __printflike(3, 4); 153204076Spjdconst char *nv_get_string(struct nv *nv, const char *namefmt, ...) 154204076Spjd __printflike(2, 3); 155204076Spjd 156204076Spjdvoid nv_dump(struct nv *nv); 157204076Spjd 158204076Spjd#endif /* !_NV_H_ */ 159