xref: /illumos-gate/usr/src/lib/libzfs/common/libzfs.h (revision ecd6cf800b63704be73fb264c3f5b6e0dafc068d)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5441d80aaSlling  * Common Development and Distribution License (the "License").
6441d80aaSlling  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21f3861e1aSahl 
22fa9e4066Sahrens /*
2355434c77Sek  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24fa9e4066Sahrens  * Use is subject to license terms.
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
27fa9e4066Sahrens #ifndef	_LIBZFS_H
28fa9e4066Sahrens #define	_LIBZFS_H
29fa9e4066Sahrens 
30fa9e4066Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
31fa9e4066Sahrens 
32fa9e4066Sahrens #include <assert.h>
33fa9e4066Sahrens #include <libnvpair.h>
34fa9e4066Sahrens #include <sys/param.h>
35fa9e4066Sahrens #include <sys/types.h>
36fa9e4066Sahrens #include <sys/varargs.h>
37fa9e4066Sahrens #include <sys/fs/zfs.h>
38*ecd6cf80Smarks #include <sys/avl.h>
39*ecd6cf80Smarks #include <libuutil.h>
40*ecd6cf80Smarks #include <ucred.h>
41fa9e4066Sahrens 
42fa9e4066Sahrens #ifdef	__cplusplus
43fa9e4066Sahrens extern "C" {
44fa9e4066Sahrens #endif
45fa9e4066Sahrens 
46fa9e4066Sahrens /*
47fa9e4066Sahrens  * Miscellaneous ZFS constants
48fa9e4066Sahrens  */
49fa9e4066Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
50fa9e4066Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
51fa9e4066Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
52fa9e4066Sahrens 
5399653d4eSeschrock /*
5499653d4eSeschrock  * libzfs errors
5599653d4eSeschrock  */
5699653d4eSeschrock enum {
5799653d4eSeschrock 	EZFS_NOMEM = 2000,	/* out of memory */
5899653d4eSeschrock 	EZFS_BADPROP,		/* invalid property value */
5999653d4eSeschrock 	EZFS_PROPREADONLY,	/* cannot set readonly property */
6099653d4eSeschrock 	EZFS_PROPTYPE,		/* property does not apply to dataset type */
6199653d4eSeschrock 	EZFS_PROPNONINHERIT,	/* property is not inheritable */
6299653d4eSeschrock 	EZFS_PROPSPACE,		/* bad quota or reservation */
6399653d4eSeschrock 	EZFS_BADTYPE,		/* dataset is not of appropriate type */
6499653d4eSeschrock 	EZFS_BUSY,		/* pool or dataset is busy */
6599653d4eSeschrock 	EZFS_EXISTS,		/* pool or dataset already exists */
6699653d4eSeschrock 	EZFS_NOENT,		/* no such pool or dataset */
6799653d4eSeschrock 	EZFS_BADSTREAM,		/* bad backup stream */
6899653d4eSeschrock 	EZFS_DSREADONLY,	/* dataset is readonly */
6999653d4eSeschrock 	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
7099653d4eSeschrock 	EZFS_VOLHASDATA,	/* volume already contains data */
7199653d4eSeschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
7299653d4eSeschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
7399653d4eSeschrock 	EZFS_BADBACKUP,		/* backup failed */
7499653d4eSeschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
7599653d4eSeschrock 	EZFS_NODEVICE,		/* no such device in pool */
7699653d4eSeschrock 	EZFS_BADDEV,		/* invalid device to add */
7799653d4eSeschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
7899653d4eSeschrock 	EZFS_RESILVERING,	/* currently resilvering */
7999653d4eSeschrock 	EZFS_BADVERSION,	/* unsupported version */
8099653d4eSeschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
8199653d4eSeschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
8299653d4eSeschrock 	EZFS_BADPATH,		/* must be an absolute path */
8399653d4eSeschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
8499653d4eSeschrock 	EZFS_ZONED,		/* used improperly in local zone */
8599653d4eSeschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
8699653d4eSeschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
87f3861e1aSahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
88f3861e1aSahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
8999653d4eSeschrock 	EZFS_DEVLINKS,		/* failed to create zvol links */
9099653d4eSeschrock 	EZFS_PERM,		/* permission denied */
9199653d4eSeschrock 	EZFS_NOSPC,		/* out of space */
9299653d4eSeschrock 	EZFS_IO,		/* I/O error */
9399653d4eSeschrock 	EZFS_INTR,		/* signal received */
9499653d4eSeschrock 	EZFS_ISSPARE,		/* device is a hot spare */
9599653d4eSeschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
963bb79becSeschrock 	EZFS_RECURSIVE,		/* recursive dependency */
9706eeb2adSek 	EZFS_NOHISTORY,		/* no history object */
98f3861e1aSahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
99f3861e1aSahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
100b1b8ab34Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
101b1b8ab34Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
102b1b8ab34Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
103b7661cccSmmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1048488aeb5Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1058488aeb5Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1068488aeb5Staylor 	EZFS_LABELFAILED,	/* write of label failed */
107*ecd6cf80Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
108*ecd6cf80Smarks 	EZFS_BADWHO,		/* invalid permission who */
109*ecd6cf80Smarks 	EZFS_BADPERM,		/* invalid permission */
110*ecd6cf80Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
111*ecd6cf80Smarks 	EZFS_PERMSET_CIRCULAR,	/* circular dependency on permset */
112*ecd6cf80Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
113*ecd6cf80Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
114b1b8ab34Slling 	EZFS_UNKNOWN
11599653d4eSeschrock };
11699653d4eSeschrock 
117*ecd6cf80Smarks /*
118*ecd6cf80Smarks  * The following data structures are all part
119*ecd6cf80Smarks  * of the zfs_allow_t data structure which is
120*ecd6cf80Smarks  * used for printing 'allow' permissions.
121*ecd6cf80Smarks  * It is a linked list of zfs_allow_t's which
122*ecd6cf80Smarks  * then contain avl tree's for user/group/sets/...
123*ecd6cf80Smarks  * and each one of the entries in those trees have
124*ecd6cf80Smarks  * avl tree's for the permissions they belong to and
125*ecd6cf80Smarks  * whether they are local,descendent or local+descendent
126*ecd6cf80Smarks  * permissions.  The AVL trees are used primarily for
127*ecd6cf80Smarks  * sorting purposes, but also so that we can quickly find
128*ecd6cf80Smarks  * a given user and or permission.
129*ecd6cf80Smarks  */
130*ecd6cf80Smarks typedef struct zfs_perm_node {
131*ecd6cf80Smarks 	avl_node_t z_node;
132*ecd6cf80Smarks 	char z_pname[MAXPATHLEN];
133*ecd6cf80Smarks } zfs_perm_node_t;
134*ecd6cf80Smarks 
135*ecd6cf80Smarks typedef struct zfs_allow_node {
136*ecd6cf80Smarks 	avl_node_t z_node;
137*ecd6cf80Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
138*ecd6cf80Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
139*ecd6cf80Smarks 	avl_tree_t z_local;		/* local permissions */
140*ecd6cf80Smarks 	avl_tree_t z_descend;		/* descendent permissions */
141*ecd6cf80Smarks } zfs_allow_node_t;
142*ecd6cf80Smarks 
143*ecd6cf80Smarks typedef struct zfs_allow {
144*ecd6cf80Smarks 	struct zfs_allow *z_next;
145*ecd6cf80Smarks 	char z_setpoint[MAXPATHLEN];
146*ecd6cf80Smarks 	avl_tree_t z_sets;
147*ecd6cf80Smarks 	avl_tree_t z_crperms;
148*ecd6cf80Smarks 	avl_tree_t z_user;
149*ecd6cf80Smarks 	avl_tree_t z_group;
150*ecd6cf80Smarks 	avl_tree_t z_everyone;
151*ecd6cf80Smarks } zfs_allow_t;
152*ecd6cf80Smarks 
153fa9e4066Sahrens /*
154fa9e4066Sahrens  * Basic handle types
155fa9e4066Sahrens  */
156fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t;
157fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t;
15899653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t;
15999653d4eSeschrock 
16099653d4eSeschrock /*
16199653d4eSeschrock  * Library initialization
16299653d4eSeschrock  */
16399653d4eSeschrock extern libzfs_handle_t *libzfs_init(void);
16499653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *);
16599653d4eSeschrock 
16699653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
16799653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
16899653d4eSeschrock 
16999653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
17099653d4eSeschrock 
17199653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *);
17299653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *);
17399653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *);
174fa9e4066Sahrens 
175fa9e4066Sahrens /*
176fa9e4066Sahrens  * Basic handle functions
177fa9e4066Sahrens  */
17899653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
17999653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
180fa9e4066Sahrens extern void zpool_close(zpool_handle_t *);
181fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *);
182fa9e4066Sahrens extern uint64_t zpool_get_guid(zpool_handle_t *);
183fa9e4066Sahrens extern uint64_t zpool_get_space_used(zpool_handle_t *);
184fa9e4066Sahrens extern uint64_t zpool_get_space_total(zpool_handle_t *);
185fa9e4066Sahrens extern int zpool_get_root(zpool_handle_t *, char *, size_t);
186fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *);
18799653d4eSeschrock extern uint64_t zpool_get_version(zpool_handle_t *);
188fa9e4066Sahrens 
189fa9e4066Sahrens /*
190fa9e4066Sahrens  * Iterate over all active pools in the system.
191fa9e4066Sahrens  */
192fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
19399653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
194fa9e4066Sahrens 
195fa9e4066Sahrens /*
196fa9e4066Sahrens  * Functions to create and destroy pools
197fa9e4066Sahrens  */
19899653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
19999653d4eSeschrock     const char *);
200fa9e4066Sahrens extern int zpool_destroy(zpool_handle_t *);
201fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
202fa9e4066Sahrens 
203fa9e4066Sahrens /*
204fa9e4066Sahrens  * Functions to manipulate pool and vdev state
205fa9e4066Sahrens  */
206fa9e4066Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
2073d7072f8Seschrock extern int zpool_clear(zpool_handle_t *, const char *);
208fa9e4066Sahrens 
2093d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2103d7072f8Seschrock     vdev_state_t *);
2113d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2123d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2133d7072f8Seschrock     const char *, nvlist_t *, int);
214fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
21599653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2163d7072f8Seschrock 
2173d7072f8Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t);
2183d7072f8Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t);
2193d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2203d7072f8Seschrock 
22199653d4eSeschrock extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *);
2228488aeb5Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
223fa9e4066Sahrens 
224b1b8ab34Slling /*
225b1b8ab34Slling  * Functions to manage pool properties
226b1b8ab34Slling  */
227b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2283d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
229b1b8ab34Slling 	size_t proplen, zfs_source_t *);
2303d7072f8Seschrock extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t);
231b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t);
232b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t);
233b1b8ab34Slling 
234fa9e4066Sahrens /*
235fa9e4066Sahrens  * Pool health statistics.
236fa9e4066Sahrens  */
237fa9e4066Sahrens typedef enum {
238fa9e4066Sahrens 	/*
239fa9e4066Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
240b81d61a6Slling 	 * event namespace.  Each is associated with a corresponding message ID.
241fa9e4066Sahrens 	 */
242fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
243fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
244fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
245fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
246b81d61a6Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
247fa9e4066Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
248fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
249fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
250fa9e4066Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
251eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
25295173954Sek 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2533d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2543d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
255fa9e4066Sahrens 
256fa9e4066Sahrens 	/*
257fa9e4066Sahrens 	 * The following are not faults per se, but still an error possibly
258b81d61a6Slling 	 * requiring administrative attention.  There is no corresponding
259fa9e4066Sahrens 	 * message ID.
260fa9e4066Sahrens 	 */
261eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
262fa9e4066Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
263fa9e4066Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
264fa9e4066Sahrens 
265fa9e4066Sahrens 	/*
266fa9e4066Sahrens 	 * Finally, the following indicates a healthy pool.
267fa9e4066Sahrens 	 */
268fa9e4066Sahrens 	ZPOOL_STATUS_OK
269fa9e4066Sahrens } zpool_status_t;
270fa9e4066Sahrens 
271ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
272ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
273fa9e4066Sahrens 
274fa9e4066Sahrens /*
275fa9e4066Sahrens  * Statistics and configuration functions.
276fa9e4066Sahrens  */
277ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
27894de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
27955434c77Sek extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
280ea8dc4b6Seschrock 
281fa9e4066Sahrens /*
282fa9e4066Sahrens  * Import and export functions
283fa9e4066Sahrens  */
284fa9e4066Sahrens extern int zpool_export(zpool_handle_t *);
28599653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
28699653d4eSeschrock     const char *);
287fa9e4066Sahrens 
288fa9e4066Sahrens /*
289fa9e4066Sahrens  * Search for pools to import
290fa9e4066Sahrens  */
29199653d4eSeschrock extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
292fa9e4066Sahrens 
293c67d9675Seschrock /*
294c67d9675Seschrock  * Miscellaneous pool functions
295c67d9675Seschrock  */
296*ecd6cf80Smarks struct zfs_cmd;
297*ecd6cf80Smarks 
29899653d4eSeschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *);
299eaca9bbdSeschrock extern int zpool_upgrade(zpool_handle_t *);
30006eeb2adSek extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
301*ecd6cf80Smarks extern void zpool_stage_history(libzfs_handle_t *, int, char **,
302*ecd6cf80Smarks     boolean_t zfs_cmd, boolean_t pool_create);
30355434c77Sek extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
30455434c77Sek     size_t len);
305*ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
306fa9e4066Sahrens /*
307fa9e4066Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
308fa9e4066Sahrens  * underlying datasets, only the references to them.
309fa9e4066Sahrens  */
31099653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
311fa9e4066Sahrens extern void zfs_close(zfs_handle_t *);
312fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
313fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
314fa9e4066Sahrens 
315fa9e4066Sahrens /*
316fa9e4066Sahrens  * Property management functions.  Some functions are shared with the kernel,
317b81d61a6Slling  * and are found in sys/fs/zfs.h.
318fa9e4066Sahrens  */
319e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t);
320e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
321e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
322e9dbad6fSeschrock     zfs_source_t *, char *, size_t, boolean_t);
323e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
324e9dbad6fSeschrock     zfs_source_t *, char *, size_t);
325e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
326e9dbad6fSeschrock extern const char *zfs_prop_get_string(zfs_handle_t *, zfs_prop_t);
327e9dbad6fSeschrock extern int zfs_prop_inherit(zfs_handle_t *, const char *);
328e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t);
329e9dbad6fSeschrock extern int zfs_prop_valid_for_type(zfs_prop_t, int);
330e9dbad6fSeschrock extern const char *zfs_prop_default_string(zfs_prop_t prop);
331e9dbad6fSeschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
332e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop);
333e9dbad6fSeschrock extern const char *zfs_prop_column_name(zfs_prop_t);
334e9dbad6fSeschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
335b1b8ab34Slling extern void nicebool(int value, char *buf, size_t buflen);
336e9dbad6fSeschrock 
337e9dbad6fSeschrock typedef struct zfs_proplist {
338e9dbad6fSeschrock 	zfs_prop_t	pl_prop;
339e9dbad6fSeschrock 	char		*pl_user_prop;
340e9dbad6fSeschrock 	struct zfs_proplist *pl_next;
341e9dbad6fSeschrock 	boolean_t	pl_all;
342e9dbad6fSeschrock 	size_t		pl_width;
343e9dbad6fSeschrock 	boolean_t	pl_fixed;
344e9dbad6fSeschrock } zfs_proplist_t;
345e9dbad6fSeschrock 
346b1b8ab34Slling typedef zfs_proplist_t zpool_proplist_t;
347b1b8ab34Slling 
348e9dbad6fSeschrock extern int zfs_get_proplist(libzfs_handle_t *, char *, zfs_proplist_t **);
349b1b8ab34Slling extern int zpool_get_proplist(libzfs_handle_t *, char *, zpool_proplist_t **);
350e9dbad6fSeschrock extern int zfs_expand_proplist(zfs_handle_t *, zfs_proplist_t **);
351b1b8ab34Slling extern int zpool_expand_proplist(zpool_handle_t *, zpool_proplist_t **);
352b1b8ab34Slling extern void zfs_free_proplist(zfs_proplist_t *);
353e9dbad6fSeschrock extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
354fa9e4066Sahrens 
355fa9e4066Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
356fa9e4066Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
357fa9e4066Sahrens 
358b1b8ab34Slling /*
359b1b8ab34Slling  * Functions for printing properties from zfs/zpool
360b1b8ab34Slling  */
361b1b8ab34Slling typedef struct libzfs_get_cbdata {
362b1b8ab34Slling 	int cb_sources;
363b1b8ab34Slling 	int cb_columns[4];
364b1b8ab34Slling 	int cb_colwidths[5];
365b1b8ab34Slling 	boolean_t cb_scripted;
366b1b8ab34Slling 	boolean_t cb_literal;
367b1b8ab34Slling 	boolean_t cb_first;
368b1b8ab34Slling 	zfs_proplist_t *cb_proplist;
369b1b8ab34Slling } libzfs_get_cbdata_t;
370b1b8ab34Slling 
371b1b8ab34Slling void libzfs_print_one_property(const char *, libzfs_get_cbdata_t *,
372b1b8ab34Slling     const char *, const char *, zfs_source_t, const char *);
373b1b8ab34Slling 
374b1b8ab34Slling #define	GET_COL_NAME		1
375b1b8ab34Slling #define	GET_COL_PROPERTY	2
376b1b8ab34Slling #define	GET_COL_VALUE		3
377b1b8ab34Slling #define	GET_COL_SOURCE		4
378b1b8ab34Slling 
379fa9e4066Sahrens /*
380fa9e4066Sahrens  * Iterator functions.
381fa9e4066Sahrens  */
382fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
38399653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
384fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
3853bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
3867f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
3877f7322feSeschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
388fa9e4066Sahrens 
389fa9e4066Sahrens /*
390fa9e4066Sahrens  * Functions to create and destroy datasets.
391fa9e4066Sahrens  */
39299653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
393e9dbad6fSeschrock     nvlist_t *);
3947f1f55eaSvb extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
395fa9e4066Sahrens extern int zfs_destroy(zfs_handle_t *);
3961d452cf5Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *);
397e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
3981d452cf5Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t);
399b12a1c38Slling extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, int);
4007f1f55eaSvb extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
40172bdce51Sahl extern int zfs_send(zfs_handle_t *, const char *, int);
40298579b20Snd extern int zfs_receive(libzfs_handle_t *, const char *, int, int, int,
40372bdce51Sahl     boolean_t, int);
40499653d4eSeschrock extern int zfs_promote(zfs_handle_t *);
405fa9e4066Sahrens 
406fa9e4066Sahrens /*
407fa9e4066Sahrens  * Miscellaneous functions.
408fa9e4066Sahrens  */
409fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t);
410fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
411fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
412f3861e1aSahl extern int zfs_disable(zfs_handle_t *);
413f3861e1aSahl extern int zfs_enable(zfs_handle_t *);
4145aba80dbSck extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
4157f1f55eaSvb extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
4167f1f55eaSvb     zfs_type_t);
417fa9e4066Sahrens 
418*ecd6cf80Smarks /*
419*ecd6cf80Smarks  * dataset permission functions.
420*ecd6cf80Smarks  */
421*ecd6cf80Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *);
422*ecd6cf80Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *);
423*ecd6cf80Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *,
424*ecd6cf80Smarks     zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t);
425*ecd6cf80Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **);
426*ecd6cf80Smarks extern void zfs_free_allows(zfs_allow_t *);
427*ecd6cf80Smarks 
428fa9e4066Sahrens /*
429fa9e4066Sahrens  * Mount support functions.
430fa9e4066Sahrens  */
43155434c77Sek extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
43299653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
433fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
434fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
435fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
436fa9e4066Sahrens 
437fa9e4066Sahrens /*
438fa9e4066Sahrens  * Share support functions.
439fa9e4066Sahrens  */
440f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *);
441fa9e4066Sahrens extern int zfs_share(zfs_handle_t *);
442f3861e1aSahl extern int zfs_unshare(zfs_handle_t *);
443f3861e1aSahl 
444f3861e1aSahl /*
4453d7072f8Seschrock  * Protocol-specific share support functions.
446f3861e1aSahl  */
447f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
448f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *);
449f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
450f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *);
451f3861e1aSahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
452f3861e1aSahl extern int zfs_share_iscsi(zfs_handle_t *);
453f3861e1aSahl extern int zfs_unshare_iscsi(zfs_handle_t *);
454*ecd6cf80Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
455*ecd6cf80Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *,
456*ecd6cf80Smarks     void *, void *, int, boolean_t);
457fa9e4066Sahrens 
458fa9e4066Sahrens /*
459fa9e4066Sahrens  * When dealing with nvlists, verify() is extremely useful
460fa9e4066Sahrens  */
461fa9e4066Sahrens #ifdef NDEBUG
462fa9e4066Sahrens #define	verify(EX)	((void)(EX))
463fa9e4066Sahrens #else
464fa9e4066Sahrens #define	verify(EX)	assert(EX)
465fa9e4066Sahrens #endif
466fa9e4066Sahrens 
467fa9e4066Sahrens /*
468fa9e4066Sahrens  * Utility function to convert a number to a human-readable form.
469fa9e4066Sahrens  */
470fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
471e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
472fa9e4066Sahrens 
473fa9e4066Sahrens /*
474fa9e4066Sahrens  * Pool destroy special.  Remove the device information without destroying
475fa9e4066Sahrens  * the underlying dataset.
476fa9e4066Sahrens  */
477fa9e4066Sahrens extern int zfs_remove_link(zfs_handle_t *);
478fa9e4066Sahrens 
479fa9e4066Sahrens /*
480fa9e4066Sahrens  * Given a device or file, determine if it is part of a pool.
481fa9e4066Sahrens  */
48299653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
48399653d4eSeschrock     boolean_t *);
484fa9e4066Sahrens 
485fa9e4066Sahrens /*
486fa9e4066Sahrens  * ftyp special.  Read the label from a given device.
487fa9e4066Sahrens  */
48899653d4eSeschrock extern int zpool_read_label(int, nvlist_t **);
489fa9e4066Sahrens 
490fa9e4066Sahrens /*
491f3861e1aSahl  * Create and remove zvol /dev links.
492fa9e4066Sahrens  */
493fa9e4066Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
494fa9e4066Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
495fa9e4066Sahrens 
4963bb79becSeschrock /*
497f3861e1aSahl  * Enable and disable datasets within a pool by mounting/unmounting and
498f3861e1aSahl  * sharing/unsharing them.
4993bb79becSeschrock  */
500f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
501f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
5023bb79becSeschrock 
503fa9e4066Sahrens #ifdef	__cplusplus
504fa9e4066Sahrens }
505fa9e4066Sahrens #endif
506fa9e4066Sahrens 
507fa9e4066Sahrens #endif	/* _LIBZFS_H */
508