Home | History | Annotate | Download | only in sys
      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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #ifndef	_SYS_ZFS_IOCTL_H
     27 #define	_SYS_ZFS_IOCTL_H
     28 
     29 #include <sys/cred.h>
     30 #include <sys/dmu.h>
     31 #include <sys/zio.h>
     32 #include <sys/dsl_deleg.h>
     33 #include <sys/spa.h>
     34 
     35 #ifdef _KERNEL
     36 #include <sys/nvpair.h>
     37 #endif	/* _KERNEL */
     38 
     39 #ifdef	__cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 /*
     44  * Property values for snapdir
     45  */
     46 #define	ZFS_SNAPDIR_HIDDEN		0
     47 #define	ZFS_SNAPDIR_VISIBLE		1
     48 
     49 /*
     50  * Field manipulation macros for the drr_versioninfo field of the
     51  * send stream header.
     52  */
     53 
     54 /*
     55  * Header types for zfs send streams.
     56  */
     57 typedef enum drr_headertype {
     58 	DMU_SUBSTREAM = 0x1,
     59 	DMU_COMPOUNDSTREAM = 0x2
     60 } drr_headertype_t;
     61 
     62 #define	DMU_GET_STREAM_HDRTYPE(vi)	BF64_GET((vi), 0, 2)
     63 #define	DMU_SET_STREAM_HDRTYPE(vi, x)	BF64_SET((vi), 0, 2, x)
     64 
     65 #define	DMU_GET_FEATUREFLAGS(vi)	BF64_GET((vi), 2, 30)
     66 #define	DMU_SET_FEATUREFLAGS(vi, x)	BF64_SET((vi), 2, 30, x)
     67 
     68 /*
     69  * Feature flags for zfs send streams (flags in drr_versioninfo)
     70  */
     71 
     72 #define	DMU_BACKUP_FEATURE_DEDUP	(0x1)
     73 
     74 /*
     75  * Mask of all supported backup features
     76  */
     77 #define	DMU_BACKUP_FEATURE_MASK	(DMU_BACKUP_FEATURE_DEDUP)
     78 
     79 /* Are all features in the given flag word currently supported? */
     80 #define	DMU_STREAM_SUPPORTED(x)	(!((x) & ~DMU_BACKUP_FEATURE_MASK))
     81 
     82 /*
     83  * The drr_versioninfo field of the dmu_replay_record has the
     84  * following layout:
     85  *
     86  *	64	56	48	40	32	24	16	8	0
     87  *	+-------+-------+-------+-------+-------+-------+-------+-------+
     88  *  	|		reserved	|        feature-flags	    |C|S|
     89  *	+-------+-------+-------+-------+-------+-------+-------+-------+
     90  *
     91  * The low order two bits indicate the header type: SUBSTREAM (0x1)
     92  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
     93  * this field used to be a version number, where the two version types
     94  * were 1 and 2.  Using two bits for this allows earlier versions of
     95  * the code to be able to recognize send streams that don't use any
     96  * of the features indicated by feature flags.
     97  */
     98 
     99 #define	DMU_BACKUP_MAGIC 0x2F5bacbacULL
    100 
    101 #define	DRR_FLAG_CLONE		(1<<0)
    102 #define	DRR_FLAG_CI_DATA	(1<<1)
    103 
    104 /*
    105  * zfs ioctl command structure
    106  */
    107 typedef struct dmu_replay_record {
    108 	enum {
    109 		DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
    110 		DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
    111 		DRR_NUMTYPES
    112 	} drr_type;
    113 	uint32_t drr_payloadlen;
    114 	union {
    115 		struct drr_begin {
    116 			uint64_t drr_magic;
    117 			uint64_t drr_versioninfo; /* was drr_version */
    118 			uint64_t drr_creation_time;
    119 			dmu_objset_type_t drr_type;
    120 			uint32_t drr_flags;
    121 			uint64_t drr_toguid;
    122 			uint64_t drr_fromguid;
    123 			char drr_toname[MAXNAMELEN];
    124 		} drr_begin;
    125 		struct drr_end {
    126 			zio_cksum_t drr_checksum;
    127 			uint64_t drr_toguid;
    128 		} drr_end;
    129 		struct drr_object {
    130 			uint64_t drr_object;
    131 			dmu_object_type_t drr_type;
    132 			dmu_object_type_t drr_bonustype;
    133 			uint32_t drr_blksz;
    134 			uint32_t drr_bonuslen;
    135 			uint8_t drr_checksumtype;
    136 			uint8_t drr_compress;
    137 			uint8_t drr_pad[6];
    138 			uint64_t drr_toguid;
    139 			/* bonus content follows */
    140 		} drr_object;
    141 		struct drr_freeobjects {
    142 			uint64_t drr_firstobj;
    143 			uint64_t drr_numobjs;
    144 			uint64_t drr_toguid;
    145 		} drr_freeobjects;
    146 		struct drr_write {
    147 			uint64_t drr_object;
    148 			dmu_object_type_t drr_type;
    149 			uint32_t drr_pad;
    150 			uint64_t drr_offset;
    151 			uint64_t drr_length;
    152 			uint64_t drr_toguid;
    153 			uint8_t drr_checksumtype;
    154 			uint8_t drr_pad2[7];
    155 			zio_cksum_t drr_blkcksum;
    156 			/* content follows */
    157 		} drr_write;
    158 		struct drr_free {
    159 			uint64_t drr_object;
    160 			uint64_t drr_offset;
    161 			uint64_t drr_length;
    162 			uint64_t drr_toguid;
    163 		} drr_free;
    164 		struct drr_write_byref {
    165 			/* where to put the data */
    166 			uint64_t drr_object;
    167 			uint64_t drr_offset;
    168 			uint64_t drr_length;
    169 			uint64_t drr_toguid;
    170 			/* where to find the prior copy of the data */
    171 			uint64_t drr_refguid;
    172 			uint64_t drr_refobject;
    173 			uint64_t drr_refoffset;
    174 			uint8_t drr_checksumtype;
    175 			uint8_t drr_pad[7];
    176 			zio_cksum_t drr_blkcksum;
    177 		} drr_write_byref;
    178 	} drr_u;
    179 } dmu_replay_record_t;
    180 
    181 typedef struct zinject_record {
    182 	uint64_t	zi_objset;
    183 	uint64_t	zi_object;
    184 	uint64_t	zi_start;
    185 	uint64_t	zi_end;
    186 	uint64_t	zi_guid;
    187 	uint32_t	zi_level;
    188 	uint32_t	zi_error;
    189 	uint64_t	zi_type;
    190 	uint32_t	zi_freq;
    191 	uint32_t	zi_failfast;
    192 	char		zi_func[MAXNAMELEN];
    193 	uint32_t	zi_iotype;
    194 	int32_t		zi_duration;
    195 	uint64_t	zi_timer;
    196 } zinject_record_t;
    197 
    198 #define	ZINJECT_NULL		0x1
    199 #define	ZINJECT_FLUSH_ARC	0x2
    200 #define	ZINJECT_UNLOAD_SPA	0x4
    201 
    202 typedef struct zfs_share {
    203 	uint64_t	z_exportdata;
    204 	uint64_t	z_sharedata;
    205 	uint64_t	z_sharetype;	/* 0 = share, 1 = unshare */
    206 	uint64_t	z_sharemax;  /* max length of share string */
    207 } zfs_share_t;
    208 
    209 /*
    210  * ZFS file systems may behave the usual, POSIX-compliant way, where
    211  * name lookups are case-sensitive.  They may also be set up so that
    212  * all the name lookups are case-insensitive, or so that only some
    213  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
    214  */
    215 typedef enum zfs_case {
    216 	ZFS_CASE_SENSITIVE,
    217 	ZFS_CASE_INSENSITIVE,
    218 	ZFS_CASE_MIXED
    219 } zfs_case_t;
    220 
    221 typedef struct zfs_cmd {
    222 	char		zc_name[MAXPATHLEN];
    223 	char		zc_value[MAXPATHLEN * 2];
    224 	char		zc_string[MAXNAMELEN];
    225 	char		zc_top_ds[MAXPATHLEN];
    226 	uint64_t	zc_guid;
    227 	uint64_t	zc_nvlist_conf;		/* really (char *) */
    228 	uint64_t	zc_nvlist_conf_size;
    229 	uint64_t	zc_nvlist_src;		/* really (char *) */
    230 	uint64_t	zc_nvlist_src_size;
    231 	uint64_t	zc_nvlist_dst;		/* really (char *) */
    232 	uint64_t	zc_nvlist_dst_size;
    233 	uint64_t	zc_cookie;
    234 	uint64_t	zc_objset_type;
    235 	uint64_t	zc_perm_action;
    236 	uint64_t 	zc_history;		/* really (char *) */
    237 	uint64_t 	zc_history_len;
    238 	uint64_t	zc_history_offset;
    239 	uint64_t	zc_obj;
    240 	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
    241 	zfs_share_t	zc_share;
    242 	dmu_objset_stats_t zc_objset_stats;
    243 	struct drr_begin zc_begin_record;
    244 	zinject_record_t zc_inject_record;
    245 	boolean_t	zc_defer_destroy;
    246 	boolean_t	zc_temphold;
    247 } zfs_cmd_t;
    248 
    249 typedef struct zfs_useracct {
    250 	char zu_domain[256];
    251 	uid_t zu_rid;
    252 	uint32_t zu_pad;
    253 	uint64_t zu_space;
    254 } zfs_useracct_t;
    255 
    256 #define	ZVOL_MAX_MINOR	(1 << 16)
    257 #define	ZFS_MIN_MINOR	(ZVOL_MAX_MINOR + 1)
    258 
    259 #ifdef _KERNEL
    260 
    261 typedef struct zfs_creat {
    262 	nvlist_t	*zct_zplprops;
    263 	nvlist_t	*zct_props;
    264 } zfs_creat_t;
    265 
    266 extern dev_info_t *zfs_dip;
    267 
    268 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
    269 extern int zfs_secpolicy_rename_perms(const char *from,
    270     const char *to, cred_t *cr);
    271 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
    272 extern int zfs_busy(void);
    273 extern int zfs_unmount_snap(char *, void *);
    274 
    275 #endif	/* _KERNEL */
    276 
    277 #ifdef	__cplusplus
    278 }
    279 #endif
    280 
    281 #endif	/* _SYS_ZFS_IOCTL_H */
    282