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