1 /*- 2 * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef _BHND_NVRAM_BHND_NVRAM_STORE_H_ 33 #define _BHND_NVRAM_BHND_NVRAM_STORE_H_ 34 35 #ifdef _KERNEL 36 #include <sys/param.h> 37 #include <sys/bus.h> 38 #else /* !_KERNEL */ 39 #include <errno.h> 40 #include <stdint.h> 41 #include <stdlib.h> 42 #endif 43 44 #include <sys/queue.h> 45 46 #include "bhnd_nvram_data.h" 47 #include "bhnd_nvram_io.h" 48 49 struct bhnd_nvram_store; 50 51 /** 52 * NVRAM export flags. 53 */ 54 enum { 55 BHND_NVSTORE_EXPORT_CHILDREN = (1<<0), /**< Include all subpaths */ 56 BHND_NVSTORE_EXPORT_PRESERVE_DEVPATHS = (1<<1), /**< Preserve existing device path definitions (default) */ 57 BHND_NVSTORE_EXPORT_COMPACT_DEVPATHS = (1<<2), /**< Re-encode all device paths using compact syntax */ 58 BHND_NVSTORE_EXPORT_EXPAND_DEVPATHS = (1<<3), /**< Re-encode all device paths using non-compact syntax */ 59 BHND_NVSTORE_EXPORT_ALL_VARS = (1<<6|1<<7), /**< Include all variables (default) */ 60 BHND_NVSTORE_EXPORT_COMMITTED = (1<<6), /**< Include all committed changes */ 61 BHND_NVSTORE_EXPORT_UNCOMMITTED = (1<<7), /**< Include all uncommitted changes (not including deletions) */ 62 BHND_NVSTORE_EXPORT_DELETED = (1<<8), /**< Include all uncommitted deltions (as 63 properties of type BHND_NVRAM_TYPE_NULL) */ 64 }; 65 66 int bhnd_nvram_store_new(struct bhnd_nvram_store **store, 67 struct bhnd_nvram_data *data); 68 69 int bhnd_nvram_store_parse_new(struct bhnd_nvram_store **store, 70 struct bhnd_nvram_io *io, bhnd_nvram_data_class *cls); 71 72 void bhnd_nvram_store_free(struct bhnd_nvram_store *store); 73 74 int bhnd_nvram_store_export(struct bhnd_nvram_store *store, 75 const char *path, bhnd_nvram_data_class **cls, 76 bhnd_nvram_plist **props, bhnd_nvram_plist **options, 77 uint32_t flags); 78 79 int bhnd_nvram_store_serialize(struct bhnd_nvram_store *store, 80 const char *path, struct bhnd_nvram_io **data, uint32_t flags); 81 82 int bhnd_nvram_store_getvar(struct bhnd_nvram_store *sc, const char *name, 83 void *outp, size_t *olen, bhnd_nvram_type otype); 84 int bhnd_nvram_store_setvar(struct bhnd_nvram_store *sc, const char *name, 85 const void *inp, size_t ilen, bhnd_nvram_type itype); 86 int bhnd_nvram_store_unsetvar(struct bhnd_nvram_store *sc, 87 const char *name); 88 89 int bhnd_nvram_store_setval(struct bhnd_nvram_store *sc, const char *name, 90 bhnd_nvram_val *value); 91 92 #endif /* _BHND_NVRAM_BHND_NVRAM_STORE_H_ */ 93