]> git.proxmox.com Git - mirror_zfs.git/blame - include/libzfs.h
Illumos #3745, #3811
[mirror_zfs.git] / include / libzfs.h
CommitLineData
34dc7c2f
BB
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
428870ff 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3541dc6d 24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
1bd201e7 25 * Copyright (c) 2012 by Delphix. All rights reserved.
37abac6d 26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
34dc7c2f
BB
27 */
28
29#ifndef _LIBZFS_H
30#define _LIBZFS_H
31
34dc7c2f
BB
32#include <assert.h>
33#include <libnvpair.h>
fb5f0bc8 34#include <sys/mnttab.h>
34dc7c2f
BB
35#include <sys/param.h>
36#include <sys/types.h>
37#include <sys/varargs.h>
38#include <sys/fs/zfs.h>
39#include <sys/avl.h>
40#include <ucred.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/*
47 * Miscellaneous ZFS constants
48 */
49#define ZFS_MAXNAMELEN MAXNAMELEN
50#define ZPOOL_MAXNAMELEN MAXNAMELEN
51#define ZFS_MAXPROPLEN MAXPATHLEN
52#define ZPOOL_MAXPROPLEN MAXPATHLEN
53
d603ed6c
BB
54/*
55 * Default device paths
56 */
eac47204
BB
57#define DISK_ROOT "/dev"
58#define UDISK_ROOT "/dev/disk"
d603ed6c 59
11cb9d77
BB
60/*
61 * Default wait time for a device name to be created.
62 */
63#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
64
dbf763b3 65#define DEFAULT_IMPORT_PATH_SIZE 7
eac47204 66extern char *zpool_default_import_path[DEFAULT_IMPORT_PATH_SIZE];
d603ed6c 67
34dc7c2f
BB
68/*
69 * libzfs errors
70 */
6f1ffb06
MA
71typedef enum zfs_error {
72 EZFS_SUCCESS = 0, /* no error -- success */
34dc7c2f
BB
73 EZFS_NOMEM = 2000, /* out of memory */
74 EZFS_BADPROP, /* invalid property value */
75 EZFS_PROPREADONLY, /* cannot set readonly property */
76 EZFS_PROPTYPE, /* property does not apply to dataset type */
77 EZFS_PROPNONINHERIT, /* property is not inheritable */
78 EZFS_PROPSPACE, /* bad quota or reservation */
79 EZFS_BADTYPE, /* dataset is not of appropriate type */
80 EZFS_BUSY, /* pool or dataset is busy */
81 EZFS_EXISTS, /* pool or dataset already exists */
82 EZFS_NOENT, /* no such pool or dataset */
83 EZFS_BADSTREAM, /* bad backup stream */
84 EZFS_DSREADONLY, /* dataset is readonly */
85 EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */
34dc7c2f
BB
86 EZFS_INVALIDNAME, /* invalid dataset name */
87 EZFS_BADRESTORE, /* unable to restore to destination */
88 EZFS_BADBACKUP, /* backup failed */
89 EZFS_BADTARGET, /* bad attach/detach/replace target */
90 EZFS_NODEVICE, /* no such device in pool */
91 EZFS_BADDEV, /* invalid device to add */
92 EZFS_NOREPLICAS, /* no valid replicas */
93 EZFS_RESILVERING, /* currently resilvering */
94 EZFS_BADVERSION, /* unsupported version */
95 EZFS_POOLUNAVAIL, /* pool is currently unavailable */
96 EZFS_DEVOVERFLOW, /* too many devices in one vdev */
97 EZFS_BADPATH, /* must be an absolute path */
98 EZFS_CROSSTARGET, /* rename or clone across pool or dataset */
99 EZFS_ZONED, /* used improperly in local zone */
100 EZFS_MOUNTFAILED, /* failed to mount dataset */
101 EZFS_UMOUNTFAILED, /* failed to unmount dataset */
102 EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */
103 EZFS_SHARENFSFAILED, /* share(1M) failed */
34dc7c2f
BB
104 EZFS_PERM, /* permission denied */
105 EZFS_NOSPC, /* out of space */
428870ff 106 EZFS_FAULT, /* bad address */
34dc7c2f
BB
107 EZFS_IO, /* I/O error */
108 EZFS_INTR, /* signal received */
109 EZFS_ISSPARE, /* device is a hot spare */
110 EZFS_INVALCONFIG, /* invalid vdev configuration */
111 EZFS_RECURSIVE, /* recursive dependency */
112 EZFS_NOHISTORY, /* no history object */
34dc7c2f
BB
113 EZFS_POOLPROPS, /* couldn't retrieve pool props */
114 EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */
115 EZFS_POOL_INVALARG, /* invalid argument for this pool operation */
116 EZFS_NAMETOOLONG, /* dataset name is too long */
117 EZFS_OPENFAILED, /* open of device failed */
118 EZFS_NOCAP, /* couldn't get capacity */
119 EZFS_LABELFAILED, /* write of label failed */
34dc7c2f
BB
120 EZFS_BADWHO, /* invalid permission who */
121 EZFS_BADPERM, /* invalid permission */
122 EZFS_BADPERMSET, /* invalid permission set name */
123 EZFS_NODELEGATION, /* delegated administration is disabled */
34dc7c2f
BB
124 EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */
125 EZFS_SHARESMBFAILED, /* failed to share over smb */
126 EZFS_BADCACHE, /* bad cache file */
127 EZFS_ISL2CACHE, /* device is for the level 2 ARC */
128 EZFS_VDEVNOTSUP, /* unsupported vdev type */
b128c09f
BB
129 EZFS_NOTSUP, /* ops not supported on this dataset */
130 EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */
9babb374 131 EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */
45d1cae3
BB
132 EZFS_REFTAG_RELE, /* snapshot release: tag not found */
133 EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */
428870ff
BB
134 EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */
135 EZFS_PIPEFAILED, /* pipe create failed */
136 EZFS_THREADCREATEFAILED, /* thread create failed */
137 EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */
138 EZFS_SCRUBBING, /* currently scrubbing */
139 EZFS_NO_SCRUB, /* no active scrub */
572e2857
BB
140 EZFS_DIFF, /* general failure of zfs diff */
141 EZFS_DIFFDATA, /* bad zfs diff data */
142 EZFS_POOLREADONLY, /* pool is in read-only mode */
34dc7c2f 143 EZFS_UNKNOWN
6f1ffb06 144} zfs_error_t;
34dc7c2f
BB
145
146/*
147 * The following data structures are all part
148 * of the zfs_allow_t data structure which is
149 * used for printing 'allow' permissions.
150 * It is a linked list of zfs_allow_t's which
151 * then contain avl tree's for user/group/sets/...
152 * and each one of the entries in those trees have
153 * avl tree's for the permissions they belong to and
154 * whether they are local,descendent or local+descendent
155 * permissions. The AVL trees are used primarily for
156 * sorting purposes, but also so that we can quickly find
157 * a given user and or permission.
158 */
159typedef struct zfs_perm_node {
160 avl_node_t z_node;
161 char z_pname[MAXPATHLEN];
162} zfs_perm_node_t;
163
164typedef struct zfs_allow_node {
165 avl_node_t z_node;
166 char z_key[MAXPATHLEN]; /* name, such as joe */
167 avl_tree_t z_localdescend; /* local+descendent perms */
168 avl_tree_t z_local; /* local permissions */
169 avl_tree_t z_descend; /* descendent permissions */
170} zfs_allow_node_t;
171
172typedef struct zfs_allow {
173 struct zfs_allow *z_next;
174 char z_setpoint[MAXPATHLEN];
175 avl_tree_t z_sets;
176 avl_tree_t z_crperms;
177 avl_tree_t z_user;
178 avl_tree_t z_group;
179 avl_tree_t z_everyone;
180} zfs_allow_t;
181
182/*
183 * Basic handle types
184 */
185typedef struct zfs_handle zfs_handle_t;
186typedef struct zpool_handle zpool_handle_t;
187typedef struct libzfs_handle libzfs_handle_t;
188
189/*
190 * Library initialization
191 */
192extern libzfs_handle_t *libzfs_init(void);
193extern void libzfs_fini(libzfs_handle_t *);
194
195extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
196extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
197
198extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
199
6f1ffb06
MA
200extern void zfs_save_arguments(int argc, char **, char *, int);
201extern int zpool_log_history(libzfs_handle_t *, const char *);
202
34dc7c2f
BB
203extern int libzfs_errno(libzfs_handle_t *);
204extern const char *libzfs_error_action(libzfs_handle_t *);
205extern const char *libzfs_error_description(libzfs_handle_t *);
fb5f0bc8
BB
206extern void libzfs_mnttab_init(libzfs_handle_t *);
207extern void libzfs_mnttab_fini(libzfs_handle_t *);
9babb374 208extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
fb5f0bc8
BB
209extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
210 struct mnttab *);
211extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
212 const char *, const char *);
213extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
34dc7c2f
BB
214
215/*
216 * Basic handle functions
217 */
218extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
219extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
220extern void zpool_close(zpool_handle_t *);
221extern const char *zpool_get_name(zpool_handle_t *);
222extern int zpool_get_state(zpool_handle_t *);
223extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
131cc95c 224extern const char *zpool_pool_state_to_name(pool_state_t);
b128c09f 225extern void zpool_free_handles(libzfs_handle_t *);
34dc7c2f
BB
226
227/*
228 * Iterate over all active pools in the system.
229 */
230typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
231extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
232
233/*
234 * Functions to create and destroy pools
235 */
236extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
b128c09f 237 nvlist_t *, nvlist_t *);
6f1ffb06 238extern int zpool_destroy(zpool_handle_t *, const char *);
34dc7c2f
BB
239extern int zpool_add(zpool_handle_t *, nvlist_t *);
240
428870ff
BB
241typedef struct splitflags {
242 /* do not split, but return the config that would be split off */
243 int dryrun : 1;
244
245 /* after splitting, import the pool */
246 int import : 1;
247} splitflags_t;
248
34dc7c2f
BB
249/*
250 * Functions to manipulate pool and vdev state
251 */
428870ff
BB
252extern int zpool_scan(zpool_handle_t *, pool_scan_func_t);
253extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
3541dc6d 254extern int zpool_reguid(zpool_handle_t *);
1bd201e7 255extern int zpool_reopen(zpool_handle_t *);
34dc7c2f
BB
256
257extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
258 vdev_state_t *);
259extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
260extern int zpool_vdev_attach(zpool_handle_t *, const char *,
261 const char *, nvlist_t *, int);
262extern int zpool_vdev_detach(zpool_handle_t *, const char *);
263extern int zpool_vdev_remove(zpool_handle_t *, const char *);
428870ff
BB
264extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
265 splitflags_t);
34dc7c2f 266
428870ff
BB
267extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
268extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
34dc7c2f
BB
269extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
270
271extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
b128c09f 272 boolean_t *, boolean_t *);
9babb374
BB
273extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
274 boolean_t *, boolean_t *, boolean_t *);
d603ed6c 275extern int zpool_label_disk_wait(char *, int);
34dc7c2f
BB
276extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
277
278/*
279 * Functions to manage pool properties
280 */
281extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
282extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
283 size_t proplen, zprop_source_t *);
8b921f66
RE
284extern int zpool_get_prop_literal(zpool_handle_t *, zpool_prop_t, char *,
285 size_t proplen, zprop_source_t *, boolean_t literal);
34dc7c2f
BB
286extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
287 zprop_source_t *);
288
289extern const char *zpool_prop_to_name(zpool_prop_t);
290extern const char *zpool_prop_values(zpool_prop_t);
291
292/*
293 * Pool health statistics.
294 */
295typedef enum {
296 /*
297 * The following correspond to faults as defined in the (fault.fs.zfs.*)
298 * event namespace. Each is associated with a corresponding message ID.
299 */
300 ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */
301 ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */
302 ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */
303 ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */
304 ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */
305 ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */
306 ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */
307 ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */
308 ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */
309 ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */
310 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */
b128c09f
BB
311 ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */
312 ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
d164b209
BB
313 ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */
314
9ae529ec
CS
315 /*
316 * If the pool has unsupported features but can still be opened in
317 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
318 * pool has unsupported features but cannot be opened at all, its
319 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
320 */
321 ZPOOL_STATUS_UNSUP_FEAT_READ, /* unsupported features for read */
322 ZPOOL_STATUS_UNSUP_FEAT_WRITE, /* unsupported features for write */
323
d164b209
BB
324 /*
325 * These faults have no corresponding message ID. At the time we are
326 * checking the status, the original reason for the FMA fault (I/O or
327 * checksum errors) has been lost.
328 */
34dc7c2f
BB
329 ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */
330 ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */
331
332 /*
333 * The following are not faults per se, but still an error possibly
334 * requiring administrative attention. There is no corresponding
335 * message ID.
336 */
b9b24bb4
CS
337 ZPOOL_STATUS_VERSION_OLDER, /* older legacy on-disk version */
338 ZPOOL_STATUS_FEAT_DISABLED, /* supported features are disabled */
34dc7c2f
BB
339 ZPOOL_STATUS_RESILVERING, /* device being resilvered */
340 ZPOOL_STATUS_OFFLINE_DEV, /* device online */
45d1cae3 341 ZPOOL_STATUS_REMOVED_DEV, /* removed device */
34dc7c2f
BB
342
343 /*
344 * Finally, the following indicates a healthy pool.
345 */
346 ZPOOL_STATUS_OK
347} zpool_status_t;
348
349extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
350extern zpool_status_t zpool_import_status(nvlist_t *, char **);
428870ff 351extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
34dc7c2f
BB
352
353/*
354 * Statistics and configuration functions.
355 */
356extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
9ae529ec 357extern nvlist_t *zpool_get_features(zpool_handle_t *);
34dc7c2f
BB
358extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
359extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
360
361/*
362 * Import and export functions
363 */
6f1ffb06
MA
364extern int zpool_export(zpool_handle_t *, boolean_t, const char *);
365extern int zpool_export_force(zpool_handle_t *, const char *);
34dc7c2f
BB
366extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
367 char *altroot);
368extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
572e2857 369 nvlist_t *, int);
9ae529ec 370extern void zpool_print_unsup_feat(nvlist_t *config);
34dc7c2f
BB
371
372/*
373 * Search for pools to import
374 */
428870ff
BB
375
376typedef struct importargs {
377 char **path; /* a list of paths to search */
378 int paths; /* number of paths to search */
379 char *poolname; /* name of a pool to find */
380 uint64_t guid; /* guid of a pool to find */
381 char *cachefile; /* cachefile to use for import */
382 int can_be_active : 1; /* can the pool be active? */
383 int unique : 1; /* does 'poolname' already exist? */
384 int exists : 1; /* set on return if pool already exists */
385} importargs_t;
386
387extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
388
389/* legacy pool search routines */
b128c09f 390extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
34dc7c2f 391extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
b128c09f 392 char *, uint64_t);
34dc7c2f
BB
393
394/*
395 * Miscellaneous pool functions
396 */
397struct zfs_cmd;
398
6f1ffb06 399extern const char *zfs_history_event_names[];
428870ff
BB
400
401extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
402 boolean_t verbose);
34dc7c2f
BB
403extern int zpool_upgrade(zpool_handle_t *, uint64_t);
404extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
428870ff
BB
405extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
406 nvlist_t ***, uint_t *);
26685276
BB
407extern int zpool_events_next(libzfs_handle_t *, nvlist_t **, int *, int, int);
408extern int zpool_events_clear(libzfs_handle_t *, int *);
34dc7c2f
BB
409extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
410 size_t len);
411extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
9babb374 412extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
428870ff
BB
413extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
414 nvlist_t *);
9babb374 415
34dc7c2f
BB
416/*
417 * Basic handle manipulations. These functions do not create or destroy the
418 * underlying datasets, only the references to them.
419 */
420extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
330d06f9 421extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
34dc7c2f
BB
422extern void zfs_close(zfs_handle_t *);
423extern zfs_type_t zfs_get_type(const zfs_handle_t *);
424extern const char *zfs_get_name(const zfs_handle_t *);
b128c09f 425extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
34dc7c2f
BB
426
427/*
428 * Property management functions. Some functions are shared with the kernel,
429 * and are found in sys/fs/zfs.h.
430 */
431
432/*
433 * zfs dataset property management
434 */
435extern const char *zfs_prop_default_string(zfs_prop_t);
436extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
437extern const char *zfs_prop_column_name(zfs_prop_t);
438extern boolean_t zfs_prop_align_right(zfs_prop_t);
439
b128c09f
BB
440extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
441 nvlist_t *, uint64_t, zfs_handle_t *, const char *);
442
34dc7c2f
BB
443extern const char *zfs_prop_to_name(zfs_prop_t);
444extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
445extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
446 zprop_source_t *, char *, size_t, boolean_t);
428870ff
BB
447extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
448 boolean_t);
34dc7c2f
BB
449extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
450 zprop_source_t *, char *, size_t);
9babb374
BB
451extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
452 uint64_t *propvalue);
453extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
454 char *propbuf, int proplen, boolean_t literal);
330d06f9
MA
455extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
456 uint64_t *propvalue);
457extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
458 char *propbuf, int proplen, boolean_t literal);
9ae529ec
CS
459extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
460 char *buf, size_t len);
2cf7f52b 461extern uint64_t getprop_uint64(zfs_handle_t *, zfs_prop_t, char **);
34dc7c2f 462extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
428870ff 463extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
34dc7c2f
BB
464extern const char *zfs_prop_values(zfs_prop_t);
465extern int zfs_prop_is_string(zfs_prop_t prop);
466extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
428870ff 467extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
330d06f9 468extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
34dc7c2f
BB
469
470typedef struct zprop_list {
471 int pl_prop;
472 char *pl_user_prop;
473 struct zprop_list *pl_next;
474 boolean_t pl_all;
475 size_t pl_width;
428870ff 476 size_t pl_recvd_width;
34dc7c2f
BB
477 boolean_t pl_fixed;
478} zprop_list_t;
479
428870ff 480extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t);
9babb374 481extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
34dc7c2f
BB
482
483#define ZFS_MOUNTPOINT_NONE "none"
484#define ZFS_MOUNTPOINT_LEGACY "legacy"
485
9ae529ec
CS
486#define ZFS_FEATURE_DISABLED "disabled"
487#define ZFS_FEATURE_ENABLED "enabled"
488#define ZFS_FEATURE_ACTIVE "active"
489
490#define ZFS_UNSUPPORTED_INACTIVE "inactive"
491#define ZFS_UNSUPPORTED_READONLY "readonly"
492
34dc7c2f
BB
493/*
494 * zpool property management
495 */
496extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
9ae529ec
CS
497extern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
498 size_t);
34dc7c2f
BB
499extern const char *zpool_prop_default_string(zpool_prop_t);
500extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
501extern const char *zpool_prop_column_name(zpool_prop_t);
502extern boolean_t zpool_prop_align_right(zpool_prop_t);
503
504/*
505 * Functions shared by zfs and zpool property management.
506 */
507extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
508 boolean_t ordered, zfs_type_t type);
509extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
510 zfs_type_t);
511extern void zprop_free_list(zprop_list_t *);
512
428870ff
BB
513#define ZFS_GET_NCOLS 5
514
515typedef enum {
516 GET_COL_NONE,
517 GET_COL_NAME,
518 GET_COL_PROPERTY,
519 GET_COL_VALUE,
520 GET_COL_RECVD,
521 GET_COL_SOURCE
522} zfs_get_column_t;
523
34dc7c2f
BB
524/*
525 * Functions for printing zfs or zpool properties
526 */
527typedef struct zprop_get_cbdata {
528 int cb_sources;
428870ff
BB
529 zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
530 int cb_colwidths[ZFS_GET_NCOLS + 1];
34dc7c2f
BB
531 boolean_t cb_scripted;
532 boolean_t cb_literal;
533 boolean_t cb_first;
534 zprop_list_t *cb_proplist;
535 zfs_type_t cb_type;
536} zprop_get_cbdata_t;
537
538void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
428870ff
BB
539 const char *, const char *, zprop_source_t, const char *,
540 const char *);
34dc7c2f
BB
541
542/*
543 * Iterator functions.
544 */
545typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
546extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
547extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
548extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
549extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
0cee2406 550extern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
428870ff 551extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
330d06f9 552extern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *);
34dc7c2f 553
572e2857
BB
554typedef struct get_all_cb {
555 zfs_handle_t **cb_handles;
556 size_t cb_alloc;
557 size_t cb_used;
558 boolean_t cb_verbose;
559 int (*cb_getone)(zfs_handle_t *, void *);
560} get_all_cb_t;
561
562void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
563int libzfs_dataset_cmp(const void *, const void *);
564
34dc7c2f
BB
565/*
566 * Functions to create and destroy datasets.
567 */
568extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
569 nvlist_t *);
570extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
45d1cae3
BB
571extern int zfs_destroy(zfs_handle_t *, boolean_t);
572extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
13fe0198 573extern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);
34dc7c2f 574extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
b128c09f 575extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
6f1ffb06
MA
576extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
577 nvlist_t *props);
34dc7c2f 578extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
db49968e 579extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
428870ff
BB
580
581typedef struct sendflags {
582 /* print informational messages (ie, -v was specified) */
330d06f9 583 boolean_t verbose;
428870ff
BB
584
585 /* recursive send (ie, -R) */
330d06f9 586 boolean_t replicate;
428870ff
BB
587
588 /* for incrementals, do all intermediate snapshots */
330d06f9 589 boolean_t doall;
428870ff
BB
590
591 /* if dataset is a clone, do incremental from its origin */
330d06f9 592 boolean_t fromorigin;
428870ff
BB
593
594 /* do deduplication */
330d06f9 595 boolean_t dedup;
428870ff
BB
596
597 /* send properties (ie, -p) */
330d06f9
MA
598 boolean_t props;
599
600 /* do not send (no-op, ie. -n) */
601 boolean_t dryrun;
602
603 /* parsable verbose output (ie. -P) */
604 boolean_t parsable;
37abac6d
BP
605
606 /* show progress (ie. -v) */
607 boolean_t progress;
428870ff
BB
608} sendflags_t;
609
610typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
611
330d06f9
MA
612extern int zfs_send(zfs_handle_t *, const char *, const char *,
613 sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **);
428870ff 614
34dc7c2f 615extern int zfs_promote(zfs_handle_t *);
13fe0198
MA
616extern int zfs_hold(zfs_handle_t *, const char *, const char *,
617 boolean_t, boolean_t, int);
45d1cae3 618extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t);
0b7936d5 619extern int zfs_get_holds(zfs_handle_t *, nvlist_t **);
428870ff 620extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *);
34dc7c2f 621
9babb374
BB
622typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain,
623 uid_t rid, uint64_t space);
624
0b7936d5
AS
625extern int zfs_userspace(zfs_handle_t *, zfs_userquota_prop_t,
626 zfs_userspace_cb_t, void *);
627
628extern int zfs_get_fsacl(zfs_handle_t *, nvlist_t **);
629extern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *);
9babb374 630
34dc7c2f
BB
631typedef struct recvflags {
632 /* print informational messages (ie, -v was specified) */
330d06f9 633 boolean_t verbose;
34dc7c2f
BB
634
635 /* the destination is a prefix, not the exact fs (ie, -d) */
330d06f9 636 boolean_t isprefix;
34dc7c2f 637
428870ff
BB
638 /*
639 * Only the tail of the sent snapshot path is appended to the
640 * destination to determine the received snapshot name (ie, -e).
641 */
330d06f9 642 boolean_t istail;
428870ff 643
34dc7c2f 644 /* do not actually do the recv, just check if it would work (ie, -n) */
330d06f9 645 boolean_t dryrun;
34dc7c2f
BB
646
647 /* rollback/destroy filesystems as necessary (eg, -F) */
330d06f9 648 boolean_t force;
34dc7c2f
BB
649
650 /* set "canmount=off" on all modified filesystems */
330d06f9 651 boolean_t canmountoff;
34dc7c2f
BB
652
653 /* byteswap flag is used internally; callers need not specify */
330d06f9 654 boolean_t byteswap;
d164b209
BB
655
656 /* do not mount file systems as they are extracted (private) */
330d06f9 657 boolean_t nomount;
34dc7c2f
BB
658} recvflags_t;
659
330d06f9 660extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t *,
34dc7c2f
BB
661 int, avl_tree_t *);
662
572e2857
BB
663typedef enum diff_flags {
664 ZFS_DIFF_PARSEABLE = 0x1,
665 ZFS_DIFF_TIMESTAMP = 0x2,
666 ZFS_DIFF_CLASSIFY = 0x4
667} diff_flags_t;
668
669extern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *,
670 int);
671
34dc7c2f
BB
672/*
673 * Miscellaneous functions.
674 */
675extern const char *zfs_type_to_name(zfs_type_t);
676extern void zfs_refresh_properties(zfs_handle_t *);
677extern int zfs_name_valid(const char *, zfs_type_t);
678extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
679extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
680 zfs_type_t);
681extern int zfs_spa_version(zfs_handle_t *, int *);
eac47204 682extern int zfs_append_partition(char *path, size_t max_len);
79e7242a 683extern int zfs_resolve_shortname(const char *name, char *path, size_t pathlen);
eac47204 684extern int zfs_strcmp_pathname(char *name, char *cmp_name, int wholedisk);
34dc7c2f 685
34dc7c2f
BB
686/*
687 * Mount support functions.
688 */
689extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
690extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
691extern int zfs_mount(zfs_handle_t *, const char *, int);
692extern int zfs_unmount(zfs_handle_t *, const char *, int);
693extern int zfs_unmountall(zfs_handle_t *, int);
694
695/*
696 * Share support functions.
697 */
698extern boolean_t zfs_is_shared(zfs_handle_t *);
699extern int zfs_share(zfs_handle_t *);
700extern int zfs_unshare(zfs_handle_t *);
701
702/*
703 * Protocol-specific share support functions.
704 */
705extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
706extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
707extern int zfs_share_nfs(zfs_handle_t *);
708extern int zfs_share_smb(zfs_handle_t *);
709extern int zfs_shareall(zfs_handle_t *);
710extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
711extern int zfs_unshare_smb(zfs_handle_t *, const char *);
712extern int zfs_unshareall_nfs(zfs_handle_t *);
713extern int zfs_unshareall_smb(zfs_handle_t *);
714extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
715extern int zfs_unshareall(zfs_handle_t *);
9babb374 716extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
34dc7c2f
BB
717 void *, void *, int, zfs_share_op_t);
718
34dc7c2f
BB
719/*
720 * Utility function to convert a number to a human-readable form.
721 */
722extern void zfs_nicenum(uint64_t, char *, size_t);
723extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
724
feb46b92
BB
725/*
726 * Utility functions to run an external process.
727 */
9ac97c2a
BB
728#define STDOUT_VERBOSE 0x01
729#define STDERR_VERBOSE 0x02
730
731int libzfs_run_process(const char *, char **, int flags);
feb46b92
BB
732int libzfs_load_module(const char *);
733
34dc7c2f
BB
734/*
735 * Given a device or file, determine if it is part of a pool.
736 */
737extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
738 boolean_t *);
739
740/*
428870ff 741 * Label manipulation.
34dc7c2f
BB
742 */
743extern int zpool_read_label(int, nvlist_t **);
428870ff 744extern int zpool_clear_label(int);
34dc7c2f 745
9babb374
BB
746/*
747 * Management interfaces for SMB ACL files
748 */
749
750int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *);
751int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *);
752int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *);
753int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
754
34dc7c2f
BB
755/*
756 * Enable and disable datasets within a pool by mounting/unmounting and
757 * sharing/unsharing them.
758 */
759extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
760extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
761
428870ff
BB
762/*
763 * Mappings between vdev and FRU.
764 */
765extern void libzfs_fru_refresh(libzfs_handle_t *);
766extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *);
767extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *);
768extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *,
769 const char *);
770extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *);
771extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *);
772
34dc7c2f
BB
773#ifdef __cplusplus
774}
775#endif
776
777#endif /* _LIBZFS_H */