1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51485Slling  * Common Development and Distribution License (the "License").
61485Slling  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
213126Sahl 
22789Sahrens /*
235993Smarks  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24789Sahrens  * Use is subject to license terms.
25789Sahrens  */
26789Sahrens 
27789Sahrens #ifndef	_LIBZFS_H
28789Sahrens #define	_LIBZFS_H
29789Sahrens 
30789Sahrens #include <assert.h>
31789Sahrens #include <libnvpair.h>
32789Sahrens #include <sys/param.h>
33789Sahrens #include <sys/types.h>
34789Sahrens #include <sys/varargs.h>
35789Sahrens #include <sys/fs/zfs.h>
364543Smarks #include <sys/avl.h>
374543Smarks #include <ucred.h>
38789Sahrens 
39789Sahrens #ifdef	__cplusplus
40789Sahrens extern "C" {
41789Sahrens #endif
42789Sahrens 
43789Sahrens /*
44789Sahrens  * Miscellaneous ZFS constants
45789Sahrens  */
46789Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
47789Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
48789Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
495094Slling #define	ZPOOL_MAXPROPLEN	MAXPATHLEN
50789Sahrens 
51789Sahrens /*
522082Seschrock  * libzfs errors
532082Seschrock  */
542082Seschrock enum {
552082Seschrock 	EZFS_NOMEM = 2000,	/* out of memory */
562082Seschrock 	EZFS_BADPROP,		/* invalid property value */
572082Seschrock 	EZFS_PROPREADONLY,	/* cannot set readonly property */
582082Seschrock 	EZFS_PROPTYPE,		/* property does not apply to dataset type */
592082Seschrock 	EZFS_PROPNONINHERIT,	/* property is not inheritable */
602082Seschrock 	EZFS_PROPSPACE,		/* bad quota or reservation */
612082Seschrock 	EZFS_BADTYPE,		/* dataset is not of appropriate type */
622082Seschrock 	EZFS_BUSY,		/* pool or dataset is busy */
632082Seschrock 	EZFS_EXISTS,		/* pool or dataset already exists */
642082Seschrock 	EZFS_NOENT,		/* no such pool or dataset */
652082Seschrock 	EZFS_BADSTREAM,		/* bad backup stream */
662082Seschrock 	EZFS_DSREADONLY,	/* dataset is readonly */
672082Seschrock 	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
682082Seschrock 	EZFS_VOLHASDATA,	/* volume already contains data */
692082Seschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
702082Seschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
712082Seschrock 	EZFS_BADBACKUP,		/* backup failed */
722082Seschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
732082Seschrock 	EZFS_NODEVICE,		/* no such device in pool */
742082Seschrock 	EZFS_BADDEV,		/* invalid device to add */
752082Seschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
762082Seschrock 	EZFS_RESILVERING,	/* currently resilvering */
772082Seschrock 	EZFS_BADVERSION,	/* unsupported version */
782082Seschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
792082Seschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
802082Seschrock 	EZFS_BADPATH,		/* must be an absolute path */
812082Seschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
822082Seschrock 	EZFS_ZONED,		/* used improperly in local zone */
832082Seschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
842082Seschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
853126Sahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
863126Sahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
872082Seschrock 	EZFS_DEVLINKS,		/* failed to create zvol links */
882082Seschrock 	EZFS_PERM,		/* permission denied */
892082Seschrock 	EZFS_NOSPC,		/* out of space */
902082Seschrock 	EZFS_IO,		/* I/O error */
912082Seschrock 	EZFS_INTR,		/* signal received */
922082Seschrock 	EZFS_ISSPARE,		/* device is a hot spare */
932082Seschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
942474Seschrock 	EZFS_RECURSIVE,		/* recursive dependency */
952926Sek110237 	EZFS_NOHISTORY,		/* no history object */
963126Sahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
973126Sahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
983912Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
993912Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
1003912Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
1013978Smmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1024276Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1034276Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1044276Staylor 	EZFS_LABELFAILED,	/* write of label failed */
1054543Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
1064543Smarks 	EZFS_BADWHO,		/* invalid permission who */
1074543Smarks 	EZFS_BADPERM,		/* invalid permission */
1084543Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
1094543Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
1104543Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
1115331Samw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
1125331Samw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1135363Seschrock 	EZFS_BADCACHE,		/* bad cache file */
1145450Sbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
1156423Sgw25295 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
1167042Sgw25295 	EZFS_NOTSUP,		/* ops not supported on this dataset */
1177214Slling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
1183912Slling 	EZFS_UNKNOWN
1192082Seschrock };
1202082Seschrock 
1212082Seschrock /*
1224543Smarks  * The following data structures are all part
1234543Smarks  * of the zfs_allow_t data structure which is
1244543Smarks  * used for printing 'allow' permissions.
1254543Smarks  * It is a linked list of zfs_allow_t's which
1264543Smarks  * then contain avl tree's for user/group/sets/...
1274543Smarks  * and each one of the entries in those trees have
1284543Smarks  * avl tree's for the permissions they belong to and
1294543Smarks  * whether they are local,descendent or local+descendent
1304543Smarks  * permissions.  The AVL trees are used primarily for
1314543Smarks  * sorting purposes, but also so that we can quickly find
1324543Smarks  * a given user and or permission.
1334543Smarks  */
1344543Smarks typedef struct zfs_perm_node {
1354543Smarks 	avl_node_t z_node;
1364543Smarks 	char z_pname[MAXPATHLEN];
1374543Smarks } zfs_perm_node_t;
1384543Smarks 
1394543Smarks typedef struct zfs_allow_node {
1404543Smarks 	avl_node_t z_node;
1414543Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
1424543Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
1434543Smarks 	avl_tree_t z_local;		/* local permissions */
1444543Smarks 	avl_tree_t z_descend;		/* descendent permissions */
1454543Smarks } zfs_allow_node_t;
1464543Smarks 
1474543Smarks typedef struct zfs_allow {
1484543Smarks 	struct zfs_allow *z_next;
1494543Smarks 	char z_setpoint[MAXPATHLEN];
1504543Smarks 	avl_tree_t z_sets;
1514543Smarks 	avl_tree_t z_crperms;
1524543Smarks 	avl_tree_t z_user;
1534543Smarks 	avl_tree_t z_group;
1544543Smarks 	avl_tree_t z_everyone;
1554543Smarks } zfs_allow_t;
1564543Smarks 
1574543Smarks /*
158789Sahrens  * Basic handle types
159789Sahrens  */
160789Sahrens typedef struct zfs_handle zfs_handle_t;
161789Sahrens typedef struct zpool_handle zpool_handle_t;
1622082Seschrock typedef struct libzfs_handle libzfs_handle_t;
1632082Seschrock 
1642082Seschrock /*
1652082Seschrock  * Library initialization
1662082Seschrock  */
1672082Seschrock extern libzfs_handle_t *libzfs_init(void);
1682082Seschrock extern void libzfs_fini(libzfs_handle_t *);
1692082Seschrock 
1702082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
1712082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
1722082Seschrock 
1732082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
1742082Seschrock 
1752082Seschrock extern int libzfs_errno(libzfs_handle_t *);
1762082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *);
1772082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *);
178789Sahrens 
179789Sahrens /*
180789Sahrens  * Basic handle functions
181789Sahrens  */
1822082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
1832082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
184789Sahrens extern void zpool_close(zpool_handle_t *);
185789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
186789Sahrens extern int zpool_get_state(zpool_handle_t *);
1875094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
1886865Srm160521 extern void zpool_free_handles(libzfs_handle_t *);
189789Sahrens 
190789Sahrens /*
191789Sahrens  * Iterate over all active pools in the system.
192789Sahrens  */
193789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
1942082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
195789Sahrens 
196789Sahrens /*
197789Sahrens  * Functions to create and destroy pools
198789Sahrens  */
1992082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2007184Stimh     nvlist_t *, nvlist_t *);
201789Sahrens extern int zpool_destroy(zpool_handle_t *);
202789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
203789Sahrens 
204789Sahrens /*
205789Sahrens  * Functions to manipulate pool and vdev state
206789Sahrens  */
207789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
2084451Seschrock extern int zpool_clear(zpool_handle_t *, const char *);
209789Sahrens 
2104451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2114451Seschrock     vdev_state_t *);
2124451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2134451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2144451Seschrock     const char *, nvlist_t *, int);
215789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
2162082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2174451Seschrock 
2184451Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t);
2194451Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t);
2204451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2214451Seschrock 
2225450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
2237326SEric.Schrock@Sun.COM     boolean_t *, boolean_t *);
2244276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
225789Sahrens 
226789Sahrens /*
2273912Slling  * Functions to manage pool properties
2283912Slling  */
2293912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2304451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
2315094Slling     size_t proplen, zprop_source_t *);
2325094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
2335094Slling     zprop_source_t *);
2345094Slling 
2353912Slling extern const char *zpool_prop_to_name(zpool_prop_t);
2363912Slling extern const char *zpool_prop_values(zpool_prop_t);
2373912Slling 
2383912Slling /*
239789Sahrens  * Pool health statistics.
240789Sahrens  */
241789Sahrens typedef enum {
242789Sahrens 	/*
243789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
2441003Slling 	 * event namespace.  Each is associated with a corresponding message ID.
245789Sahrens 	 */
246789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
247789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
248789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
249789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
2501003Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
251789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
252789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
253789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
254789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
2551760Seschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
2563975Sek110237 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2576523Sek110237 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
2586523Sek110237 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
2594451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2604451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
2617294Sperrin 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
262789Sahrens 
263789Sahrens 	/*
264789Sahrens 	 * The following are not faults per se, but still an error possibly
2651003Slling 	 * requiring administrative attention.  There is no corresponding
266789Sahrens 	 * message ID.
267789Sahrens 	 */
2681760Seschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
269789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
270789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
271789Sahrens 
272789Sahrens 	/*
273789Sahrens 	 * Finally, the following indicates a healthy pool.
274789Sahrens 	 */
275789Sahrens 	ZPOOL_STATUS_OK
276789Sahrens } zpool_status_t;
277789Sahrens 
2781544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
2791544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
280789Sahrens 
281789Sahrens /*
282789Sahrens  * Statistics and configuration functions.
283789Sahrens  */
2841544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
2852142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
2863444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
2871544Seschrock 
288789Sahrens /*
289789Sahrens  * Import and export functions
290789Sahrens  */
2917214Slling extern int zpool_export(zpool_handle_t *, boolean_t);
292*8211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *);
2932082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
2945094Slling     char *altroot);
2955094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
2966643Seschrock     nvlist_t *, boolean_t);
297789Sahrens 
298789Sahrens /*
299789Sahrens  * Search for pools to import
300789Sahrens  */
3016807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
3025994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
3036957Sck153898     char *, uint64_t);
3046807Sck153898 extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **,
3056807Sck153898     char *);
3066807Sck153898 extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **,
3076807Sck153898     uint64_t);
3086807Sck153898 extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **);
309789Sahrens 
310789Sahrens /*
3111354Seschrock  * Miscellaneous pool functions
3121354Seschrock  */
3134543Smarks struct zfs_cmd;
3144543Smarks 
3152082Seschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *);
3165094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
3172926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
3184988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc,
3194988Sek110237     char **argv, char *history_str);
3204988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *);
3213444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
3223444Sek110237     size_t len);
3234543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
3247656SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *);
3251354Seschrock /*
326789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
327789Sahrens  * underlying datasets, only the references to them.
328789Sahrens  */
3292082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
330789Sahrens extern void zfs_close(zfs_handle_t *);
331789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
332789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
3337538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
334789Sahrens 
335789Sahrens /*
336789Sahrens  * Property management functions.  Some functions are shared with the kernel,
3371003Slling  * and are found in sys/fs/zfs.h.
338789Sahrens  */
3395094Slling 
3405094Slling /*
3415094Slling  * zfs dataset property management
3425094Slling  */
3435094Slling extern const char *zfs_prop_default_string(zfs_prop_t);
3442676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
3452676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t);
3462676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
3472676Seschrock 
3487184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
3497184Stimh     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
3507184Stimh 
3515094Slling extern const char *zfs_prop_to_name(zfs_prop_t);
3525094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
3535094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
3545094Slling     zprop_source_t *, char *, size_t, boolean_t);
3555094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
3565094Slling     zprop_source_t *, char *, size_t);
3575094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
3585094Slling extern int zfs_prop_inherit(zfs_handle_t *, const char *);
3595094Slling extern const char *zfs_prop_values(zfs_prop_t);
3605094Slling extern int zfs_prop_is_string(zfs_prop_t prop);
3615094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
3625094Slling 
3635094Slling typedef struct zprop_list {
3645094Slling 	int		pl_prop;
3652676Seschrock 	char		*pl_user_prop;
3665094Slling 	struct zprop_list *pl_next;
3672676Seschrock 	boolean_t	pl_all;
3682676Seschrock 	size_t		pl_width;
3692676Seschrock 	boolean_t	pl_fixed;
3705094Slling } zprop_list_t;
3713912Slling 
3725094Slling extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **);
373789Sahrens 
374789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
375789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
376789Sahrens 
377789Sahrens /*
3785094Slling  * zpool property management
3795094Slling  */
3805094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
3815094Slling extern const char *zpool_prop_default_string(zpool_prop_t);
3825094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
3835094Slling extern const char *zpool_prop_column_name(zpool_prop_t);
3845094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
3855094Slling 
3865094Slling /*
3875094Slling  * Functions shared by zfs and zpool property management.
3883912Slling  */
3895094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
3905094Slling     boolean_t ordered, zfs_type_t type);
3915094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
3925094Slling     zfs_type_t);
3935094Slling extern void zprop_free_list(zprop_list_t *);
3945094Slling 
3955094Slling /*
3965094Slling  * Functions for printing zfs or zpool properties
3975094Slling  */
3985094Slling typedef struct zprop_get_cbdata {
3993912Slling 	int cb_sources;
4003912Slling 	int cb_columns[4];
4013912Slling 	int cb_colwidths[5];
4023912Slling 	boolean_t cb_scripted;
4033912Slling 	boolean_t cb_literal;
4043912Slling 	boolean_t cb_first;
4055094Slling 	zprop_list_t *cb_proplist;
4065094Slling 	zfs_type_t cb_type;
4075094Slling } zprop_get_cbdata_t;
4083912Slling 
4095094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
4105094Slling     const char *, const char *, zprop_source_t, const char *);
4113912Slling 
4123912Slling #define	GET_COL_NAME		1
4133912Slling #define	GET_COL_PROPERTY	2
4143912Slling #define	GET_COL_VALUE		3
4153912Slling #define	GET_COL_SOURCE		4
4163912Slling 
4173912Slling /*
418789Sahrens  * Iterator functions.
419789Sahrens  */
420789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
4212082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
422789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
4232474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
4241356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
4251356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
426789Sahrens 
427789Sahrens /*
428789Sahrens  * Functions to create and destroy datasets.
429789Sahrens  */
4302082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
4312676Seschrock     nvlist_t *);
4324490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
433789Sahrens extern int zfs_destroy(zfs_handle_t *);
4342199Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *);
4352676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
4367265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
4375749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
4384490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
4395367Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
4405367Sahrens     boolean_t, boolean_t, boolean_t, boolean_t, int);
4412082Seschrock extern int zfs_promote(zfs_handle_t *);
442789Sahrens 
4435367Sahrens typedef struct recvflags {
4445446Sahrens 	/* print informational messages (ie, -v was specified) */
4455501Seschrock 	int verbose : 1;
4465446Sahrens 
4475446Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
4485501Seschrock 	int isprefix : 1;
4495446Sahrens 
4505446Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
4515501Seschrock 	int dryrun : 1;
4525446Sahrens 
4535446Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
4545501Seschrock 	int force : 1;
4555446Sahrens 
4565446Sahrens 	/* set "canmount=off" on all modified filesystems */
4575501Seschrock 	int canmountoff : 1;
4585446Sahrens 
4595446Sahrens 	/* byteswap flag is used internally; callers need not specify */
4605501Seschrock 	int byteswap : 1;
4615367Sahrens } recvflags_t;
4625367Sahrens 
4635367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t,
4645367Sahrens     int, avl_tree_t *);
4655367Sahrens 
466789Sahrens /*
467789Sahrens  * Miscellaneous functions.
468789Sahrens  */
469789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
470789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
471789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
4723635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
4734490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
4744490Svb160487     zfs_type_t);
4755713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *);
476789Sahrens 
477789Sahrens /*
4784543Smarks  * dataset permission functions.
4794543Smarks  */
4804543Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *);
4814543Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *);
4824543Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *,
4834543Smarks     zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t);
4844543Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **);
4854543Smarks extern void zfs_free_allows(zfs_allow_t *);
4865993Smarks extern void zfs_deleg_permissions(void);
4874543Smarks 
4884543Smarks /*
489789Sahrens  * Mount support functions.
490789Sahrens  */
4913444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
4922082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
493789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
494789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
495789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
496789Sahrens 
497789Sahrens /*
498789Sahrens  * Share support functions.
499789Sahrens  */
5003126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *);
501789Sahrens extern int zfs_share(zfs_handle_t *);
5023126Sahl extern int zfs_unshare(zfs_handle_t *);
5033126Sahl 
5043126Sahl /*
5054451Seschrock  * Protocol-specific share support functions.
5063126Sahl  */
5073126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
5085331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
5093126Sahl extern int zfs_share_nfs(zfs_handle_t *);
5105331Samw extern int zfs_share_smb(zfs_handle_t *);
5115331Samw extern int zfs_shareall(zfs_handle_t *);
5123126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
5135331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
5143126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *);
5155331Samw extern int zfs_unshareall_smb(zfs_handle_t *);
5165331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
5175331Samw extern int zfs_unshareall(zfs_handle_t *);
5183126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
5193126Sahl extern int zfs_share_iscsi(zfs_handle_t *);
5203126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *);
5214543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
5224543Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *,
5235331Samw     void *, void *, int, zfs_share_op_t);
524789Sahrens 
525789Sahrens /*
526789Sahrens  * When dealing with nvlists, verify() is extremely useful
527789Sahrens  */
528789Sahrens #ifdef NDEBUG
529789Sahrens #define	verify(EX)	((void)(EX))
530789Sahrens #else
531789Sahrens #define	verify(EX)	assert(EX)
532789Sahrens #endif
533789Sahrens 
534789Sahrens /*
535789Sahrens  * Utility function to convert a number to a human-readable form.
536789Sahrens  */
537789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
5382676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
539789Sahrens 
540789Sahrens /*
541789Sahrens  * Given a device or file, determine if it is part of a pool.
542789Sahrens  */
5432082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
5442082Seschrock     boolean_t *);
545789Sahrens 
546789Sahrens /*
547789Sahrens  * ftyp special.  Read the label from a given device.
548789Sahrens  */
5492082Seschrock extern int zpool_read_label(int, nvlist_t **);
550789Sahrens 
551789Sahrens /*
5523126Sahl  * Create and remove zvol /dev links.
553789Sahrens  */
554789Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
555789Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
556789Sahrens 
5576423Sgw25295 /* is this zvol valid for use as a dump device? */
5586423Sgw25295 extern int zvol_check_dump_config(char *);
5596423Sgw25295 
5602474Seschrock /*
5613126Sahl  * Enable and disable datasets within a pool by mounting/unmounting and
5623126Sahl  * sharing/unsharing them.
5632474Seschrock  */
5643126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
5653126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
5662474Seschrock 
567789Sahrens #ifdef	__cplusplus
568789Sahrens }
569789Sahrens #endif
570789Sahrens 
571789Sahrens #endif	/* _LIBZFS_H */
572