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>
32*8228SEric.Taylor@Sun.COM #include <sys/mnttab.h>
33789Sahrens #include <sys/param.h>
34789Sahrens #include <sys/types.h>
35789Sahrens #include <sys/varargs.h>
36789Sahrens #include <sys/fs/zfs.h>
374543Smarks #include <sys/avl.h>
384543Smarks #include <ucred.h>
39789Sahrens 
40789Sahrens #ifdef	__cplusplus
41789Sahrens extern "C" {
42789Sahrens #endif
43789Sahrens 
44789Sahrens /*
45789Sahrens  * Miscellaneous ZFS constants
46789Sahrens  */
47789Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
48789Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
49789Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
505094Slling #define	ZPOOL_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 */
1125331Samw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
1135331Samw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1145363Seschrock 	EZFS_BADCACHE,		/* bad cache file */
1155450Sbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
1166423Sgw25295 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
1177042Sgw25295 	EZFS_NOTSUP,		/* ops not supported on this dataset */
1187214Slling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
1193912Slling 	EZFS_UNKNOWN
1202082Seschrock };
1212082Seschrock 
1222082Seschrock /*
1234543Smarks  * The following data structures are all part
1244543Smarks  * of the zfs_allow_t data structure which is
1254543Smarks  * used for printing 'allow' permissions.
1264543Smarks  * It is a linked list of zfs_allow_t's which
1274543Smarks  * then contain avl tree's for user/group/sets/...
1284543Smarks  * and each one of the entries in those trees have
1294543Smarks  * avl tree's for the permissions they belong to and
1304543Smarks  * whether they are local,descendent or local+descendent
1314543Smarks  * permissions.  The AVL trees are used primarily for
1324543Smarks  * sorting purposes, but also so that we can quickly find
1334543Smarks  * a given user and or permission.
1344543Smarks  */
1354543Smarks typedef struct zfs_perm_node {
1364543Smarks 	avl_node_t z_node;
1374543Smarks 	char z_pname[MAXPATHLEN];
1384543Smarks } zfs_perm_node_t;
1394543Smarks 
1404543Smarks typedef struct zfs_allow_node {
1414543Smarks 	avl_node_t z_node;
1424543Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
1434543Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
1444543Smarks 	avl_tree_t z_local;		/* local permissions */
1454543Smarks 	avl_tree_t z_descend;		/* descendent permissions */
1464543Smarks } zfs_allow_node_t;
1474543Smarks 
1484543Smarks typedef struct zfs_allow {
1494543Smarks 	struct zfs_allow *z_next;
1504543Smarks 	char z_setpoint[MAXPATHLEN];
1514543Smarks 	avl_tree_t z_sets;
1524543Smarks 	avl_tree_t z_crperms;
1534543Smarks 	avl_tree_t z_user;
1544543Smarks 	avl_tree_t z_group;
1554543Smarks 	avl_tree_t z_everyone;
1564543Smarks } zfs_allow_t;
1574543Smarks 
1584543Smarks /*
159789Sahrens  * Basic handle types
160789Sahrens  */
161789Sahrens typedef struct zfs_handle zfs_handle_t;
162789Sahrens typedef struct zpool_handle zpool_handle_t;
1632082Seschrock typedef struct libzfs_handle libzfs_handle_t;
1642082Seschrock 
1652082Seschrock /*
1662082Seschrock  * Library initialization
1672082Seschrock  */
1682082Seschrock extern libzfs_handle_t *libzfs_init(void);
1692082Seschrock extern void libzfs_fini(libzfs_handle_t *);
1702082Seschrock 
1712082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
1722082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
1732082Seschrock 
1742082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
1752082Seschrock 
1762082Seschrock extern int libzfs_errno(libzfs_handle_t *);
1772082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *);
1782082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *);
179*8228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *);
180*8228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *);
181*8228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
182*8228SEric.Taylor@Sun.COM     struct mnttab *);
183*8228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
184*8228SEric.Taylor@Sun.COM     const char *, const char *);
185*8228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
186789Sahrens 
187789Sahrens /*
188789Sahrens  * Basic handle functions
189789Sahrens  */
1902082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
1912082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
192789Sahrens extern void zpool_close(zpool_handle_t *);
193789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
194789Sahrens extern int zpool_get_state(zpool_handle_t *);
1955094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
1966865Srm160521 extern void zpool_free_handles(libzfs_handle_t *);
197789Sahrens 
198789Sahrens /*
199789Sahrens  * Iterate over all active pools in the system.
200789Sahrens  */
201789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
2022082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
203789Sahrens 
204789Sahrens /*
205789Sahrens  * Functions to create and destroy pools
206789Sahrens  */
2072082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2087184Stimh     nvlist_t *, nvlist_t *);
209789Sahrens extern int zpool_destroy(zpool_handle_t *);
210789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
211789Sahrens 
212789Sahrens /*
213789Sahrens  * Functions to manipulate pool and vdev state
214789Sahrens  */
215789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
2164451Seschrock extern int zpool_clear(zpool_handle_t *, const char *);
217789Sahrens 
2184451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2194451Seschrock     vdev_state_t *);
2204451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2214451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2224451Seschrock     const char *, nvlist_t *, int);
223789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
2242082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2254451Seschrock 
2264451Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t);
2274451Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t);
2284451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2294451Seschrock 
2305450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
2317326SEric.Schrock@Sun.COM     boolean_t *, boolean_t *);
2324276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
233789Sahrens 
234789Sahrens /*
2353912Slling  * Functions to manage pool properties
2363912Slling  */
2373912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2384451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
2395094Slling     size_t proplen, zprop_source_t *);
2405094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
2415094Slling     zprop_source_t *);
2425094Slling 
2433912Slling extern const char *zpool_prop_to_name(zpool_prop_t);
2443912Slling extern const char *zpool_prop_values(zpool_prop_t);
2453912Slling 
2463912Slling /*
247789Sahrens  * Pool health statistics.
248789Sahrens  */
249789Sahrens typedef enum {
250789Sahrens 	/*
251789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
2521003Slling 	 * event namespace.  Each is associated with a corresponding message ID.
253789Sahrens 	 */
254789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
255789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
256789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
257789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
2581003Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
259789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
260789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
261789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
262789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
2631760Seschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
2643975Sek110237 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2656523Sek110237 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
2666523Sek110237 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
2674451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2684451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
2697294Sperrin 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
270789Sahrens 
271789Sahrens 	/*
272789Sahrens 	 * The following are not faults per se, but still an error possibly
2731003Slling 	 * requiring administrative attention.  There is no corresponding
274789Sahrens 	 * message ID.
275789Sahrens 	 */
2761760Seschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
277789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
278789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
279789Sahrens 
280789Sahrens 	/*
281789Sahrens 	 * Finally, the following indicates a healthy pool.
282789Sahrens 	 */
283789Sahrens 	ZPOOL_STATUS_OK
284789Sahrens } zpool_status_t;
285789Sahrens 
2861544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
2871544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
288789Sahrens 
289789Sahrens /*
290789Sahrens  * Statistics and configuration functions.
291789Sahrens  */
2921544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
2932142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
2943444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
2951544Seschrock 
296789Sahrens /*
297789Sahrens  * Import and export functions
298789Sahrens  */
2997214Slling extern int zpool_export(zpool_handle_t *, boolean_t);
3008211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *);
3012082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
3025094Slling     char *altroot);
3035094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
3046643Seschrock     nvlist_t *, boolean_t);
305789Sahrens 
306789Sahrens /*
307789Sahrens  * Search for pools to import
308789Sahrens  */
3096807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
3105994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
3116957Sck153898     char *, uint64_t);
3126807Sck153898 extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **,
3136807Sck153898     char *);
3146807Sck153898 extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **,
3156807Sck153898     uint64_t);
3166807Sck153898 extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **);
317789Sahrens 
318789Sahrens /*
3191354Seschrock  * Miscellaneous pool functions
3201354Seschrock  */
3214543Smarks struct zfs_cmd;
3224543Smarks 
3232082Seschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *);
3245094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
3252926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
3264988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc,
3274988Sek110237     char **argv, char *history_str);
3284988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *);
3293444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
3303444Sek110237     size_t len);
3314543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
3327656SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *);
3331354Seschrock /*
334789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
335789Sahrens  * underlying datasets, only the references to them.
336789Sahrens  */
3372082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
338789Sahrens extern void zfs_close(zfs_handle_t *);
339789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
340789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
3417538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
342789Sahrens 
343789Sahrens /*
344789Sahrens  * Property management functions.  Some functions are shared with the kernel,
3451003Slling  * and are found in sys/fs/zfs.h.
346789Sahrens  */
3475094Slling 
3485094Slling /*
3495094Slling  * zfs dataset property management
3505094Slling  */
3515094Slling extern const char *zfs_prop_default_string(zfs_prop_t);
3522676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
3532676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t);
3542676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
3552676Seschrock 
3567184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
3577184Stimh     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
3587184Stimh 
3595094Slling extern const char *zfs_prop_to_name(zfs_prop_t);
3605094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
3615094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
3625094Slling     zprop_source_t *, char *, size_t, boolean_t);
3635094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
3645094Slling     zprop_source_t *, char *, size_t);
3655094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
3665094Slling extern int zfs_prop_inherit(zfs_handle_t *, const char *);
3675094Slling extern const char *zfs_prop_values(zfs_prop_t);
3685094Slling extern int zfs_prop_is_string(zfs_prop_t prop);
3695094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
3705094Slling 
3715094Slling typedef struct zprop_list {
3725094Slling 	int		pl_prop;
3732676Seschrock 	char		*pl_user_prop;
3745094Slling 	struct zprop_list *pl_next;
3752676Seschrock 	boolean_t	pl_all;
3762676Seschrock 	size_t		pl_width;
3772676Seschrock 	boolean_t	pl_fixed;
3785094Slling } zprop_list_t;
3793912Slling 
3805094Slling extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **);
381789Sahrens 
382789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
383789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
384789Sahrens 
385789Sahrens /*
3865094Slling  * zpool property management
3875094Slling  */
3885094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
3895094Slling extern const char *zpool_prop_default_string(zpool_prop_t);
3905094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
3915094Slling extern const char *zpool_prop_column_name(zpool_prop_t);
3925094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
3935094Slling 
3945094Slling /*
3955094Slling  * Functions shared by zfs and zpool property management.
3963912Slling  */
3975094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
3985094Slling     boolean_t ordered, zfs_type_t type);
3995094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
4005094Slling     zfs_type_t);
4015094Slling extern void zprop_free_list(zprop_list_t *);
4025094Slling 
4035094Slling /*
4045094Slling  * Functions for printing zfs or zpool properties
4055094Slling  */
4065094Slling typedef struct zprop_get_cbdata {
4073912Slling 	int cb_sources;
4083912Slling 	int cb_columns[4];
4093912Slling 	int cb_colwidths[5];
4103912Slling 	boolean_t cb_scripted;
4113912Slling 	boolean_t cb_literal;
4123912Slling 	boolean_t cb_first;
4135094Slling 	zprop_list_t *cb_proplist;
4145094Slling 	zfs_type_t cb_type;
4155094Slling } zprop_get_cbdata_t;
4163912Slling 
4175094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
4185094Slling     const char *, const char *, zprop_source_t, const char *);
4193912Slling 
4203912Slling #define	GET_COL_NAME		1
4213912Slling #define	GET_COL_PROPERTY	2
4223912Slling #define	GET_COL_VALUE		3
4233912Slling #define	GET_COL_SOURCE		4
4243912Slling 
4253912Slling /*
426789Sahrens  * Iterator functions.
427789Sahrens  */
428789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
4292082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
430789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
4312474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
4321356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
4331356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
434789Sahrens 
435789Sahrens /*
436789Sahrens  * Functions to create and destroy datasets.
437789Sahrens  */
4382082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
4392676Seschrock     nvlist_t *);
4404490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
441789Sahrens extern int zfs_destroy(zfs_handle_t *);
4422199Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *);
4432676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
4447265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
4455749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
4464490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
4475367Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
4485367Sahrens     boolean_t, boolean_t, boolean_t, boolean_t, int);
4492082Seschrock extern int zfs_promote(zfs_handle_t *);
450789Sahrens 
4515367Sahrens typedef struct recvflags {
4525446Sahrens 	/* print informational messages (ie, -v was specified) */
4535501Seschrock 	int verbose : 1;
4545446Sahrens 
4555446Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
4565501Seschrock 	int isprefix : 1;
4575446Sahrens 
4585446Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
4595501Seschrock 	int dryrun : 1;
4605446Sahrens 
4615446Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
4625501Seschrock 	int force : 1;
4635446Sahrens 
4645446Sahrens 	/* set "canmount=off" on all modified filesystems */
4655501Seschrock 	int canmountoff : 1;
4665446Sahrens 
4675446Sahrens 	/* byteswap flag is used internally; callers need not specify */
4685501Seschrock 	int byteswap : 1;
4695367Sahrens } recvflags_t;
4705367Sahrens 
4715367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t,
4725367Sahrens     int, avl_tree_t *);
4735367Sahrens 
474789Sahrens /*
475789Sahrens  * Miscellaneous functions.
476789Sahrens  */
477789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
478789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
479789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
4803635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
4814490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
4824490Svb160487     zfs_type_t);
4835713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *);
484789Sahrens 
485789Sahrens /*
4864543Smarks  * dataset permission functions.
4874543Smarks  */
4884543Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *);
4894543Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *);
4904543Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *,
4914543Smarks     zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t);
4924543Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **);
4934543Smarks extern void zfs_free_allows(zfs_allow_t *);
4945993Smarks extern void zfs_deleg_permissions(void);
4954543Smarks 
4964543Smarks /*
497789Sahrens  * Mount support functions.
498789Sahrens  */
4993444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
5002082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
501789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
502789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
503789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
504789Sahrens 
505789Sahrens /*
506789Sahrens  * Share support functions.
507789Sahrens  */
5083126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *);
509789Sahrens extern int zfs_share(zfs_handle_t *);
5103126Sahl extern int zfs_unshare(zfs_handle_t *);
5113126Sahl 
5123126Sahl /*
5134451Seschrock  * Protocol-specific share support functions.
5143126Sahl  */
5153126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
5165331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
5173126Sahl extern int zfs_share_nfs(zfs_handle_t *);
5185331Samw extern int zfs_share_smb(zfs_handle_t *);
5195331Samw extern int zfs_shareall(zfs_handle_t *);
5203126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
5215331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
5223126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *);
5235331Samw extern int zfs_unshareall_smb(zfs_handle_t *);
5245331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
5255331Samw extern int zfs_unshareall(zfs_handle_t *);
5263126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
5273126Sahl extern int zfs_share_iscsi(zfs_handle_t *);
5283126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *);
5294543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
5304543Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *,
5315331Samw     void *, void *, int, zfs_share_op_t);
532789Sahrens 
533789Sahrens /*
534789Sahrens  * When dealing with nvlists, verify() is extremely useful
535789Sahrens  */
536789Sahrens #ifdef NDEBUG
537789Sahrens #define	verify(EX)	((void)(EX))
538789Sahrens #else
539789Sahrens #define	verify(EX)	assert(EX)
540789Sahrens #endif
541789Sahrens 
542789Sahrens /*
543789Sahrens  * Utility function to convert a number to a human-readable form.
544789Sahrens  */
545789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
5462676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
547789Sahrens 
548789Sahrens /*
549789Sahrens  * Given a device or file, determine if it is part of a pool.
550789Sahrens  */
5512082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
5522082Seschrock     boolean_t *);
553789Sahrens 
554789Sahrens /*
555789Sahrens  * ftyp special.  Read the label from a given device.
556789Sahrens  */
5572082Seschrock extern int zpool_read_label(int, nvlist_t **);
558789Sahrens 
559789Sahrens /*
5603126Sahl  * Create and remove zvol /dev links.
561789Sahrens  */
562789Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
563789Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
564789Sahrens 
5656423Sgw25295 /* is this zvol valid for use as a dump device? */
5666423Sgw25295 extern int zvol_check_dump_config(char *);
5676423Sgw25295 
5682474Seschrock /*
5693126Sahl  * Enable and disable datasets within a pool by mounting/unmounting and
5703126Sahl  * sharing/unsharing them.
5712474Seschrock  */
5723126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
5733126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
5742474Seschrock 
575789Sahrens #ifdef	__cplusplus
576789Sahrens }
577789Sahrens #endif
578789Sahrens 
579789Sahrens #endif	/* _LIBZFS_H */
580