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 /*
233444Sek110237  * Copyright 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31789Sahrens 
32789Sahrens #include <assert.h>
33789Sahrens #include <libnvpair.h>
34789Sahrens #include <sys/param.h>
35789Sahrens #include <sys/types.h>
36789Sahrens #include <sys/varargs.h>
37789Sahrens #include <sys/fs/zfs.h>
384543Smarks #include <sys/avl.h>
394543Smarks #include <ucred.h>
40789Sahrens 
41789Sahrens #ifdef	__cplusplus
42789Sahrens extern "C" {
43789Sahrens #endif
44789Sahrens 
45789Sahrens /*
46789Sahrens  * Miscellaneous ZFS constants
47789Sahrens  */
48789Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
49789Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
50789Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
51789Sahrens 
52789Sahrens /*
532082Seschrock  * libzfs errors
542082Seschrock  */
552082Seschrock enum {
562082Seschrock 	EZFS_NOMEM = 2000,	/* out of memory */
572082Seschrock 	EZFS_BADPROP,		/* invalid property value */
582082Seschrock 	EZFS_PROPREADONLY,	/* cannot set readonly property */
592082Seschrock 	EZFS_PROPTYPE,		/* property does not apply to dataset type */
602082Seschrock 	EZFS_PROPNONINHERIT,	/* property is not inheritable */
612082Seschrock 	EZFS_PROPSPACE,		/* bad quota or reservation */
622082Seschrock 	EZFS_BADTYPE,		/* dataset is not of appropriate type */
632082Seschrock 	EZFS_BUSY,		/* pool or dataset is busy */
642082Seschrock 	EZFS_EXISTS,		/* pool or dataset already exists */
652082Seschrock 	EZFS_NOENT,		/* no such pool or dataset */
662082Seschrock 	EZFS_BADSTREAM,		/* bad backup stream */
672082Seschrock 	EZFS_DSREADONLY,	/* dataset is readonly */
682082Seschrock 	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
692082Seschrock 	EZFS_VOLHASDATA,	/* volume already contains data */
702082Seschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
712082Seschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
722082Seschrock 	EZFS_BADBACKUP,		/* backup failed */
732082Seschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
742082Seschrock 	EZFS_NODEVICE,		/* no such device in pool */
752082Seschrock 	EZFS_BADDEV,		/* invalid device to add */
762082Seschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
772082Seschrock 	EZFS_RESILVERING,	/* currently resilvering */
782082Seschrock 	EZFS_BADVERSION,	/* unsupported version */
792082Seschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
802082Seschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
812082Seschrock 	EZFS_BADPATH,		/* must be an absolute path */
822082Seschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
832082Seschrock 	EZFS_ZONED,		/* used improperly in local zone */
842082Seschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
852082Seschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
863126Sahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
873126Sahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
882082Seschrock 	EZFS_DEVLINKS,		/* failed to create zvol links */
892082Seschrock 	EZFS_PERM,		/* permission denied */
902082Seschrock 	EZFS_NOSPC,		/* out of space */
912082Seschrock 	EZFS_IO,		/* I/O error */
922082Seschrock 	EZFS_INTR,		/* signal received */
932082Seschrock 	EZFS_ISSPARE,		/* device is a hot spare */
942082Seschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
952474Seschrock 	EZFS_RECURSIVE,		/* recursive dependency */
962926Sek110237 	EZFS_NOHISTORY,		/* no history object */
973126Sahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
983126Sahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
993912Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
1003912Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
1013912Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
1023978Smmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1034276Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1044276Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1054276Staylor 	EZFS_LABELFAILED,	/* write of label failed */
1064543Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
1074543Smarks 	EZFS_BADWHO,		/* invalid permission who */
1084543Smarks 	EZFS_BADPERM,		/* invalid permission */
1094543Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
1104543Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
1114543Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
1123912Slling 	EZFS_UNKNOWN
1132082Seschrock };
1142082Seschrock 
1152082Seschrock /*
1164543Smarks  * The following data structures are all part
1174543Smarks  * of the zfs_allow_t data structure which is
1184543Smarks  * used for printing 'allow' permissions.
1194543Smarks  * It is a linked list of zfs_allow_t's which
1204543Smarks  * then contain avl tree's for user/group/sets/...
1214543Smarks  * and each one of the entries in those trees have
1224543Smarks  * avl tree's for the permissions they belong to and
1234543Smarks  * whether they are local,descendent or local+descendent
1244543Smarks  * permissions.  The AVL trees are used primarily for
1254543Smarks  * sorting purposes, but also so that we can quickly find
1264543Smarks  * a given user and or permission.
1274543Smarks  */
1284543Smarks typedef struct zfs_perm_node {
1294543Smarks 	avl_node_t z_node;
1304543Smarks 	char z_pname[MAXPATHLEN];
1314543Smarks } zfs_perm_node_t;
1324543Smarks 
1334543Smarks typedef struct zfs_allow_node {
1344543Smarks 	avl_node_t z_node;
1354543Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
1364543Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
1374543Smarks 	avl_tree_t z_local;		/* local permissions */
1384543Smarks 	avl_tree_t z_descend;		/* descendent permissions */
1394543Smarks } zfs_allow_node_t;
1404543Smarks 
1414543Smarks typedef struct zfs_allow {
1424543Smarks 	struct zfs_allow *z_next;
1434543Smarks 	char z_setpoint[MAXPATHLEN];
1444543Smarks 	avl_tree_t z_sets;
1454543Smarks 	avl_tree_t z_crperms;
1464543Smarks 	avl_tree_t z_user;
1474543Smarks 	avl_tree_t z_group;
1484543Smarks 	avl_tree_t z_everyone;
1494543Smarks } zfs_allow_t;
1504543Smarks 
1514543Smarks /*
152789Sahrens  * Basic handle types
153789Sahrens  */
154789Sahrens typedef struct zfs_handle zfs_handle_t;
155789Sahrens typedef struct zpool_handle zpool_handle_t;
1562082Seschrock typedef struct libzfs_handle libzfs_handle_t;
1572082Seschrock 
1582082Seschrock /*
1592082Seschrock  * Library initialization
1602082Seschrock  */
1612082Seschrock extern libzfs_handle_t *libzfs_init(void);
1622082Seschrock extern void libzfs_fini(libzfs_handle_t *);
1632082Seschrock 
1642082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
1652082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
1662082Seschrock 
1672082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
1682082Seschrock 
1692082Seschrock extern int libzfs_errno(libzfs_handle_t *);
1702082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *);
1712082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *);
172789Sahrens 
173789Sahrens /*
174789Sahrens  * Basic handle functions
175789Sahrens  */
1762082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
1772082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
178789Sahrens extern void zpool_close(zpool_handle_t *);
179789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
180789Sahrens extern uint64_t zpool_get_guid(zpool_handle_t *);
181789Sahrens extern uint64_t zpool_get_space_used(zpool_handle_t *);
182789Sahrens extern uint64_t zpool_get_space_total(zpool_handle_t *);
183789Sahrens extern int zpool_get_root(zpool_handle_t *, char *, size_t);
184789Sahrens extern int zpool_get_state(zpool_handle_t *);
1852082Seschrock extern uint64_t zpool_get_version(zpool_handle_t *);
186789Sahrens 
187789Sahrens /*
188789Sahrens  * Iterate over all active pools in the system.
189789Sahrens  */
190789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
1912082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
192789Sahrens 
193789Sahrens /*
194789Sahrens  * Functions to create and destroy pools
195789Sahrens  */
1962082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
1972082Seschrock     const char *);
198789Sahrens extern int zpool_destroy(zpool_handle_t *);
199789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
200789Sahrens 
201789Sahrens /*
202789Sahrens  * Functions to manipulate pool and vdev state
203789Sahrens  */
204789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
2054451Seschrock extern int zpool_clear(zpool_handle_t *, const char *);
206789Sahrens 
2074451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2084451Seschrock     vdev_state_t *);
2094451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2104451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2114451Seschrock     const char *, nvlist_t *, int);
212789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
2132082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2144451Seschrock 
2154451Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t);
2164451Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t);
2174451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2184451Seschrock 
2192082Seschrock extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *);
2204276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
221789Sahrens 
222789Sahrens /*
2233912Slling  * Functions to manage pool properties
2243912Slling  */
2253912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2264451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
2273912Slling 	size_t proplen, zfs_source_t *);
2284451Seschrock extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t);
2293912Slling extern const char *zpool_prop_to_name(zpool_prop_t);
2303912Slling extern const char *zpool_prop_values(zpool_prop_t);
2313912Slling 
2323912Slling /*
233789Sahrens  * Pool health statistics.
234789Sahrens  */
235789Sahrens typedef enum {
236789Sahrens 	/*
237789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
2381003Slling 	 * event namespace.  Each is associated with a corresponding message ID.
239789Sahrens 	 */
240789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
241789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
242789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
243789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
2441003Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
245789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
246789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
247789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
248789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
2491760Seschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
2503975Sek110237 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2514451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2524451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
253789Sahrens 
254789Sahrens 	/*
255789Sahrens 	 * The following are not faults per se, but still an error possibly
2561003Slling 	 * requiring administrative attention.  There is no corresponding
257789Sahrens 	 * message ID.
258789Sahrens 	 */
2591760Seschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
260789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
261789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
262789Sahrens 
263789Sahrens 	/*
264789Sahrens 	 * Finally, the following indicates a healthy pool.
265789Sahrens 	 */
266789Sahrens 	ZPOOL_STATUS_OK
267789Sahrens } zpool_status_t;
268789Sahrens 
2691544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
2701544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
271789Sahrens 
272789Sahrens /*
273789Sahrens  * Statistics and configuration functions.
274789Sahrens  */
2751544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
2762142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
2773444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
2781544Seschrock 
279789Sahrens /*
280789Sahrens  * Import and export functions
281789Sahrens  */
282789Sahrens extern int zpool_export(zpool_handle_t *);
2832082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
2842082Seschrock     const char *);
285789Sahrens 
286789Sahrens /*
287789Sahrens  * Search for pools to import
288789Sahrens  */
2892082Seschrock extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
290789Sahrens 
291789Sahrens /*
2921354Seschrock  * Miscellaneous pool functions
2931354Seschrock  */
2944543Smarks struct zfs_cmd;
2954543Smarks 
2962082Seschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *);
2971760Seschrock extern int zpool_upgrade(zpool_handle_t *);
2982926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
299*4988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc,
300*4988Sek110237     char **argv, char *history_str);
301*4988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *);
3023444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
3033444Sek110237     size_t len);
3044543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
3051354Seschrock /*
306789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
307789Sahrens  * underlying datasets, only the references to them.
308789Sahrens  */
3092082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
310789Sahrens extern void zfs_close(zfs_handle_t *);
311789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
312789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
313789Sahrens 
314789Sahrens /*
315789Sahrens  * Property management functions.  Some functions are shared with the kernel,
3161003Slling  * and are found in sys/fs/zfs.h.
317789Sahrens  */
3182676Seschrock extern const char *zfs_prop_to_name(zfs_prop_t);
3192676Seschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
3202676Seschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
3212676Seschrock     zfs_source_t *, char *, size_t, boolean_t);
3222676Seschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
3232676Seschrock     zfs_source_t *, char *, size_t);
3242676Seschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
3252676Seschrock extern const char *zfs_prop_get_string(zfs_handle_t *, zfs_prop_t);
3262676Seschrock extern int zfs_prop_inherit(zfs_handle_t *, const char *);
3272676Seschrock extern const char *zfs_prop_values(zfs_prop_t);
3282676Seschrock extern int zfs_prop_valid_for_type(zfs_prop_t, int);
3292676Seschrock extern const char *zfs_prop_default_string(zfs_prop_t prop);
3302676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
3312676Seschrock extern int zfs_prop_is_string(zfs_prop_t prop);
3322676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t);
3332676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
3342676Seschrock 
3352676Seschrock typedef struct zfs_proplist {
3362676Seschrock 	zfs_prop_t	pl_prop;
3372676Seschrock 	char		*pl_user_prop;
3382676Seschrock 	struct zfs_proplist *pl_next;
3392676Seschrock 	boolean_t	pl_all;
3402676Seschrock 	size_t		pl_width;
3412676Seschrock 	boolean_t	pl_fixed;
3422676Seschrock } zfs_proplist_t;
3432676Seschrock 
3443912Slling typedef zfs_proplist_t zpool_proplist_t;
3453912Slling 
3462676Seschrock extern int zfs_get_proplist(libzfs_handle_t *, char *, zfs_proplist_t **);
3473912Slling extern int zpool_get_proplist(libzfs_handle_t *, char *, zpool_proplist_t **);
3483912Slling extern int zfs_expand_proplist(zfs_handle_t *, zfs_proplist_t **);
3493912Slling extern int zpool_expand_proplist(zpool_handle_t *, zpool_proplist_t **);
3502676Seschrock extern void zfs_free_proplist(zfs_proplist_t *);
3512676Seschrock extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
352789Sahrens 
353789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
354789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
355789Sahrens 
356789Sahrens /*
3573912Slling  * Functions for printing properties from zfs/zpool
3583912Slling  */
3593912Slling typedef struct libzfs_get_cbdata {
3603912Slling 	int cb_sources;
3613912Slling 	int cb_columns[4];
3623912Slling 	int cb_colwidths[5];
3633912Slling 	boolean_t cb_scripted;
3643912Slling 	boolean_t cb_literal;
3653912Slling 	boolean_t cb_first;
3663912Slling 	zfs_proplist_t *cb_proplist;
3673912Slling } libzfs_get_cbdata_t;
3683912Slling 
3693912Slling void libzfs_print_one_property(const char *, libzfs_get_cbdata_t *,
3703912Slling     const char *, const char *, zfs_source_t, const char *);
3713912Slling 
3723912Slling #define	GET_COL_NAME		1
3733912Slling #define	GET_COL_PROPERTY	2
3743912Slling #define	GET_COL_VALUE		3
3753912Slling #define	GET_COL_SOURCE		4
3763912Slling 
3773912Slling /*
378789Sahrens  * Iterator functions.
379789Sahrens  */
380789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
3812082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
382789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
3832474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
3841356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
3851356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
386789Sahrens 
387789Sahrens /*
388789Sahrens  * Functions to create and destroy datasets.
389789Sahrens  */
3902082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
3912676Seschrock     nvlist_t *);
3924490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
393789Sahrens extern int zfs_destroy(zfs_handle_t *);
3942199Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *);
3952676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
3962199Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t);
3971294Slling extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, int);
3984490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
3993504Sahl extern int zfs_send(zfs_handle_t *, const char *, int);
4002665Snd150628 extern int zfs_receive(libzfs_handle_t *, const char *, int, int, int,
4013504Sahl     boolean_t, int);
4022082Seschrock extern int zfs_promote(zfs_handle_t *);
403789Sahrens 
404789Sahrens /*
405789Sahrens  * Miscellaneous functions.
406789Sahrens  */
407789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
408789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
409789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
4103635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
4114490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
4124490Svb160487     zfs_type_t);
413789Sahrens 
414789Sahrens /*
4154543Smarks  * dataset permission functions.
4164543Smarks  */
4174543Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *);
4184543Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *);
4194543Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *,
4204543Smarks     zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t);
4214543Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **);
4224543Smarks extern void zfs_free_allows(zfs_allow_t *);
4234543Smarks 
4244543Smarks /*
425789Sahrens  * Mount support functions.
426789Sahrens  */
4273444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
4282082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
429789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
430789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
431789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
432789Sahrens 
433789Sahrens /*
434789Sahrens  * Share support functions.
435789Sahrens  */
4363126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *);
437789Sahrens extern int zfs_share(zfs_handle_t *);
4383126Sahl extern int zfs_unshare(zfs_handle_t *);
4393126Sahl 
4403126Sahl /*
4414451Seschrock  * Protocol-specific share support functions.
4423126Sahl  */
4433126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
4443126Sahl extern int zfs_share_nfs(zfs_handle_t *);
4453126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
4463126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *);
4473126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
4483126Sahl extern int zfs_share_iscsi(zfs_handle_t *);
4493126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *);
4504543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
4514543Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *,
4524543Smarks     void *, void *, int, boolean_t);
453789Sahrens 
454789Sahrens /*
455789Sahrens  * When dealing with nvlists, verify() is extremely useful
456789Sahrens  */
457789Sahrens #ifdef NDEBUG
458789Sahrens #define	verify(EX)	((void)(EX))
459789Sahrens #else
460789Sahrens #define	verify(EX)	assert(EX)
461789Sahrens #endif
462789Sahrens 
463789Sahrens /*
464789Sahrens  * Utility function to convert a number to a human-readable form.
465789Sahrens  */
466789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
4672676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
468789Sahrens 
469789Sahrens /*
470789Sahrens  * Pool destroy special.  Remove the device information without destroying
471789Sahrens  * the underlying dataset.
472789Sahrens  */
473789Sahrens extern int zfs_remove_link(zfs_handle_t *);
474789Sahrens 
475789Sahrens /*
476789Sahrens  * Given a device or file, determine if it is part of a pool.
477789Sahrens  */
4782082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
4792082Seschrock     boolean_t *);
480789Sahrens 
481789Sahrens /*
482789Sahrens  * ftyp special.  Read the label from a given device.
483789Sahrens  */
4842082Seschrock extern int zpool_read_label(int, nvlist_t **);
485789Sahrens 
486789Sahrens /*
4873126Sahl  * Create and remove zvol /dev links.
488789Sahrens  */
489789Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
490789Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
491789Sahrens 
4922474Seschrock /*
4933126Sahl  * Enable and disable datasets within a pool by mounting/unmounting and
4943126Sahl  * sharing/unsharing them.
4952474Seschrock  */
4963126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
4973126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
4982474Seschrock 
499789Sahrens #ifdef	__cplusplus
500789Sahrens }
501789Sahrens #endif
502789Sahrens 
503789Sahrens #endif	/* _LIBZFS_H */
504