1*789Sahrens /*
2*789Sahrens  * CDDL HEADER START
3*789Sahrens  *
4*789Sahrens  * The contents of this file are subject to the terms of the
5*789Sahrens  * Common Development and Distribution License, Version 1.0 only
6*789Sahrens  * (the "License").  You may not use this file except in compliance
7*789Sahrens  * with the License.
8*789Sahrens  *
9*789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*789Sahrens  * or http://www.opensolaris.org/os/licensing.
11*789Sahrens  * See the License for the specific language governing permissions
12*789Sahrens  * and limitations under the License.
13*789Sahrens  *
14*789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
15*789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
17*789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
18*789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
19*789Sahrens  *
20*789Sahrens  * CDDL HEADER END
21*789Sahrens  */
22*789Sahrens /*
23*789Sahrens  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*789Sahrens  * Use is subject to license terms.
25*789Sahrens  */
26*789Sahrens 
27*789Sahrens #ifndef	_LIBZFS_H
28*789Sahrens #define	_LIBZFS_H
29*789Sahrens 
30*789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*789Sahrens 
32*789Sahrens #include <assert.h>
33*789Sahrens #include <libnvpair.h>
34*789Sahrens #include <sys/param.h>
35*789Sahrens #include <sys/types.h>
36*789Sahrens #include <sys/varargs.h>
37*789Sahrens #include <sys/fs/zfs.h>
38*789Sahrens 
39*789Sahrens #ifdef	__cplusplus
40*789Sahrens extern "C" {
41*789Sahrens #endif
42*789Sahrens 
43*789Sahrens /*
44*789Sahrens  * Miscellaneous ZFS constants
45*789Sahrens  */
46*789Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
47*789Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
48*789Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
49*789Sahrens 
50*789Sahrens /*
51*789Sahrens  * Basic handle types
52*789Sahrens  */
53*789Sahrens typedef struct zfs_handle zfs_handle_t;
54*789Sahrens typedef struct zpool_handle zpool_handle_t;
55*789Sahrens 
56*789Sahrens /*
57*789Sahrens  * Basic handle functions
58*789Sahrens  */
59*789Sahrens extern zpool_handle_t *zpool_open(const char *);
60*789Sahrens extern zpool_handle_t *zpool_open_canfail(const char *);
61*789Sahrens extern void zpool_close(zpool_handle_t *);
62*789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
63*789Sahrens extern uint64_t zpool_get_guid(zpool_handle_t *);
64*789Sahrens extern uint64_t zpool_get_space_used(zpool_handle_t *);
65*789Sahrens extern uint64_t zpool_get_space_total(zpool_handle_t *);
66*789Sahrens extern int zpool_get_root(zpool_handle_t *, char *, size_t);
67*789Sahrens extern int zpool_get_state(zpool_handle_t *);
68*789Sahrens 
69*789Sahrens /*
70*789Sahrens  * Iterate over all active pools in the system.
71*789Sahrens  */
72*789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
73*789Sahrens extern int zpool_iter(zpool_iter_f, void *);
74*789Sahrens 
75*789Sahrens /*
76*789Sahrens  * Functions to create and destroy pools
77*789Sahrens  */
78*789Sahrens extern int zpool_create(const char *, nvlist_t *, const char *);
79*789Sahrens extern int zpool_destroy(zpool_handle_t *);
80*789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
81*789Sahrens 
82*789Sahrens /*
83*789Sahrens  * Functions to manipulate pool and vdev state
84*789Sahrens  */
85*789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
86*789Sahrens 
87*789Sahrens extern int zpool_vdev_online(zpool_handle_t *, const char *);
88*789Sahrens extern int zpool_vdev_offline(zpool_handle_t *, const char *);
89*789Sahrens extern int zpool_vdev_attach(zpool_handle_t *, const char *, const char *,
90*789Sahrens     nvlist_t *, int);
91*789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
92*789Sahrens 
93*789Sahrens /*
94*789Sahrens  * Pool health statistics.
95*789Sahrens  */
96*789Sahrens typedef enum {
97*789Sahrens 	/*
98*789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
99*789Sahrens 	 * event namespace.  Each is associated with a correponding message ID.
100*789Sahrens 	 */
101*789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
102*789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
103*789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
104*789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
105*789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device lable with no replicas */
106*789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
107*789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
108*789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
109*789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
110*789Sahrens 	ZPOOL_STATUS_VERSION_MISMATCH,	/* bad on-disk version */
111*789Sahrens 
112*789Sahrens 	/*
113*789Sahrens 	 * The following are not faults per se, but still an error possibly
114*789Sahrens 	 * requiring adminsitrative attention.  There is no corresponding
115*789Sahrens 	 * message ID.
116*789Sahrens 	 */
117*789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
118*789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
119*789Sahrens 
120*789Sahrens 	/*
121*789Sahrens 	 * Finally, the following indicates a healthy pool.
122*789Sahrens 	 */
123*789Sahrens 	ZPOOL_STATUS_OK
124*789Sahrens } zpool_status_t;
125*789Sahrens 
126*789Sahrens extern zpool_status_t zpool_get_status(zpool_handle_t *, char **msgid);
127*789Sahrens extern zpool_status_t zpool_import_status(nvlist_t *, char **msgid);
128*789Sahrens 
129*789Sahrens /*
130*789Sahrens  * Statistics and configuration functions.
131*789Sahrens  */
132*789Sahrens extern nvlist_t *zpool_get_config(zpool_handle_t *);
133*789Sahrens extern int zpool_refresh_stats(zpool_handle_t *,
134*789Sahrens     nvlist_t **oldconfig, nvlist_t **newconfig);
135*789Sahrens 
136*789Sahrens /*
137*789Sahrens  * Import and export functions
138*789Sahrens  */
139*789Sahrens extern int zpool_export(zpool_handle_t *);
140*789Sahrens extern int zpool_import(nvlist_t *, const char *, const char *);
141*789Sahrens 
142*789Sahrens /*
143*789Sahrens  * Search for pools to import
144*789Sahrens  */
145*789Sahrens extern nvlist_t *zpool_find_import(int argc, char **argv);
146*789Sahrens 
147*789Sahrens /*
148*789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
149*789Sahrens  * underlying datasets, only the references to them.
150*789Sahrens  */
151*789Sahrens extern zfs_handle_t *zfs_open(const char *, int);
152*789Sahrens extern void zfs_close(zfs_handle_t *);
153*789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
154*789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
155*789Sahrens 
156*789Sahrens typedef enum {
157*789Sahrens 	ZFS_SRC_NONE = 0x1,
158*789Sahrens 	ZFS_SRC_DEFAULT = 0x2,
159*789Sahrens 	ZFS_SRC_TEMPORARY = 0x4,
160*789Sahrens 	ZFS_SRC_LOCAL = 0x8,
161*789Sahrens 	ZFS_SRC_INHERITED = 0x10
162*789Sahrens } zfs_source_t;
163*789Sahrens 
164*789Sahrens #define	ZFS_SRC_ALL	0x1f
165*789Sahrens 
166*789Sahrens /*
167*789Sahrens  * Property management functions.  Some functions are shared with the kernel,
168*789Sahrens  * and are found in fs/zfs.h.
169*789Sahrens  */
170*789Sahrens const char *zfs_prop_to_name(zfs_prop_t);
171*789Sahrens int zfs_prop_set(zfs_handle_t *, zfs_prop_t, const char *);
172*789Sahrens int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, zfs_source_t *,
173*789Sahrens     char *, size_t, int);
174*789Sahrens int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, zfs_source_t *,
175*789Sahrens     char *, size_t);
176*789Sahrens uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
177*789Sahrens int zfs_prop_validate(zfs_prop_t, const char *, uint64_t *);
178*789Sahrens int zfs_prop_inheritable(zfs_prop_t);
179*789Sahrens int zfs_prop_inherit(zfs_handle_t *, zfs_prop_t);
180*789Sahrens const char *zfs_prop_values(zfs_prop_t);
181*789Sahrens int zfs_prop_valid_for_type(zfs_prop_t, int);
182*789Sahrens void zfs_prop_default_string(zfs_prop_t prop, char *buf, size_t buflen);
183*789Sahrens uint64_t zfs_prop_default_numeric(zfs_prop_t);
184*789Sahrens int zfs_prop_is_string(zfs_prop_t prop);
185*789Sahrens const char *zfs_prop_column_name(zfs_prop_t);
186*789Sahrens const char *zfs_prop_column_format(zfs_prop_t);
187*789Sahrens char ** zfs_prop_column_subopts(void);
188*789Sahrens char ** zfs_prop_column_short_subopts(void);
189*789Sahrens 
190*789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
191*789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
192*789Sahrens 
193*789Sahrens /*
194*789Sahrens  * Iterator functions.
195*789Sahrens  */
196*789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
197*789Sahrens extern int zfs_iter_root(zfs_iter_f, void *);
198*789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
199*789Sahrens extern int zfs_iter_dependents(zfs_handle_t *, zfs_iter_f, void *);
200*789Sahrens 
201*789Sahrens /*
202*789Sahrens  * Functions to create and destroy datasets.
203*789Sahrens  */
204*789Sahrens extern int zfs_create(const char *, zfs_type_t, const char *, const char *);
205*789Sahrens extern int zfs_destroy(zfs_handle_t *);
206*789Sahrens extern int zfs_clone(zfs_handle_t *, const char *);
207*789Sahrens extern int zfs_snapshot(const char *);
208*789Sahrens extern int zfs_rollback(zfs_handle_t *);
209*789Sahrens extern int zfs_rename(zfs_handle_t *, const char *);
210*789Sahrens extern int zfs_backup(zfs_handle_t *, zfs_handle_t *);
211*789Sahrens extern int zfs_restore(const char *, int, int, int);
212*789Sahrens 
213*789Sahrens /*
214*789Sahrens  * Miscellaneous functions.
215*789Sahrens  */
216*789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
217*789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
218*789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
219*789Sahrens 
220*789Sahrens /*
221*789Sahrens  * Mount support functions.
222*789Sahrens  */
223*789Sahrens extern int zfs_is_mounted(zfs_handle_t *, char **);
224*789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
225*789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
226*789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
227*789Sahrens 
228*789Sahrens /*
229*789Sahrens  * Share support functions.
230*789Sahrens  */
231*789Sahrens extern int zfs_is_shared(zfs_handle_t *, char **);
232*789Sahrens extern int zfs_share(zfs_handle_t *);
233*789Sahrens extern int zfs_unshare(zfs_handle_t *, const char *);
234*789Sahrens extern int zfs_unshareall(zfs_handle_t *);
235*789Sahrens 
236*789Sahrens /*
237*789Sahrens  * For clients that need to capture error output.
238*789Sahrens  */
239*789Sahrens extern void zfs_set_error_handler(void (*)(const char *, va_list));
240*789Sahrens 
241*789Sahrens /*
242*789Sahrens  * When dealing with nvlists, verify() is extremely useful
243*789Sahrens  */
244*789Sahrens #ifdef NDEBUG
245*789Sahrens #define	verify(EX)	((void)(EX))
246*789Sahrens #else
247*789Sahrens #define	verify(EX)	assert(EX)
248*789Sahrens #endif
249*789Sahrens 
250*789Sahrens /*
251*789Sahrens  * Utility function to convert a number to a human-readable form.
252*789Sahrens  */
253*789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
254*789Sahrens extern int zfs_nicestrtonum(const char *, uint64_t *);
255*789Sahrens 
256*789Sahrens /*
257*789Sahrens  * Pool destroy special.  Remove the device information without destroying
258*789Sahrens  * the underlying dataset.
259*789Sahrens  */
260*789Sahrens extern int zfs_remove_link(zfs_handle_t *);
261*789Sahrens 
262*789Sahrens /*
263*789Sahrens  * Given a device or file, determine if it is part of a pool.
264*789Sahrens  */
265*789Sahrens extern int zpool_in_use(int fd, char **state,
266*789Sahrens     char **name);
267*789Sahrens 
268*789Sahrens /*
269*789Sahrens  * ftyp special.  Read the label from a given device.
270*789Sahrens  */
271*789Sahrens extern nvlist_t *zpool_read_label(int fd);
272*789Sahrens 
273*789Sahrens /*
274*789Sahrens  * Create and remove zvol /dev links
275*789Sahrens  */
276*789Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
277*789Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
278*789Sahrens 
279*789Sahrens /*
280*789Sahrens  * zoneadmd hack
281*789Sahrens  */
282*789Sahrens extern void zfs_init(void);
283*789Sahrens 
284*789Sahrens /*
285*789Sahrens  * Useful defines
286*789Sahrens  */
287*789Sahrens #ifndef TRUE
288*789Sahrens #define	TRUE	1
289*789Sahrens #endif
290*789Sahrens #ifndef FALSE
291*789Sahrens #define	FALSE	0
292*789Sahrens #endif
293*789Sahrens 
294*789Sahrens #ifdef	__cplusplus
295*789Sahrens }
296*789Sahrens #endif
297*789Sahrens 
298*789Sahrens #endif	/* _LIBZFS_H */
299