1*22028508SToomas Soome /* 2*22028508SToomas Soome * Copyright (c) 2012 Andriy Gapon <avg@FreeBSD.org> 3*22028508SToomas Soome * All rights reserved. 4*22028508SToomas Soome * 5*22028508SToomas Soome * Redistribution and use in source and binary forms, with or without 6*22028508SToomas Soome * modification, are permitted provided that the following conditions 7*22028508SToomas Soome * are met: 8*22028508SToomas Soome * 1. Redistributions of source code must retain the above copyright 9*22028508SToomas Soome * notice, this list of conditions and the following disclaimer. 10*22028508SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 11*22028508SToomas Soome * notice, this list of conditions and the following disclaimer in the 12*22028508SToomas Soome * documentation and/or other materials provided with the distribution. 13*22028508SToomas Soome * 14*22028508SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*22028508SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*22028508SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*22028508SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*22028508SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*22028508SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*22028508SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*22028508SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*22028508SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*22028508SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*22028508SToomas Soome * SUCH DAMAGE. 25*22028508SToomas Soome */ 26*22028508SToomas Soome 27*22028508SToomas Soome #ifndef _BOOT_LIBZFS_H_ 28*22028508SToomas Soome #define _BOOT_LIBZFS_H_ 29*22028508SToomas Soome 30*22028508SToomas Soome #include <zfsimpl.h> 31*22028508SToomas Soome 32*22028508SToomas Soome #define ZFS_MAXNAMELEN 256 33*22028508SToomas Soome 34*22028508SToomas Soome /* 35*22028508SToomas Soome * ZFS fully-qualified device descriptor. 36*22028508SToomas Soome */ 37*22028508SToomas Soome struct zfs_devdesc { 38*22028508SToomas Soome struct devdesc dd; /* Must be first. */ 39*22028508SToomas Soome uint64_t pool_guid; 40*22028508SToomas Soome uint64_t root_guid; 41*22028508SToomas Soome }; 42*22028508SToomas Soome 43*22028508SToomas Soome /* nvp implementation version */ 44*22028508SToomas Soome #define NV_VERSION 0 45*22028508SToomas Soome 46*22028508SToomas Soome /* nvlist persistent unique name flags, stored in nvl_nvflags */ 47*22028508SToomas Soome #define NV_UNIQUE_NAME 0x1 48*22028508SToomas Soome #define NV_UNIQUE_NAME_TYPE 0x2 49*22028508SToomas Soome 50*22028508SToomas Soome #define NV_ALIGN4(x) (((x) + 3) & ~3) 51*22028508SToomas Soome #define NV_ALIGN(x) (((x) + 7) & ~7) 52*22028508SToomas Soome 53*22028508SToomas Soome /* 54*22028508SToomas Soome * nvlist header. 55*22028508SToomas Soome * nvlist has 4 bytes header followed by version and flags, then nvpairs 56*22028508SToomas Soome * and the list is terminated by double zero. 57*22028508SToomas Soome */ 58*22028508SToomas Soome typedef struct { 59*22028508SToomas Soome char nvh_encoding; 60*22028508SToomas Soome char nvh_endian; 61*22028508SToomas Soome char nvh_reserved1; 62*22028508SToomas Soome char nvh_reserved2; 63*22028508SToomas Soome } nvs_header_t; 64*22028508SToomas Soome 65*22028508SToomas Soome typedef struct { 66*22028508SToomas Soome nvs_header_t nv_header; 67*22028508SToomas Soome size_t nv_asize; 68*22028508SToomas Soome size_t nv_size; 69*22028508SToomas Soome uint8_t *nv_data; 70*22028508SToomas Soome uint8_t *nv_idx; 71*22028508SToomas Soome } nvlist_t; 72*22028508SToomas Soome 73*22028508SToomas Soome /* 74*22028508SToomas Soome * nvpair header. 75*22028508SToomas Soome * nvpair has encoded and decoded size 76*22028508SToomas Soome * name string (size and data) 77*22028508SToomas Soome * data type and number of elements 78*22028508SToomas Soome * data 79*22028508SToomas Soome */ 80*22028508SToomas Soome typedef struct { 81*22028508SToomas Soome unsigned encoded_size; 82*22028508SToomas Soome unsigned decoded_size; 83*22028508SToomas Soome } nvp_header_t; 84*22028508SToomas Soome 85*22028508SToomas Soome /* 86*22028508SToomas Soome * nvlist stream head. 87*22028508SToomas Soome */ 88*22028508SToomas Soome typedef struct { 89*22028508SToomas Soome unsigned nvl_version; 90*22028508SToomas Soome unsigned nvl_nvflag; 91*22028508SToomas Soome nvp_header_t nvl_pair; 92*22028508SToomas Soome } nvs_data_t; 93*22028508SToomas Soome 94*22028508SToomas Soome typedef struct { 95*22028508SToomas Soome unsigned nv_size; 96*22028508SToomas Soome uint8_t nv_data[]; /* NV_ALIGN4(string) */ 97*22028508SToomas Soome } nv_string_t; 98*22028508SToomas Soome 99*22028508SToomas Soome typedef struct { 100*22028508SToomas Soome unsigned nv_type; /* data_type_t */ 101*22028508SToomas Soome unsigned nv_nelem; /* number of elements */ 102*22028508SToomas Soome uint8_t nv_data[]; /* data stream */ 103*22028508SToomas Soome } nv_pair_data_t; 104*22028508SToomas Soome 105*22028508SToomas Soome nvlist_t *nvlist_create(int); 106*22028508SToomas Soome void nvlist_destroy(nvlist_t *); 107*22028508SToomas Soome nvlist_t *nvlist_import(const char *, size_t); 108*22028508SToomas Soome int nvlist_export(nvlist_t *); 109*22028508SToomas Soome int nvlist_remove(nvlist_t *, const char *, data_type_t); 110*22028508SToomas Soome int nvpair_type_from_name(const char *); 111*22028508SToomas Soome nvp_header_t *nvpair_find(nvlist_t *, const char *); 112*22028508SToomas Soome void nvpair_print(nvp_header_t *, unsigned int); 113*22028508SToomas Soome void nvlist_print(const nvlist_t *, unsigned int); 114*22028508SToomas Soome char *nvstring_get(nv_string_t *); 115*22028508SToomas Soome int nvlist_find(const nvlist_t *, const char *, data_type_t, 116*22028508SToomas Soome int *, void *, int *); 117*22028508SToomas Soome nvp_header_t *nvlist_next_nvpair(nvlist_t *, nvp_header_t *); 118*22028508SToomas Soome 119*22028508SToomas Soome int nvlist_add_boolean_value(nvlist_t *, const char *, boolean_t); 120*22028508SToomas Soome int nvlist_add_byte(nvlist_t *, const char *, uint8_t); 121*22028508SToomas Soome int nvlist_add_int8(nvlist_t *, const char *, int8_t); 122*22028508SToomas Soome int nvlist_add_uint8(nvlist_t *, const char *, uint8_t); 123*22028508SToomas Soome int nvlist_add_int16(nvlist_t *, const char *, int16_t); 124*22028508SToomas Soome int nvlist_add_uint16(nvlist_t *, const char *, uint16_t); 125*22028508SToomas Soome int nvlist_add_int32(nvlist_t *, const char *, int32_t); 126*22028508SToomas Soome int nvlist_add_uint32(nvlist_t *, const char *, uint32_t); 127*22028508SToomas Soome int nvlist_add_int64(nvlist_t *, const char *, int64_t); 128*22028508SToomas Soome int nvlist_add_uint64(nvlist_t *, const char *, uint64_t); 129*22028508SToomas Soome int nvlist_add_string(nvlist_t *, const char *, const char *); 130*22028508SToomas Soome int nvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *, uint32_t); 131*22028508SToomas Soome int nvlist_add_byte_array(nvlist_t *, const char *, uint8_t *, uint32_t); 132*22028508SToomas Soome int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint32_t); 133*22028508SToomas Soome int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint32_t); 134*22028508SToomas Soome int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint32_t); 135*22028508SToomas Soome int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint32_t); 136*22028508SToomas Soome int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint32_t); 137*22028508SToomas Soome int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint32_t); 138*22028508SToomas Soome int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint32_t); 139*22028508SToomas Soome int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint32_t); 140*22028508SToomas Soome int nvlist_add_string_array(nvlist_t *, const char *, char * const *, uint32_t); 141*22028508SToomas Soome int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *); 142*22028508SToomas Soome int nvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint32_t); 143*22028508SToomas Soome 144*22028508SToomas Soome int zfs_parsedev(struct zfs_devdesc *, const char *, const char **); 145*22028508SToomas Soome char *zfs_bootfs(void *); 146*22028508SToomas Soome char *zfs_fmtdev(void *); 147*22028508SToomas Soome int zfs_probe_dev(const char *, uint64_t *); 148*22028508SToomas Soome int zfs_list(const char *); 149*22028508SToomas Soome int zfs_get_bootonce(void *, const char *, char *, size_t); 150*22028508SToomas Soome int zfs_get_bootenv(void *, nvlist_t **); 151*22028508SToomas Soome int zfs_set_bootenv(void *, nvlist_t *); 152*22028508SToomas Soome int zfs_attach_nvstore(void *); 153*22028508SToomas Soome uint64_t ldi_get_size(void *); 154*22028508SToomas Soome 155*22028508SToomas Soome nvlist_t *vdev_read_bootenv(vdev_t *); 156*22028508SToomas Soome 157*22028508SToomas Soome extern struct devsw zfs_dev; 158*22028508SToomas Soome extern struct fs_ops zfs_fsops; 159*22028508SToomas Soome 160*22028508SToomas Soome #endif /* _BOOT_LIBZFS_H_ */ 161