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 /* 2355434c77Sek110237 * 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> 38ecd6cf80Smarks #include <sys/avl.h> 39ecd6cf80Smarks #include <ucred.h> 40fa9e4066Sahrens 41fa9e4066Sahrens #ifdef __cplusplus 42fa9e4066Sahrens extern "C" { 43fa9e4066Sahrens #endif 44fa9e4066Sahrens 45fa9e4066Sahrens /* 46fa9e4066Sahrens * Miscellaneous ZFS constants 47fa9e4066Sahrens */ 48fa9e4066Sahrens #define ZFS_MAXNAMELEN MAXNAMELEN 49fa9e4066Sahrens #define ZPOOL_MAXNAMELEN MAXNAMELEN 50fa9e4066Sahrens #define ZFS_MAXPROPLEN MAXPATHLEN 51fa9e4066Sahrens 52fa9e4066Sahrens /* 5399653d4eSeschrock * libzfs errors 5499653d4eSeschrock */ 5599653d4eSeschrock enum { 5699653d4eSeschrock EZFS_NOMEM = 2000, /* out of memory */ 5799653d4eSeschrock EZFS_BADPROP, /* invalid property value */ 5899653d4eSeschrock EZFS_PROPREADONLY, /* cannot set readonly property */ 5999653d4eSeschrock EZFS_PROPTYPE, /* property does not apply to dataset type */ 6099653d4eSeschrock EZFS_PROPNONINHERIT, /* property is not inheritable */ 6199653d4eSeschrock EZFS_PROPSPACE, /* bad quota or reservation */ 6299653d4eSeschrock EZFS_BADTYPE, /* dataset is not of appropriate type */ 6399653d4eSeschrock EZFS_BUSY, /* pool or dataset is busy */ 6499653d4eSeschrock EZFS_EXISTS, /* pool or dataset already exists */ 6599653d4eSeschrock EZFS_NOENT, /* no such pool or dataset */ 6699653d4eSeschrock EZFS_BADSTREAM, /* bad backup stream */ 6799653d4eSeschrock EZFS_DSREADONLY, /* dataset is readonly */ 6899653d4eSeschrock EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 6999653d4eSeschrock EZFS_VOLHASDATA, /* volume already contains data */ 7099653d4eSeschrock EZFS_INVALIDNAME, /* invalid dataset name */ 7199653d4eSeschrock EZFS_BADRESTORE, /* unable to restore to destination */ 7299653d4eSeschrock EZFS_BADBACKUP, /* backup failed */ 7399653d4eSeschrock EZFS_BADTARGET, /* bad attach/detach/replace target */ 7499653d4eSeschrock EZFS_NODEVICE, /* no such device in pool */ 7599653d4eSeschrock EZFS_BADDEV, /* invalid device to add */ 7699653d4eSeschrock EZFS_NOREPLICAS, /* no valid replicas */ 7799653d4eSeschrock EZFS_RESILVERING, /* currently resilvering */ 7899653d4eSeschrock EZFS_BADVERSION, /* unsupported version */ 7999653d4eSeschrock EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 8099653d4eSeschrock EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 8199653d4eSeschrock EZFS_BADPATH, /* must be an absolute path */ 8299653d4eSeschrock EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 8399653d4eSeschrock EZFS_ZONED, /* used improperly in local zone */ 8499653d4eSeschrock EZFS_MOUNTFAILED, /* failed to mount dataset */ 8599653d4eSeschrock EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 86f3861e1aSahl EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 87f3861e1aSahl EZFS_SHARENFSFAILED, /* share(1M) failed */ 8899653d4eSeschrock EZFS_DEVLINKS, /* failed to create zvol links */ 8999653d4eSeschrock EZFS_PERM, /* permission denied */ 9099653d4eSeschrock EZFS_NOSPC, /* out of space */ 9199653d4eSeschrock EZFS_IO, /* I/O error */ 9299653d4eSeschrock EZFS_INTR, /* signal received */ 9399653d4eSeschrock EZFS_ISSPARE, /* device is a hot spare */ 9499653d4eSeschrock EZFS_INVALCONFIG, /* invalid vdev configuration */ 953bb79becSeschrock EZFS_RECURSIVE, /* recursive dependency */ 9606eeb2adSek110237 EZFS_NOHISTORY, /* no history object */ 97f3861e1aSahl EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */ 98f3861e1aSahl EZFS_SHAREISCSIFAILED, /* iscsitgtd failed request to share */ 99b1b8ab34Slling EZFS_POOLPROPS, /* couldn't retrieve pool props */ 100b1b8ab34Slling EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 101b1b8ab34Slling EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 102b7661cccSmmusante EZFS_NAMETOOLONG, /* dataset name is too long */ 1038488aeb5Staylor EZFS_OPENFAILED, /* open of device failed */ 1048488aeb5Staylor EZFS_NOCAP, /* couldn't get capacity */ 1058488aeb5Staylor EZFS_LABELFAILED, /* write of label failed */ 106ecd6cf80Smarks EZFS_ISCSISVCUNAVAIL, /* iscsi service unavailable */ 107ecd6cf80Smarks EZFS_BADWHO, /* invalid permission who */ 108ecd6cf80Smarks EZFS_BADPERM, /* invalid permission */ 109ecd6cf80Smarks EZFS_BADPERMSET, /* invalid permission set name */ 110ecd6cf80Smarks EZFS_NODELEGATION, /* delegated administration is disabled */ 111ecd6cf80Smarks EZFS_PERMRDONLY, /* pemissions are readonly */ 112b1b8ab34Slling EZFS_UNKNOWN 11399653d4eSeschrock }; 11499653d4eSeschrock 11599653d4eSeschrock /* 116ecd6cf80Smarks * The following data structures are all part 117ecd6cf80Smarks * of the zfs_allow_t data structure which is 118ecd6cf80Smarks * used for printing 'allow' permissions. 119ecd6cf80Smarks * It is a linked list of zfs_allow_t's which 120ecd6cf80Smarks * then contain avl tree's for user/group/sets/... 121ecd6cf80Smarks * and each one of the entries in those trees have 122ecd6cf80Smarks * avl tree's for the permissions they belong to and 123ecd6cf80Smarks * whether they are local,descendent or local+descendent 124ecd6cf80Smarks * permissions. The AVL trees are used primarily for 125ecd6cf80Smarks * sorting purposes, but also so that we can quickly find 126ecd6cf80Smarks * a given user and or permission. 127ecd6cf80Smarks */ 128ecd6cf80Smarks typedef struct zfs_perm_node { 129ecd6cf80Smarks avl_node_t z_node; 130ecd6cf80Smarks char z_pname[MAXPATHLEN]; 131ecd6cf80Smarks } zfs_perm_node_t; 132ecd6cf80Smarks 133ecd6cf80Smarks typedef struct zfs_allow_node { 134ecd6cf80Smarks avl_node_t z_node; 135ecd6cf80Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 136ecd6cf80Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 137ecd6cf80Smarks avl_tree_t z_local; /* local permissions */ 138ecd6cf80Smarks avl_tree_t z_descend; /* descendent permissions */ 139ecd6cf80Smarks } zfs_allow_node_t; 140ecd6cf80Smarks 141ecd6cf80Smarks typedef struct zfs_allow { 142ecd6cf80Smarks struct zfs_allow *z_next; 143ecd6cf80Smarks char z_setpoint[MAXPATHLEN]; 144ecd6cf80Smarks avl_tree_t z_sets; 145ecd6cf80Smarks avl_tree_t z_crperms; 146ecd6cf80Smarks avl_tree_t z_user; 147ecd6cf80Smarks avl_tree_t z_group; 148ecd6cf80Smarks avl_tree_t z_everyone; 149ecd6cf80Smarks } zfs_allow_t; 150ecd6cf80Smarks 151ecd6cf80Smarks /* 152fa9e4066Sahrens * Basic handle types 153fa9e4066Sahrens */ 154fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t; 155fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t; 15699653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t; 15799653d4eSeschrock 15899653d4eSeschrock /* 15999653d4eSeschrock * Library initialization 16099653d4eSeschrock */ 16199653d4eSeschrock extern libzfs_handle_t *libzfs_init(void); 16299653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *); 16399653d4eSeschrock 16499653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 16599653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 16699653d4eSeschrock 16799653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 16899653d4eSeschrock 16999653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *); 17099653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *); 17199653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *); 172fa9e4066Sahrens 173fa9e4066Sahrens /* 174fa9e4066Sahrens * Basic handle functions 175fa9e4066Sahrens */ 17699653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 17799653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 178fa9e4066Sahrens extern void zpool_close(zpool_handle_t *); 179fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *); 180fa9e4066Sahrens extern uint64_t zpool_get_guid(zpool_handle_t *); 181fa9e4066Sahrens extern uint64_t zpool_get_space_used(zpool_handle_t *); 182fa9e4066Sahrens extern uint64_t zpool_get_space_total(zpool_handle_t *); 183fa9e4066Sahrens extern int zpool_get_root(zpool_handle_t *, char *, size_t); 184fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *); 18599653d4eSeschrock extern uint64_t zpool_get_version(zpool_handle_t *); 186fa9e4066Sahrens 187fa9e4066Sahrens /* 188fa9e4066Sahrens * Iterate over all active pools in the system. 189fa9e4066Sahrens */ 190fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 19199653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 192fa9e4066Sahrens 193fa9e4066Sahrens /* 194fa9e4066Sahrens * Functions to create and destroy pools 195fa9e4066Sahrens */ 19699653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 19799653d4eSeschrock const char *); 198fa9e4066Sahrens extern int zpool_destroy(zpool_handle_t *); 199fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 200fa9e4066Sahrens 201fa9e4066Sahrens /* 202fa9e4066Sahrens * Functions to manipulate pool and vdev state 203fa9e4066Sahrens */ 204fa9e4066Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t); 2053d7072f8Seschrock extern int zpool_clear(zpool_handle_t *, const char *); 206fa9e4066Sahrens 2073d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2083d7072f8Seschrock vdev_state_t *); 2093d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2103d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2113d7072f8Seschrock const char *, nvlist_t *, int); 212fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 21399653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 2143d7072f8Seschrock 2153d7072f8Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t); 2163d7072f8Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t); 2173d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2183d7072f8Seschrock 21999653d4eSeschrock extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *); 2208488aeb5Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *); 221fa9e4066Sahrens 222fa9e4066Sahrens /* 223b1b8ab34Slling * Functions to manage pool properties 224b1b8ab34Slling */ 225b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2263d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 227b1b8ab34Slling size_t proplen, zfs_source_t *); 2283d7072f8Seschrock extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t); 229b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t); 230b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t); 231b1b8ab34Slling 232b1b8ab34Slling /* 233fa9e4066Sahrens * Pool health statistics. 234fa9e4066Sahrens */ 235fa9e4066Sahrens typedef enum { 236fa9e4066Sahrens /* 237fa9e4066Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 238b81d61a6Slling * event namespace. Each is associated with a corresponding message ID. 239fa9e4066Sahrens */ 240fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 241fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 242fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 243fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 244b81d61a6Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 245fa9e4066Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 246fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 247fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 248fa9e4066Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 249eaca9bbdSeschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 25095173954Sek110237 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 2513d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 2523d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 253fa9e4066Sahrens 254fa9e4066Sahrens /* 255fa9e4066Sahrens * The following are not faults per se, but still an error possibly 256b81d61a6Slling * requiring administrative attention. There is no corresponding 257fa9e4066Sahrens * message ID. 258fa9e4066Sahrens */ 259eaca9bbdSeschrock ZPOOL_STATUS_VERSION_OLDER, /* older on-disk version */ 260fa9e4066Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 261fa9e4066Sahrens ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 262fa9e4066Sahrens 263fa9e4066Sahrens /* 264fa9e4066Sahrens * Finally, the following indicates a healthy pool. 265fa9e4066Sahrens */ 266fa9e4066Sahrens ZPOOL_STATUS_OK 267fa9e4066Sahrens } zpool_status_t; 268fa9e4066Sahrens 269ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 270ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 271fa9e4066Sahrens 272fa9e4066Sahrens /* 273fa9e4066Sahrens * Statistics and configuration functions. 274fa9e4066Sahrens */ 275ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 27694de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 27755434c77Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 278ea8dc4b6Seschrock 279fa9e4066Sahrens /* 280fa9e4066Sahrens * Import and export functions 281fa9e4066Sahrens */ 282fa9e4066Sahrens extern int zpool_export(zpool_handle_t *); 28399653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 28499653d4eSeschrock const char *); 285fa9e4066Sahrens 286fa9e4066Sahrens /* 287fa9e4066Sahrens * Search for pools to import 288fa9e4066Sahrens */ 28999653d4eSeschrock extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 290fa9e4066Sahrens 291fa9e4066Sahrens /* 292c67d9675Seschrock * Miscellaneous pool functions 293c67d9675Seschrock */ 294ecd6cf80Smarks struct zfs_cmd; 295ecd6cf80Smarks 29699653d4eSeschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *); 297eaca9bbdSeschrock extern int zpool_upgrade(zpool_handle_t *); 29806eeb2adSek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 299*2a6b87f0Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc, 300*2a6b87f0Sek110237 char **argv, char *history_str); 301*2a6b87f0Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *); 30255434c77Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 30355434c77Sek110237 size_t len); 304ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 305c67d9675Seschrock /* 306fa9e4066Sahrens * Basic handle manipulations. These functions do not create or destroy the 307fa9e4066Sahrens * underlying datasets, only the references to them. 308fa9e4066Sahrens */ 30999653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 310fa9e4066Sahrens extern void zfs_close(zfs_handle_t *); 311fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 312fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 313fa9e4066Sahrens 314fa9e4066Sahrens /* 315fa9e4066Sahrens * Property management functions. Some functions are shared with the kernel, 316b81d61a6Slling * and are found in sys/fs/zfs.h. 317fa9e4066Sahrens */ 318e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t); 319e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 320e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 321e9dbad6fSeschrock zfs_source_t *, char *, size_t, boolean_t); 322e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 323e9dbad6fSeschrock zfs_source_t *, char *, size_t); 324e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 325e9dbad6fSeschrock extern const char *zfs_prop_get_string(zfs_handle_t *, zfs_prop_t); 326e9dbad6fSeschrock extern int zfs_prop_inherit(zfs_handle_t *, const char *); 327e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t); 328e9dbad6fSeschrock extern int zfs_prop_valid_for_type(zfs_prop_t, int); 329e9dbad6fSeschrock extern const char *zfs_prop_default_string(zfs_prop_t prop); 330e9dbad6fSeschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 331e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop); 332e9dbad6fSeschrock extern const char *zfs_prop_column_name(zfs_prop_t); 333e9dbad6fSeschrock extern boolean_t zfs_prop_align_right(zfs_prop_t); 334e9dbad6fSeschrock 335e9dbad6fSeschrock typedef struct zfs_proplist { 336e9dbad6fSeschrock zfs_prop_t pl_prop; 337e9dbad6fSeschrock char *pl_user_prop; 338e9dbad6fSeschrock struct zfs_proplist *pl_next; 339e9dbad6fSeschrock boolean_t pl_all; 340e9dbad6fSeschrock size_t pl_width; 341e9dbad6fSeschrock boolean_t pl_fixed; 342e9dbad6fSeschrock } zfs_proplist_t; 343e9dbad6fSeschrock 344b1b8ab34Slling typedef zfs_proplist_t zpool_proplist_t; 345b1b8ab34Slling 346e9dbad6fSeschrock extern int zfs_get_proplist(libzfs_handle_t *, char *, zfs_proplist_t **); 347b1b8ab34Slling extern int zpool_get_proplist(libzfs_handle_t *, char *, zpool_proplist_t **); 348e9dbad6fSeschrock extern int zfs_expand_proplist(zfs_handle_t *, zfs_proplist_t **); 349b1b8ab34Slling extern int zpool_expand_proplist(zpool_handle_t *, zpool_proplist_t **); 350b1b8ab34Slling extern void zfs_free_proplist(zfs_proplist_t *); 351e9dbad6fSeschrock extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 352fa9e4066Sahrens 353fa9e4066Sahrens #define ZFS_MOUNTPOINT_NONE "none" 354fa9e4066Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 355fa9e4066Sahrens 356fa9e4066Sahrens /* 357b1b8ab34Slling * Functions for printing properties from zfs/zpool 358b1b8ab34Slling */ 359b1b8ab34Slling typedef struct libzfs_get_cbdata { 360b1b8ab34Slling int cb_sources; 361b1b8ab34Slling int cb_columns[4]; 362b1b8ab34Slling int cb_colwidths[5]; 363b1b8ab34Slling boolean_t cb_scripted; 364b1b8ab34Slling boolean_t cb_literal; 365b1b8ab34Slling boolean_t cb_first; 366b1b8ab34Slling zfs_proplist_t *cb_proplist; 367b1b8ab34Slling } libzfs_get_cbdata_t; 368b1b8ab34Slling 369b1b8ab34Slling void libzfs_print_one_property(const char *, libzfs_get_cbdata_t *, 370b1b8ab34Slling const char *, const char *, zfs_source_t, const char *); 371b1b8ab34Slling 372b1b8ab34Slling #define GET_COL_NAME 1 373b1b8ab34Slling #define GET_COL_PROPERTY 2 374b1b8ab34Slling #define GET_COL_VALUE 3 375b1b8ab34Slling #define GET_COL_SOURCE 4 376b1b8ab34Slling 377b1b8ab34Slling /* 378fa9e4066Sahrens * Iterator functions. 379fa9e4066Sahrens */ 380fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 38199653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 382fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 3833bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 3847f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 3857f7322feSeschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); 386fa9e4066Sahrens 387fa9e4066Sahrens /* 388fa9e4066Sahrens * Functions to create and destroy datasets. 389fa9e4066Sahrens */ 39099653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 391e9dbad6fSeschrock nvlist_t *); 3927f1f55eaSvb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 393fa9e4066Sahrens extern int zfs_destroy(zfs_handle_t *); 3941d452cf5Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *); 395e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 3961d452cf5Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t); 397b12a1c38Slling extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, int); 3987f1f55eaSvb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); 39972bdce51Sahl extern int zfs_send(zfs_handle_t *, const char *, int); 40098579b20Snd150628 extern int zfs_receive(libzfs_handle_t *, const char *, int, int, int, 40172bdce51Sahl boolean_t, int); 40299653d4eSeschrock extern int zfs_promote(zfs_handle_t *); 403fa9e4066Sahrens 404fa9e4066Sahrens /* 405fa9e4066Sahrens * Miscellaneous functions. 406fa9e4066Sahrens */ 407fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t); 408fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 409fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 4105aba80dbSck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 4117f1f55eaSvb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 4127f1f55eaSvb160487 zfs_type_t); 413fa9e4066Sahrens 414fa9e4066Sahrens /* 415ecd6cf80Smarks * dataset permission functions. 416ecd6cf80Smarks */ 417ecd6cf80Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *); 418ecd6cf80Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *); 419ecd6cf80Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *, 420ecd6cf80Smarks zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t); 421ecd6cf80Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **); 422ecd6cf80Smarks extern void zfs_free_allows(zfs_allow_t *); 423ecd6cf80Smarks 424ecd6cf80Smarks /* 425fa9e4066Sahrens * Mount support functions. 426fa9e4066Sahrens */ 42755434c77Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 42899653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 429fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 430fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 431fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 432fa9e4066Sahrens 433fa9e4066Sahrens /* 434fa9e4066Sahrens * Share support functions. 435fa9e4066Sahrens */ 436f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *); 437fa9e4066Sahrens extern int zfs_share(zfs_handle_t *); 438f3861e1aSahl extern int zfs_unshare(zfs_handle_t *); 439f3861e1aSahl 440f3861e1aSahl /* 4413d7072f8Seschrock * Protocol-specific share support functions. 442f3861e1aSahl */ 443f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 444f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *); 445f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 446f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *); 447f3861e1aSahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *); 448f3861e1aSahl extern int zfs_share_iscsi(zfs_handle_t *); 449f3861e1aSahl extern int zfs_unshare_iscsi(zfs_handle_t *); 450ecd6cf80Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *); 451ecd6cf80Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, 452ecd6cf80Smarks void *, void *, int, boolean_t); 453fa9e4066Sahrens 454fa9e4066Sahrens /* 455fa9e4066Sahrens * When dealing with nvlists, verify() is extremely useful 456fa9e4066Sahrens */ 457fa9e4066Sahrens #ifdef NDEBUG 458fa9e4066Sahrens #define verify(EX) ((void)(EX)) 459fa9e4066Sahrens #else 460fa9e4066Sahrens #define verify(EX) assert(EX) 461fa9e4066Sahrens #endif 462fa9e4066Sahrens 463fa9e4066Sahrens /* 464fa9e4066Sahrens * Utility function to convert a number to a human-readable form. 465fa9e4066Sahrens */ 466fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 467e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 468fa9e4066Sahrens 469fa9e4066Sahrens /* 470fa9e4066Sahrens * Pool destroy special. Remove the device information without destroying 471fa9e4066Sahrens * the underlying dataset. 472fa9e4066Sahrens */ 473fa9e4066Sahrens extern int zfs_remove_link(zfs_handle_t *); 474fa9e4066Sahrens 475fa9e4066Sahrens /* 476fa9e4066Sahrens * Given a device or file, determine if it is part of a pool. 477fa9e4066Sahrens */ 47899653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 47999653d4eSeschrock boolean_t *); 480fa9e4066Sahrens 481fa9e4066Sahrens /* 482fa9e4066Sahrens * ftyp special. Read the label from a given device. 483fa9e4066Sahrens */ 48499653d4eSeschrock extern int zpool_read_label(int, nvlist_t **); 485fa9e4066Sahrens 486fa9e4066Sahrens /* 487f3861e1aSahl * Create and remove zvol /dev links. 488fa9e4066Sahrens */ 489fa9e4066Sahrens extern int zpool_create_zvol_links(zpool_handle_t *); 490fa9e4066Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *); 491fa9e4066Sahrens 4923bb79becSeschrock /* 493f3861e1aSahl * Enable and disable datasets within a pool by mounting/unmounting and 494f3861e1aSahl * sharing/unsharing them. 4953bb79becSeschrock */ 496f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 497f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 4983bb79becSeschrock 499fa9e4066Sahrens #ifdef __cplusplus 500fa9e4066Sahrens } 501fa9e4066Sahrens #endif 502fa9e4066Sahrens 503fa9e4066Sahrens #endif /* _LIBZFS_H */ 504