xref: /illumos-gate/usr/src/boot/libsa/zfs/libzfs.h (revision 22028508)
1e3c18722SToomas Soome /*
2199767f8SToomas Soome  * Copyright (c) 2012 Andriy Gapon <avg@FreeBSD.org>
3199767f8SToomas Soome  * All rights reserved.
4199767f8SToomas Soome  *
5199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
6199767f8SToomas Soome  * modification, are permitted provided that the following conditions
7199767f8SToomas Soome  * are met:
8199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
13199767f8SToomas Soome  *
14199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24199767f8SToomas Soome  * SUCH DAMAGE.
25199767f8SToomas Soome  */
26199767f8SToomas Soome 
27199767f8SToomas Soome #ifndef _BOOT_LIBZFS_H_
287fc77f3fSToomas Soome #define	_BOOT_LIBZFS_H_
29199767f8SToomas Soome 
30b713c91eSToomas Soome #include <zfsimpl.h>
31b713c91eSToomas Soome 
32199767f8SToomas Soome #define	ZFS_MAXNAMELEN	256
33199767f8SToomas Soome 
34199767f8SToomas Soome /*
35199767f8SToomas Soome  * ZFS fully-qualified device descriptor.
36199767f8SToomas Soome  */
370a06a804SToomas Soome struct zfs_devdesc {
38b713c91eSToomas Soome 	struct devdesc	dd;		/* Must be first. */
39b713c91eSToomas Soome 	uint64_t	pool_guid;
40b713c91eSToomas Soome 	uint64_t	root_guid;
41199767f8SToomas Soome };
42199767f8SToomas Soome 
43b713c91eSToomas Soome /* nvp implementation version */
44b713c91eSToomas Soome #define	NV_VERSION		0
45b713c91eSToomas Soome 
46b713c91eSToomas Soome /* nvlist persistent unique name flags, stored in nvl_nvflags */
47b713c91eSToomas Soome #define	NV_UNIQUE_NAME		0x1
48b713c91eSToomas Soome #define	NV_UNIQUE_NAME_TYPE	0x2
49b713c91eSToomas Soome 
50b713c91eSToomas Soome #define	NV_ALIGN4(x)		(((x) + 3) & ~3)
51b713c91eSToomas Soome #define	NV_ALIGN(x)		(((x) + 7) & ~7)
52b713c91eSToomas Soome 
53b713c91eSToomas Soome /*
54b713c91eSToomas Soome  * nvlist header.
55b713c91eSToomas Soome  * nvlist has 4 bytes header followed by version and flags, then nvpairs
56b713c91eSToomas Soome  * and the list is terminated by double zero.
57b713c91eSToomas Soome  */
58b713c91eSToomas Soome typedef struct {
59b713c91eSToomas Soome 	char nvh_encoding;
60b713c91eSToomas Soome 	char nvh_endian;
61b713c91eSToomas Soome 	char nvh_reserved1;
62b713c91eSToomas Soome 	char nvh_reserved2;
63b713c91eSToomas Soome } nvs_header_t;
64b713c91eSToomas Soome 
65b713c91eSToomas Soome typedef struct {
66b713c91eSToomas Soome 	nvs_header_t nv_header;
67b713c91eSToomas Soome 	size_t nv_asize;
68b713c91eSToomas Soome 	size_t nv_size;
69b713c91eSToomas Soome 	uint8_t *nv_data;
70b713c91eSToomas Soome 	uint8_t *nv_idx;
71b713c91eSToomas Soome } nvlist_t;
72b713c91eSToomas Soome 
73b713c91eSToomas Soome /*
74b713c91eSToomas Soome  * nvpair header.
75b713c91eSToomas Soome  * nvpair has encoded and decoded size
76b713c91eSToomas Soome  * name string (size and data)
77b713c91eSToomas Soome  * data type and number of elements
78b713c91eSToomas Soome  * data
79b713c91eSToomas Soome  */
80b713c91eSToomas Soome typedef struct {
81b713c91eSToomas Soome 	unsigned encoded_size;
82b713c91eSToomas Soome 	unsigned decoded_size;
83b713c91eSToomas Soome } nvp_header_t;
84b713c91eSToomas Soome 
85b713c91eSToomas Soome /*
86b713c91eSToomas Soome  * nvlist stream head.
87b713c91eSToomas Soome  */
88b713c91eSToomas Soome typedef struct {
89b713c91eSToomas Soome 	unsigned nvl_version;
90b713c91eSToomas Soome 	unsigned nvl_nvflag;
91b713c91eSToomas Soome 	nvp_header_t nvl_pair;
92b713c91eSToomas Soome } nvs_data_t;
93b713c91eSToomas Soome 
94b713c91eSToomas Soome typedef struct {
95b713c91eSToomas Soome 	unsigned nv_size;
96b713c91eSToomas Soome 	uint8_t nv_data[];	/* NV_ALIGN4(string) */
97b713c91eSToomas Soome } nv_string_t;
98b713c91eSToomas Soome 
99b713c91eSToomas Soome typedef struct {
100b713c91eSToomas Soome 	unsigned nv_type;	/* data_type_t */
101b713c91eSToomas Soome 	unsigned nv_nelem;	/* number of elements */
102b713c91eSToomas Soome 	uint8_t nv_data[];	/* data stream */
103b713c91eSToomas Soome } nv_pair_data_t;
104b713c91eSToomas Soome 
105b713c91eSToomas Soome nvlist_t *nvlist_create(int);
106b713c91eSToomas Soome void nvlist_destroy(nvlist_t *);
107b713c91eSToomas Soome nvlist_t *nvlist_import(const char *, size_t);
108b713c91eSToomas Soome int nvlist_export(nvlist_t *);
109b713c91eSToomas Soome int nvlist_remove(nvlist_t *, const char *, data_type_t);
110b713c91eSToomas Soome int nvpair_type_from_name(const char *);
111b713c91eSToomas Soome nvp_header_t *nvpair_find(nvlist_t *, const char *);
112b713c91eSToomas Soome void nvpair_print(nvp_header_t *, unsigned int);
113b713c91eSToomas Soome void nvlist_print(const nvlist_t *, unsigned int);
114b713c91eSToomas Soome char *nvstring_get(nv_string_t *);
115b713c91eSToomas Soome int nvlist_find(const nvlist_t *, const char *, data_type_t,
116b713c91eSToomas Soome     int *, void *, int *);
117b713c91eSToomas Soome nvp_header_t *nvlist_next_nvpair(nvlist_t *, nvp_header_t *);
118b713c91eSToomas Soome 
119b713c91eSToomas Soome int nvlist_add_boolean_value(nvlist_t *, const char *, boolean_t);
120b713c91eSToomas Soome int nvlist_add_byte(nvlist_t *, const char *, uint8_t);
121b713c91eSToomas Soome int nvlist_add_int8(nvlist_t *, const char *, int8_t);
122b713c91eSToomas Soome int nvlist_add_uint8(nvlist_t *, const char *, uint8_t);
123b713c91eSToomas Soome int nvlist_add_int16(nvlist_t *, const char *, int16_t);
124b713c91eSToomas Soome int nvlist_add_uint16(nvlist_t *, const char *, uint16_t);
125b713c91eSToomas Soome int nvlist_add_int32(nvlist_t *, const char *, int32_t);
126b713c91eSToomas Soome int nvlist_add_uint32(nvlist_t *, const char *, uint32_t);
127b713c91eSToomas Soome int nvlist_add_int64(nvlist_t *, const char *, int64_t);
128b713c91eSToomas Soome int nvlist_add_uint64(nvlist_t *, const char *, uint64_t);
129b713c91eSToomas Soome int nvlist_add_string(nvlist_t *, const char *, const char *);
130b713c91eSToomas Soome int nvlist_add_boolean_array(nvlist_t *, const char *, boolean_t *, uint32_t);
131b713c91eSToomas Soome int nvlist_add_byte_array(nvlist_t *, const char *, uint8_t *, uint32_t);
132b713c91eSToomas Soome int nvlist_add_int8_array(nvlist_t *, const char *, int8_t *, uint32_t);
133b713c91eSToomas Soome int nvlist_add_uint8_array(nvlist_t *, const char *, uint8_t *, uint32_t);
134b713c91eSToomas Soome int nvlist_add_int16_array(nvlist_t *, const char *, int16_t *, uint32_t);
135b713c91eSToomas Soome int nvlist_add_uint16_array(nvlist_t *, const char *, uint16_t *, uint32_t);
136b713c91eSToomas Soome int nvlist_add_int32_array(nvlist_t *, const char *, int32_t *, uint32_t);
137b713c91eSToomas Soome int nvlist_add_uint32_array(nvlist_t *, const char *, uint32_t *, uint32_t);
138b713c91eSToomas Soome int nvlist_add_int64_array(nvlist_t *, const char *, int64_t *, uint32_t);
139b713c91eSToomas Soome int nvlist_add_uint64_array(nvlist_t *, const char *, uint64_t *, uint32_t);
140b713c91eSToomas Soome int nvlist_add_string_array(nvlist_t *, const char *, char * const *, uint32_t);
141b713c91eSToomas Soome int nvlist_add_nvlist(nvlist_t *, const char *, nvlist_t *);
142b713c91eSToomas Soome int nvlist_add_nvlist_array(nvlist_t *, const char *, nvlist_t **, uint32_t);
143b713c91eSToomas Soome 
1447fc77f3fSToomas Soome int	zfs_parsedev(struct zfs_devdesc *, const char *, const char **);
1457fc77f3fSToomas Soome char	*zfs_bootfs(void *);
1467fc77f3fSToomas Soome char	*zfs_fmtdev(void *);
1477fc77f3fSToomas Soome int	zfs_probe_dev(const char *, uint64_t *);
1487fc77f3fSToomas Soome int	zfs_list(const char *);
149b713c91eSToomas Soome int	zfs_get_bootonce(void *, const char *, char *, size_t);
150b713c91eSToomas Soome int	zfs_get_bootenv(void *, nvlist_t **);
151b713c91eSToomas Soome int	zfs_set_bootenv(void *, nvlist_t *);
152b713c91eSToomas Soome int	zfs_attach_nvstore(void *);
153edb35047SToomas Soome uint64_t ldi_get_size(void *);
154199767f8SToomas Soome 
155b713c91eSToomas Soome nvlist_t *vdev_read_bootenv(vdev_t *);
156b713c91eSToomas Soome 
157199767f8SToomas Soome extern struct devsw zfs_dev;
158199767f8SToomas Soome extern struct fs_ops zfs_fsops;
159199767f8SToomas Soome 
1607fc77f3fSToomas Soome #endif /* _BOOT_LIBZFS_H_ */
161