xref: /freebsd-src/sys/contrib/openzfs/include/sys/zfs_ioctl.h (revision c6767dc1f236f20eecd75790afd42829345153da)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
230d4ad640SMartin Matuska  * Copyright (c) 2012, 2024 by Delphix. All rights reserved.
24eda14cbcSMatt Macy  * Copyright 2016 RackTop Systems.
25eda14cbcSMatt Macy  * Copyright (c) 2017, Intel Corporation.
26*c6767dc1SMartin Matuska  * Copyright (c) 2024-2025, Klara, Inc.
27eda14cbcSMatt Macy  */
28eda14cbcSMatt Macy 
29eda14cbcSMatt Macy #ifndef	_SYS_ZFS_IOCTL_H
30eda14cbcSMatt Macy #define	_SYS_ZFS_IOCTL_H
31eda14cbcSMatt Macy 
32eda14cbcSMatt Macy #include <sys/cred.h>
33eda14cbcSMatt Macy #include <sys/dmu.h>
34eda14cbcSMatt Macy #include <sys/zio.h>
35eda14cbcSMatt Macy #include <sys/dsl_deleg.h>
36eda14cbcSMatt Macy #include <sys/spa.h>
37eda14cbcSMatt Macy #include <sys/zfs_stat.h>
38eda14cbcSMatt Macy 
39eda14cbcSMatt Macy #ifdef _KERNEL
40eda14cbcSMatt Macy #include <sys/nvpair.h>
41eda14cbcSMatt Macy #endif	/* _KERNEL */
42eda14cbcSMatt Macy 
43eda14cbcSMatt Macy #ifdef	__cplusplus
44eda14cbcSMatt Macy extern "C" {
45eda14cbcSMatt Macy #endif
46eda14cbcSMatt Macy 
47eda14cbcSMatt Macy /*
48eda14cbcSMatt Macy  * The structures in this file are passed between userland and the
49eda14cbcSMatt Macy  * kernel.  Userland may be running a 32-bit process, while the kernel
50eda14cbcSMatt Macy  * is 64-bit.  Therefore, these structures need to compile the same in
51eda14cbcSMatt Macy  * 32-bit and 64-bit.  This means not using type "long", and adding
52eda14cbcSMatt Macy  * explicit padding so that the 32-bit structure will not be packed more
53eda14cbcSMatt Macy  * tightly than the 64-bit structure (which requires 64-bit alignment).
54eda14cbcSMatt Macy  */
55eda14cbcSMatt Macy 
56eda14cbcSMatt Macy /*
57eda14cbcSMatt Macy  * Property values for snapdir
58eda14cbcSMatt Macy  */
59eda14cbcSMatt Macy #define	ZFS_SNAPDIR_HIDDEN		0
60eda14cbcSMatt Macy #define	ZFS_SNAPDIR_VISIBLE		1
617a7741afSMartin Matuska #define	ZFS_SNAPDIR_DISABLED		2
62eda14cbcSMatt Macy 
63eda14cbcSMatt Macy /*
64eda14cbcSMatt Macy  * Property values for snapdev
65eda14cbcSMatt Macy  */
66eda14cbcSMatt Macy #define	ZFS_SNAPDEV_HIDDEN		0
67eda14cbcSMatt Macy #define	ZFS_SNAPDEV_VISIBLE		1
68eda14cbcSMatt Macy /*
69eda14cbcSMatt Macy  * Property values for acltype
70eda14cbcSMatt Macy  */
71eda14cbcSMatt Macy #define	ZFS_ACLTYPE_OFF			0
722c48331dSMatt Macy #define	ZFS_ACLTYPE_POSIX		1
73180f8225SMatt Macy #define	ZFS_ACLTYPE_NFSV4		2
74eda14cbcSMatt Macy 
75eda14cbcSMatt Macy /*
767a7741afSMartin Matuska  * The drr_versioninfo field of the dmu_replay_record has the
777a7741afSMartin Matuska  * following layout:
787a7741afSMartin Matuska  *
797a7741afSMartin Matuska  *	64	56	48	40	32	24	16	8	0
807a7741afSMartin Matuska  *	+-------+-------+-------+-------+-------+-------+-------+-------+
817a7741afSMartin Matuska  *	|reserve|		  feature-flags			    |C|S|
827a7741afSMartin Matuska  *	+-------+-------+-------+-------+-------+-------+-------+-------+
837a7741afSMartin Matuska  *
847a7741afSMartin Matuska  * The low order two bits indicate the header type: SUBSTREAM (0x1)
857a7741afSMartin Matuska  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
867a7741afSMartin Matuska  * this field used to be a version number, where the two version types
877a7741afSMartin Matuska  * were 1 and 2.  Using two bits for this allows earlier versions of
887a7741afSMartin Matuska  * the code to be able to recognize send streams that don't use any
897a7741afSMartin Matuska  * of the features indicated by feature flags.
907a7741afSMartin Matuska  *
917a7741afSMartin Matuska  * The top 8 bits are reserved for future expansion. At time of writing there
927a7741afSMartin Matuska  * are no plans for these. If you want to use them, please reach out to the
937a7741afSMartin Matuska  * OpenZFS community, e.g., on GitHub or Slack.
947a7741afSMartin Matuska  */
957a7741afSMartin Matuska 
967a7741afSMartin Matuska /*
97eda14cbcSMatt Macy  * Field manipulation macros for the drr_versioninfo field of the
98eda14cbcSMatt Macy  * send stream header.
99eda14cbcSMatt Macy  */
1007a7741afSMartin Matuska #define	DMU_GET_STREAM_HDRTYPE(vi)	BF64_GET((vi), 0, 2)
1017a7741afSMartin Matuska #define	DMU_SET_STREAM_HDRTYPE(vi, x)	BF64_SET((vi), 0, 2, x)
1027a7741afSMartin Matuska 
1037a7741afSMartin Matuska #define	DMU_GET_FEATUREFLAGS(vi)	BF64_GET((vi), 2, 56)
1047a7741afSMartin Matuska #define	DMU_SET_FEATUREFLAGS(vi, x)	BF64_SET((vi), 2, 56, x)
105eda14cbcSMatt Macy 
106eda14cbcSMatt Macy /*
107eda14cbcSMatt Macy  * Header types for zfs send streams.
108eda14cbcSMatt Macy  */
109eda14cbcSMatt Macy typedef enum drr_headertype {
110eda14cbcSMatt Macy 	DMU_SUBSTREAM = 0x1,
111eda14cbcSMatt Macy 	DMU_COMPOUNDSTREAM = 0x2
112eda14cbcSMatt Macy } drr_headertype_t;
113eda14cbcSMatt Macy 
114eda14cbcSMatt Macy /*
115eda14cbcSMatt Macy  * Feature flags for zfs send streams (flags in drr_versioninfo)
116eda14cbcSMatt Macy  */
117eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_DEDUP		(1 << 0)
118eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_DEDUPPROPS		(1 << 1)
119eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_SA_SPILL		(1 << 2)
120eda14cbcSMatt Macy /* flags #3 - #15 are reserved for incompatible closed-source implementations */
121eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_EMBED_DATA		(1 << 16)
122eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_LZ4			(1 << 17)
123eda14cbcSMatt Macy /* flag #18 is reserved for a Delphix feature */
124eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_LARGE_BLOCKS		(1 << 19)
125eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_RESUMING		(1 << 20)
126eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_REDACTED		(1 << 21)
127eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_COMPRESSED		(1 << 22)
128eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_LARGE_DNODE		(1 << 23)
129eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_RAW			(1 << 24)
130eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_ZSTD			(1 << 25)
131eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_HOLDS		(1 << 26)
132eda14cbcSMatt Macy /*
133eda14cbcSMatt Macy  * The SWITCH_TO_LARGE_BLOCKS feature indicates that we can receive
134eda14cbcSMatt Macy  * incremental LARGE_BLOCKS streams (those with WRITE records of >128KB) even
135eda14cbcSMatt Macy  * if the previous send did not use LARGE_BLOCKS, and thus its large blocks
136eda14cbcSMatt Macy  * were split into multiple 128KB WRITE records.  (See
137eda14cbcSMatt Macy  * flush_write_batch_impl() and receive_object()).  Older software that does
138eda14cbcSMatt Macy  * not support this flag may encounter a bug when switching to large blocks,
139eda14cbcSMatt Macy  * which causes files to incorrectly be zeroed.
140eda14cbcSMatt Macy  *
141eda14cbcSMatt Macy  * This flag is currently not set on any send streams.  In the future, we
142eda14cbcSMatt Macy  * intend for incremental send streams of snapshots that have large blocks to
143eda14cbcSMatt Macy  * use LARGE_BLOCKS by default, and these streams will also have the
144eda14cbcSMatt Macy  * SWITCH_TO_LARGE_BLOCKS feature set. This ensures that streams from the
145eda14cbcSMatt Macy  * default use of "zfs send" won't encounter the bug mentioned above.
146eda14cbcSMatt Macy  */
147eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS (1 << 27)
1487a7741afSMartin Matuska #define	DMU_BACKUP_FEATURE_LONGNAME		(1 << 28)
1497a7741afSMartin Matuska #define	DMU_BACKUP_FEATURE_LARGE_MICROZAP	(1 << 29)
150eda14cbcSMatt Macy 
151eda14cbcSMatt Macy /*
152eda14cbcSMatt Macy  * Mask of all supported backup features
153eda14cbcSMatt Macy  */
154eda14cbcSMatt Macy #define	DMU_BACKUP_FEATURE_MASK	(DMU_BACKUP_FEATURE_SA_SPILL | \
155eda14cbcSMatt Macy     DMU_BACKUP_FEATURE_EMBED_DATA | DMU_BACKUP_FEATURE_LZ4 | \
156eda14cbcSMatt Macy     DMU_BACKUP_FEATURE_RESUMING | DMU_BACKUP_FEATURE_LARGE_BLOCKS | \
157eda14cbcSMatt Macy     DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_LARGE_DNODE | \
158eda14cbcSMatt Macy     DMU_BACKUP_FEATURE_RAW | DMU_BACKUP_FEATURE_HOLDS | \
159eda14cbcSMatt Macy     DMU_BACKUP_FEATURE_REDACTED | DMU_BACKUP_FEATURE_SWITCH_TO_LARGE_BLOCKS | \
1607a7741afSMartin Matuska     DMU_BACKUP_FEATURE_ZSTD | DMU_BACKUP_FEATURE_LONGNAME | \
1617a7741afSMartin Matuska     DMU_BACKUP_FEATURE_LARGE_MICROZAP)
162eda14cbcSMatt Macy 
163eda14cbcSMatt Macy /* Are all features in the given flag word currently supported? */
164eda14cbcSMatt Macy #define	DMU_STREAM_SUPPORTED(x)	(!((x) & ~DMU_BACKUP_FEATURE_MASK))
165eda14cbcSMatt Macy 
166eda14cbcSMatt Macy typedef enum dmu_send_resume_token_version {
167eda14cbcSMatt Macy 	ZFS_SEND_RESUME_TOKEN_VERSION = 1
168eda14cbcSMatt Macy } dmu_send_resume_token_version_t;
169eda14cbcSMatt Macy 
170eda14cbcSMatt Macy #define	DMU_BACKUP_MAGIC 0x2F5bacbacULL
171eda14cbcSMatt Macy 
172eda14cbcSMatt Macy /*
173eda14cbcSMatt Macy  * Send stream flags.  Bits 24-31 are reserved for vendor-specific
174eda14cbcSMatt Macy  * implementations and should not be used.
175eda14cbcSMatt Macy  */
176eda14cbcSMatt Macy #define	DRR_FLAG_CLONE		(1<<0)
177eda14cbcSMatt Macy #define	DRR_FLAG_CI_DATA	(1<<1)
178eda14cbcSMatt Macy /*
179eda14cbcSMatt Macy  * This send stream, if it is a full send, includes the FREE and FREEOBJECT
180eda14cbcSMatt Macy  * records that are created by the sending process.  This means that the send
181eda14cbcSMatt Macy  * stream can be received as a clone, even though it is not an incremental.
182eda14cbcSMatt Macy  * This is not implemented as a feature flag, because the receiving side does
183eda14cbcSMatt Macy  * not need to have implemented it to receive this stream; it is fully backwards
184eda14cbcSMatt Macy  * compatible.  We need a flag, though, because full send streams without it
185eda14cbcSMatt Macy  * cannot necessarily be received as a clone correctly.
186eda14cbcSMatt Macy  */
187eda14cbcSMatt Macy #define	DRR_FLAG_FREERECORDS	(1<<2)
188eda14cbcSMatt Macy /*
189eda14cbcSMatt Macy  * When DRR_FLAG_SPILL_BLOCK is set it indicates the DRR_OBJECT_SPILL
190eda14cbcSMatt Macy  * and DRR_SPILL_UNMODIFIED flags are meaningful in the send stream.
191eda14cbcSMatt Macy  *
192eda14cbcSMatt Macy  * When DRR_FLAG_SPILL_BLOCK is set, DRR_OBJECT records will have
193eda14cbcSMatt Macy  * DRR_OBJECT_SPILL set if and only if they should have a spill block
194eda14cbcSMatt Macy  * (either an existing one, or a new one in the send stream).  When clear
195eda14cbcSMatt Macy  * the object does not have a spill block and any existing spill block
196eda14cbcSMatt Macy  * should be freed.
197eda14cbcSMatt Macy  *
198eda14cbcSMatt Macy  * Similarly, when DRR_FLAG_SPILL_BLOCK is set, DRR_SPILL records will
199eda14cbcSMatt Macy  * have DRR_SPILL_UNMODIFIED set if and only if they were included for
200eda14cbcSMatt Macy  * backward compatibility purposes, and can be safely ignored by new versions
201eda14cbcSMatt Macy  * of zfs receive.  Previous versions of ZFS which do not understand the
202eda14cbcSMatt Macy  * DRR_FLAG_SPILL_BLOCK will process this record and recreate any missing
203eda14cbcSMatt Macy  * spill blocks.
204eda14cbcSMatt Macy  */
205eda14cbcSMatt Macy #define	DRR_FLAG_SPILL_BLOCK	(1<<3)
206eda14cbcSMatt Macy 
207eda14cbcSMatt Macy /*
208eda14cbcSMatt Macy  * flags in the drr_flags field in the DRR_WRITE, DRR_SPILL, DRR_OBJECT,
209eda14cbcSMatt Macy  * DRR_WRITE_BYREF, and DRR_OBJECT_RANGE blocks
210eda14cbcSMatt Macy  */
211eda14cbcSMatt Macy #define	DRR_CHECKSUM_DEDUP	(1<<0) /* not used for SPILL records */
212eda14cbcSMatt Macy #define	DRR_RAW_BYTESWAP	(1<<1)
213eda14cbcSMatt Macy #define	DRR_OBJECT_SPILL	(1<<2) /* OBJECT record has a spill block */
214eda14cbcSMatt Macy #define	DRR_SPILL_UNMODIFIED	(1<<2) /* SPILL record for unmodified block */
215eda14cbcSMatt Macy 
216eda14cbcSMatt Macy #define	DRR_IS_DEDUP_CAPABLE(flags)	((flags) & DRR_CHECKSUM_DEDUP)
217eda14cbcSMatt Macy #define	DRR_IS_RAW_BYTESWAPPED(flags)	((flags) & DRR_RAW_BYTESWAP)
218eda14cbcSMatt Macy #define	DRR_OBJECT_HAS_SPILL(flags)	((flags) & DRR_OBJECT_SPILL)
219eda14cbcSMatt Macy #define	DRR_SPILL_IS_UNMODIFIED(flags)	((flags) & DRR_SPILL_UNMODIFIED)
220eda14cbcSMatt Macy 
221eda14cbcSMatt Macy /* deal with compressed drr_write replay records */
222eda14cbcSMatt Macy #define	DRR_WRITE_COMPRESSED(drrw)	((drrw)->drr_compressiontype != 0)
223eda14cbcSMatt Macy #define	DRR_WRITE_PAYLOAD_SIZE(drrw) \
224eda14cbcSMatt Macy 	(DRR_WRITE_COMPRESSED(drrw) ? (drrw)->drr_compressed_size : \
225eda14cbcSMatt Macy 	(drrw)->drr_logical_size)
226eda14cbcSMatt Macy #define	DRR_SPILL_PAYLOAD_SIZE(drrs) \
227eda14cbcSMatt Macy 	((drrs)->drr_compressed_size ? \
228eda14cbcSMatt Macy 	(drrs)->drr_compressed_size : (drrs)->drr_length)
229eda14cbcSMatt Macy #define	DRR_OBJECT_PAYLOAD_SIZE(drro) \
230eda14cbcSMatt Macy 	((drro)->drr_raw_bonuslen != 0 ? \
231eda14cbcSMatt Macy 	(drro)->drr_raw_bonuslen : P2ROUNDUP((drro)->drr_bonuslen, 8))
232eda14cbcSMatt Macy 
233eda14cbcSMatt Macy /* Header is used in C++ so can't forward declare untagged struct */
234eda14cbcSMatt Macy struct drr_begin {
235eda14cbcSMatt Macy 	uint64_t drr_magic;
236eda14cbcSMatt Macy 	uint64_t drr_versioninfo; /* was drr_version */
237eda14cbcSMatt Macy 	uint64_t drr_creation_time;
238eda14cbcSMatt Macy 	dmu_objset_type_t drr_type;
239eda14cbcSMatt Macy 	uint32_t drr_flags;
240eda14cbcSMatt Macy 	uint64_t drr_toguid;
241eda14cbcSMatt Macy 	uint64_t drr_fromguid;
242eda14cbcSMatt Macy 	char drr_toname[MAXNAMELEN];
243eda14cbcSMatt Macy };
244eda14cbcSMatt Macy 
245eda14cbcSMatt Macy typedef struct dmu_replay_record {
246eda14cbcSMatt Macy 	enum {
247eda14cbcSMatt Macy 		DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
248eda14cbcSMatt Macy 		DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
249eda14cbcSMatt Macy 		DRR_SPILL, DRR_WRITE_EMBEDDED, DRR_OBJECT_RANGE, DRR_REDACT,
250eda14cbcSMatt Macy 		DRR_NUMTYPES
251eda14cbcSMatt Macy 	} drr_type;
252eda14cbcSMatt Macy 	uint32_t drr_payloadlen;
253eda14cbcSMatt Macy 	union {
254eda14cbcSMatt Macy 		struct drr_begin drr_begin;
255eda14cbcSMatt Macy 		struct drr_end {
256eda14cbcSMatt Macy 			zio_cksum_t drr_checksum;
257eda14cbcSMatt Macy 			uint64_t drr_toguid;
258eda14cbcSMatt Macy 		} drr_end;
259eda14cbcSMatt Macy 		struct drr_object {
260eda14cbcSMatt Macy 			uint64_t drr_object;
261eda14cbcSMatt Macy 			dmu_object_type_t drr_type;
262eda14cbcSMatt Macy 			dmu_object_type_t drr_bonustype;
263eda14cbcSMatt Macy 			uint32_t drr_blksz;
264eda14cbcSMatt Macy 			uint32_t drr_bonuslen;
265eda14cbcSMatt Macy 			uint8_t drr_checksumtype;
266eda14cbcSMatt Macy 			uint8_t drr_compress;
267eda14cbcSMatt Macy 			uint8_t drr_dn_slots;
268eda14cbcSMatt Macy 			uint8_t drr_flags;
269eda14cbcSMatt Macy 			uint32_t drr_raw_bonuslen;
270eda14cbcSMatt Macy 			uint64_t drr_toguid;
271eda14cbcSMatt Macy 			/* only (possibly) nonzero for raw streams */
272eda14cbcSMatt Macy 			uint8_t drr_indblkshift;
273eda14cbcSMatt Macy 			uint8_t drr_nlevels;
274eda14cbcSMatt Macy 			uint8_t drr_nblkptr;
275eda14cbcSMatt Macy 			uint8_t drr_pad[5];
276eda14cbcSMatt Macy 			uint64_t drr_maxblkid;
277eda14cbcSMatt Macy 			/* bonus content follows */
278eda14cbcSMatt Macy 		} drr_object;
279eda14cbcSMatt Macy 		struct drr_freeobjects {
280eda14cbcSMatt Macy 			uint64_t drr_firstobj;
281eda14cbcSMatt Macy 			uint64_t drr_numobjs;
282eda14cbcSMatt Macy 			uint64_t drr_toguid;
283eda14cbcSMatt Macy 		} drr_freeobjects;
284eda14cbcSMatt Macy 		struct drr_write {
285eda14cbcSMatt Macy 			uint64_t drr_object;
286eda14cbcSMatt Macy 			dmu_object_type_t drr_type;
287eda14cbcSMatt Macy 			uint32_t drr_pad;
288eda14cbcSMatt Macy 			uint64_t drr_offset;
289eda14cbcSMatt Macy 			uint64_t drr_logical_size;
290eda14cbcSMatt Macy 			uint64_t drr_toguid;
291eda14cbcSMatt Macy 			uint8_t drr_checksumtype;
292eda14cbcSMatt Macy 			uint8_t drr_flags;
293eda14cbcSMatt Macy 			uint8_t drr_compressiontype;
294eda14cbcSMatt Macy 			uint8_t drr_pad2[5];
295eda14cbcSMatt Macy 			/* deduplication key */
296eda14cbcSMatt Macy 			ddt_key_t drr_key;
297eda14cbcSMatt Macy 			/* only nonzero if drr_compressiontype is not 0 */
298eda14cbcSMatt Macy 			uint64_t drr_compressed_size;
299eda14cbcSMatt Macy 			/* only nonzero for raw streams */
300eda14cbcSMatt Macy 			uint8_t drr_salt[ZIO_DATA_SALT_LEN];
301eda14cbcSMatt Macy 			uint8_t drr_iv[ZIO_DATA_IV_LEN];
302eda14cbcSMatt Macy 			uint8_t drr_mac[ZIO_DATA_MAC_LEN];
303eda14cbcSMatt Macy 			/* content follows */
304eda14cbcSMatt Macy 		} drr_write;
305eda14cbcSMatt Macy 		struct drr_free {
306eda14cbcSMatt Macy 			uint64_t drr_object;
307eda14cbcSMatt Macy 			uint64_t drr_offset;
308eda14cbcSMatt Macy 			uint64_t drr_length;
309eda14cbcSMatt Macy 			uint64_t drr_toguid;
310eda14cbcSMatt Macy 		} drr_free;
311eda14cbcSMatt Macy 		struct drr_write_byref {
312eda14cbcSMatt Macy 			/* where to put the data */
313eda14cbcSMatt Macy 			uint64_t drr_object;
314eda14cbcSMatt Macy 			uint64_t drr_offset;
315eda14cbcSMatt Macy 			uint64_t drr_length;
316eda14cbcSMatt Macy 			uint64_t drr_toguid;
317eda14cbcSMatt Macy 			/* where to find the prior copy of the data */
318eda14cbcSMatt Macy 			uint64_t drr_refguid;
319eda14cbcSMatt Macy 			uint64_t drr_refobject;
320eda14cbcSMatt Macy 			uint64_t drr_refoffset;
321eda14cbcSMatt Macy 			/* properties of the data */
322eda14cbcSMatt Macy 			uint8_t drr_checksumtype;
323eda14cbcSMatt Macy 			uint8_t drr_flags;
324eda14cbcSMatt Macy 			uint8_t drr_pad2[6];
325eda14cbcSMatt Macy 			ddt_key_t drr_key; /* deduplication key */
326eda14cbcSMatt Macy 		} drr_write_byref;
327eda14cbcSMatt Macy 		struct drr_spill {
328eda14cbcSMatt Macy 			uint64_t drr_object;
329eda14cbcSMatt Macy 			uint64_t drr_length;
330eda14cbcSMatt Macy 			uint64_t drr_toguid;
331eda14cbcSMatt Macy 			uint8_t drr_flags;
332eda14cbcSMatt Macy 			uint8_t drr_compressiontype;
333eda14cbcSMatt Macy 			uint8_t drr_pad[6];
334eda14cbcSMatt Macy 			/* only nonzero for raw streams */
335eda14cbcSMatt Macy 			uint64_t drr_compressed_size;
336eda14cbcSMatt Macy 			uint8_t drr_salt[ZIO_DATA_SALT_LEN];
337eda14cbcSMatt Macy 			uint8_t drr_iv[ZIO_DATA_IV_LEN];
338eda14cbcSMatt Macy 			uint8_t drr_mac[ZIO_DATA_MAC_LEN];
339eda14cbcSMatt Macy 			dmu_object_type_t drr_type;
340eda14cbcSMatt Macy 			/* spill data follows */
341eda14cbcSMatt Macy 		} drr_spill;
342eda14cbcSMatt Macy 		struct drr_write_embedded {
343eda14cbcSMatt Macy 			uint64_t drr_object;
344eda14cbcSMatt Macy 			uint64_t drr_offset;
345eda14cbcSMatt Macy 			/* logical length, should equal blocksize */
346eda14cbcSMatt Macy 			uint64_t drr_length;
347eda14cbcSMatt Macy 			uint64_t drr_toguid;
348eda14cbcSMatt Macy 			uint8_t drr_compression;
349eda14cbcSMatt Macy 			uint8_t drr_etype;
350eda14cbcSMatt Macy 			uint8_t drr_pad[6];
351eda14cbcSMatt Macy 			uint32_t drr_lsize; /* uncompressed size of payload */
352eda14cbcSMatt Macy 			uint32_t drr_psize; /* compr. (real) size of payload */
353eda14cbcSMatt Macy 			/* (possibly compressed) content follows */
354eda14cbcSMatt Macy 		} drr_write_embedded;
355eda14cbcSMatt Macy 		struct drr_object_range {
356eda14cbcSMatt Macy 			uint64_t drr_firstobj;
357eda14cbcSMatt Macy 			uint64_t drr_numslots;
358eda14cbcSMatt Macy 			uint64_t drr_toguid;
359eda14cbcSMatt Macy 			uint8_t drr_salt[ZIO_DATA_SALT_LEN];
360eda14cbcSMatt Macy 			uint8_t drr_iv[ZIO_DATA_IV_LEN];
361eda14cbcSMatt Macy 			uint8_t drr_mac[ZIO_DATA_MAC_LEN];
362eda14cbcSMatt Macy 			uint8_t drr_flags;
363eda14cbcSMatt Macy 			uint8_t drr_pad[3];
364eda14cbcSMatt Macy 		} drr_object_range;
365eda14cbcSMatt Macy 		struct drr_redact {
366eda14cbcSMatt Macy 			uint64_t drr_object;
367eda14cbcSMatt Macy 			uint64_t drr_offset;
368eda14cbcSMatt Macy 			uint64_t drr_length;
369eda14cbcSMatt Macy 			uint64_t drr_toguid;
370eda14cbcSMatt Macy 		} drr_redact;
371eda14cbcSMatt Macy 
372eda14cbcSMatt Macy 		/*
373eda14cbcSMatt Macy 		 * Note: drr_checksum is overlaid with all record types
374eda14cbcSMatt Macy 		 * except DRR_BEGIN.  Therefore its (non-pad) members
375eda14cbcSMatt Macy 		 * must not overlap with members from the other structs.
376eda14cbcSMatt Macy 		 * We accomplish this by putting its members at the very
377eda14cbcSMatt Macy 		 * end of the struct.
378eda14cbcSMatt Macy 		 */
379eda14cbcSMatt Macy 		struct drr_checksum {
380eda14cbcSMatt Macy 			uint64_t drr_pad[34];
381eda14cbcSMatt Macy 			/*
382eda14cbcSMatt Macy 			 * fletcher-4 checksum of everything preceding the
383eda14cbcSMatt Macy 			 * checksum.
384eda14cbcSMatt Macy 			 */
385eda14cbcSMatt Macy 			zio_cksum_t drr_checksum;
386eda14cbcSMatt Macy 		} drr_checksum;
387eda14cbcSMatt Macy 	} drr_u;
388eda14cbcSMatt Macy } dmu_replay_record_t;
389eda14cbcSMatt Macy 
390eda14cbcSMatt Macy /* diff record range types */
391eda14cbcSMatt Macy typedef enum diff_type {
392eda14cbcSMatt Macy 	DDR_NONE = 0x1,
393eda14cbcSMatt Macy 	DDR_INUSE = 0x2,
394eda14cbcSMatt Macy 	DDR_FREE = 0x4
395eda14cbcSMatt Macy } diff_type_t;
396eda14cbcSMatt Macy 
397eda14cbcSMatt Macy /*
398eda14cbcSMatt Macy  * The diff reports back ranges of free or in-use objects.
399eda14cbcSMatt Macy  */
400eda14cbcSMatt Macy typedef struct dmu_diff_record {
401eda14cbcSMatt Macy 	uint64_t ddr_type;
402eda14cbcSMatt Macy 	uint64_t ddr_first;
403eda14cbcSMatt Macy 	uint64_t ddr_last;
404eda14cbcSMatt Macy } dmu_diff_record_t;
405eda14cbcSMatt Macy 
406eda14cbcSMatt Macy typedef struct zinject_record {
407eda14cbcSMatt Macy 	uint64_t	zi_objset;
408eda14cbcSMatt Macy 	uint64_t	zi_object;
409eda14cbcSMatt Macy 	uint64_t	zi_start;
410eda14cbcSMatt Macy 	uint64_t	zi_end;
411eda14cbcSMatt Macy 	uint64_t	zi_guid;
412eda14cbcSMatt Macy 	uint32_t	zi_level;
413eda14cbcSMatt Macy 	uint32_t	zi_error;
414eda14cbcSMatt Macy 	uint64_t	zi_type;
415eda14cbcSMatt Macy 	uint32_t	zi_freq;
416eda14cbcSMatt Macy 	uint32_t	zi_failfast;
417eda14cbcSMatt Macy 	char		zi_func[MAXNAMELEN];
418eda14cbcSMatt Macy 	uint32_t	zi_iotype;
419eda14cbcSMatt Macy 	int32_t		zi_duration;
420eda14cbcSMatt Macy 	uint64_t	zi_timer;
421eda14cbcSMatt Macy 	uint64_t	zi_nlanes;
422eda14cbcSMatt Macy 	uint32_t	zi_cmd;
423eda14cbcSMatt Macy 	uint32_t	zi_dvas;
424*c6767dc1SMartin Matuska 	uint64_t	zi_match_count;		/* count of times matched */
425*c6767dc1SMartin Matuska 	uint64_t	zi_inject_count;	/* count of times injected */
426eda14cbcSMatt Macy } zinject_record_t;
427eda14cbcSMatt Macy 
428eda14cbcSMatt Macy #define	ZINJECT_NULL		0x1
429eda14cbcSMatt Macy #define	ZINJECT_FLUSH_ARC	0x2
430eda14cbcSMatt Macy #define	ZINJECT_UNLOAD_SPA	0x4
431eda14cbcSMatt Macy #define	ZINJECT_CALC_RANGE	0x8
432eda14cbcSMatt Macy 
433eda14cbcSMatt Macy #define	ZEVENT_NONE		0x0
434eda14cbcSMatt Macy #define	ZEVENT_NONBLOCK		0x1
435eda14cbcSMatt Macy #define	ZEVENT_SIZE		1024
436eda14cbcSMatt Macy 
437eda14cbcSMatt Macy #define	ZEVENT_SEEK_START	0
438eda14cbcSMatt Macy #define	ZEVENT_SEEK_END		UINT64_MAX
439eda14cbcSMatt Macy 
440eda14cbcSMatt Macy /* scaled frequency ranges */
441eda14cbcSMatt Macy #define	ZI_PERCENTAGE_MIN	4294UL
442eda14cbcSMatt Macy #define	ZI_PERCENTAGE_MAX	UINT32_MAX
443eda14cbcSMatt Macy 
444eda14cbcSMatt Macy #define	ZI_NO_DVA		(-1)
445eda14cbcSMatt Macy 
446eda14cbcSMatt Macy typedef enum zinject_type {
447eda14cbcSMatt Macy 	ZINJECT_UNINITIALIZED,
448eda14cbcSMatt Macy 	ZINJECT_DATA_FAULT,
449eda14cbcSMatt Macy 	ZINJECT_DEVICE_FAULT,
450eda14cbcSMatt Macy 	ZINJECT_LABEL_FAULT,
451eda14cbcSMatt Macy 	ZINJECT_IGNORED_WRITES,
452eda14cbcSMatt Macy 	ZINJECT_PANIC,
453eda14cbcSMatt Macy 	ZINJECT_DELAY_IO,
454eda14cbcSMatt Macy 	ZINJECT_DECRYPT_FAULT,
4550d4ad640SMartin Matuska 	ZINJECT_DELAY_IMPORT,
4560d4ad640SMartin Matuska 	ZINJECT_DELAY_EXPORT,
457eda14cbcSMatt Macy } zinject_type_t;
458eda14cbcSMatt Macy 
459*c6767dc1SMartin Matuska typedef enum zinject_iotype {
460*c6767dc1SMartin Matuska 	/*
461*c6767dc1SMartin Matuska 	 * Compatibility: zi_iotype used to be set to ZIO_TYPE_, so make sure
462*c6767dc1SMartin Matuska 	 * the corresponding ZINJECT_IOTYPE_ matches. Note that existing here
463*c6767dc1SMartin Matuska 	 * does not mean that injections are possible for all these types.
464*c6767dc1SMartin Matuska 	 */
465*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_NULL	= ZIO_TYPE_NULL,
466*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_READ	= ZIO_TYPE_READ,
467*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_WRITE	= ZIO_TYPE_WRITE,
468*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_FREE	= ZIO_TYPE_FREE,
469*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_CLAIM	= ZIO_TYPE_CLAIM,
470*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_FLUSH	= ZIO_TYPE_FLUSH,
471*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_TRIM	= ZIO_TYPE_TRIM,
472*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_ALL	= ZIO_TYPES,
473*c6767dc1SMartin Matuska 	/* Room for future expansion for ZIO_TYPE_* */
474*c6767dc1SMartin Matuska 	ZINJECT_IOTYPE_PROBE	= 16,
475*c6767dc1SMartin Matuska 	ZINJECT_IOTYPES,
476*c6767dc1SMartin Matuska } zinject_iotype_t;
477*c6767dc1SMartin Matuska 
478eda14cbcSMatt Macy typedef struct zfs_share {
479eda14cbcSMatt Macy 	uint64_t	z_exportdata;
480eda14cbcSMatt Macy 	uint64_t	z_sharedata;
481eda14cbcSMatt Macy 	uint64_t	z_sharetype;	/* 0 = share, 1 = unshare */
482eda14cbcSMatt Macy 	uint64_t	z_sharemax;  /* max length of share string */
483eda14cbcSMatt Macy } zfs_share_t;
484eda14cbcSMatt Macy 
485eda14cbcSMatt Macy /*
486eda14cbcSMatt Macy  * ZFS file systems may behave the usual, POSIX-compliant way, where
487eda14cbcSMatt Macy  * name lookups are case-sensitive.  They may also be set up so that
488eda14cbcSMatt Macy  * all the name lookups are case-insensitive, or so that only some
489eda14cbcSMatt Macy  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
490eda14cbcSMatt Macy  */
491eda14cbcSMatt Macy typedef enum zfs_case {
492eda14cbcSMatt Macy 	ZFS_CASE_SENSITIVE,
493eda14cbcSMatt Macy 	ZFS_CASE_INSENSITIVE,
494eda14cbcSMatt Macy 	ZFS_CASE_MIXED
495eda14cbcSMatt Macy } zfs_case_t;
496eda14cbcSMatt Macy 
497eda14cbcSMatt Macy /*
4987a7741afSMartin Matuska  * zfs ioctl command structure
4997a7741afSMartin Matuska  */
5007a7741afSMartin Matuska 
5017a7741afSMartin Matuska /*
502eda14cbcSMatt Macy  * Note: this struct must have the same layout in 32-bit and 64-bit, so
503eda14cbcSMatt Macy  * that 32-bit processes (like /sbin/zfs) can pass it to the 64-bit
504eda14cbcSMatt Macy  * kernel.  Therefore, we add padding to it so that no "hidden" padding
505eda14cbcSMatt Macy  * is automatically added on 64-bit (but not on 32-bit).
506eda14cbcSMatt Macy  */
507eda14cbcSMatt Macy typedef struct zfs_cmd {
508eda14cbcSMatt Macy 	char		zc_name[MAXPATHLEN];	/* name of pool or dataset */
509eda14cbcSMatt Macy 	uint64_t	zc_nvlist_src;		/* really (char *) */
510eda14cbcSMatt Macy 	uint64_t	zc_nvlist_src_size;
511eda14cbcSMatt Macy 	uint64_t	zc_nvlist_dst;		/* really (char *) */
512eda14cbcSMatt Macy 	uint64_t	zc_nvlist_dst_size;
513eda14cbcSMatt Macy 	boolean_t	zc_nvlist_dst_filled;	/* put an nvlist in dst? */
514eda14cbcSMatt Macy 	int		zc_pad2;
515eda14cbcSMatt Macy 
516eda14cbcSMatt Macy 	/*
517eda14cbcSMatt Macy 	 * The following members are for legacy ioctls which haven't been
518eda14cbcSMatt Macy 	 * converted to the new method.
519eda14cbcSMatt Macy 	 */
520eda14cbcSMatt Macy 	uint64_t	zc_history;		/* really (char *) */
521eda14cbcSMatt Macy 	char		zc_value[MAXPATHLEN * 2];
522eda14cbcSMatt Macy 	char		zc_string[MAXNAMELEN];
523eda14cbcSMatt Macy 	uint64_t	zc_guid;
524eda14cbcSMatt Macy 	uint64_t	zc_nvlist_conf;		/* really (char *) */
525eda14cbcSMatt Macy 	uint64_t	zc_nvlist_conf_size;
526eda14cbcSMatt Macy 	uint64_t	zc_cookie;
527eda14cbcSMatt Macy 	uint64_t	zc_objset_type;
528eda14cbcSMatt Macy 	uint64_t	zc_perm_action;
529eda14cbcSMatt Macy 	uint64_t	zc_history_len;
530eda14cbcSMatt Macy 	uint64_t	zc_history_offset;
531eda14cbcSMatt Macy 	uint64_t	zc_obj;
532eda14cbcSMatt Macy 	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
533eda14cbcSMatt Macy 	zfs_share_t	zc_share;
534eda14cbcSMatt Macy 	dmu_objset_stats_t zc_objset_stats;
535eda14cbcSMatt Macy 	struct drr_begin zc_begin_record;
536eda14cbcSMatt Macy 	zinject_record_t zc_inject_record;
537eda14cbcSMatt Macy 	uint32_t	zc_defer_destroy;
538eda14cbcSMatt Macy 	uint32_t	zc_flags;
539eda14cbcSMatt Macy 	uint64_t	zc_action_handle;
540eda14cbcSMatt Macy 	int		zc_cleanup_fd;
541eda14cbcSMatt Macy 	uint8_t		zc_simple;
542eda14cbcSMatt Macy 	uint8_t		zc_pad[3];		/* alignment */
543eda14cbcSMatt Macy 	uint64_t	zc_sendobj;
544eda14cbcSMatt Macy 	uint64_t	zc_fromobj;
545eda14cbcSMatt Macy 	uint64_t	zc_createtxg;
546eda14cbcSMatt Macy 	zfs_stat_t	zc_stat;
547eda14cbcSMatt Macy 	uint64_t	zc_zoneid;
548eda14cbcSMatt Macy } zfs_cmd_t;
549eda14cbcSMatt Macy 
550eda14cbcSMatt Macy typedef struct zfs_useracct {
551eda14cbcSMatt Macy 	char zu_domain[256];
552eda14cbcSMatt Macy 	uid_t zu_rid;
553eda14cbcSMatt Macy 	uint32_t zu_pad;
554eda14cbcSMatt Macy 	uint64_t zu_space;
555eda14cbcSMatt Macy } zfs_useracct_t;
556eda14cbcSMatt Macy 
557eda14cbcSMatt Macy #define	ZFSDEV_MAX_MINOR	(1 << 16)
558eda14cbcSMatt Macy 
559eda14cbcSMatt Macy #define	ZPOOL_EXPORT_AFTER_SPLIT 0x1
560eda14cbcSMatt Macy 
561eda14cbcSMatt Macy #ifdef _KERNEL
562eda14cbcSMatt Macy struct objset;
563eda14cbcSMatt Macy struct zfsvfs;
564eda14cbcSMatt Macy 
565eda14cbcSMatt Macy typedef struct zfs_creat {
566eda14cbcSMatt Macy 	nvlist_t	*zct_zplprops;
567eda14cbcSMatt Macy 	nvlist_t	*zct_props;
568eda14cbcSMatt Macy } zfs_creat_t;
569eda14cbcSMatt Macy 
570eda14cbcSMatt Macy extern int zfs_secpolicy_snapshot_perms(const char *, cred_t *);
571eda14cbcSMatt Macy extern int zfs_secpolicy_rename_perms(const char *, const char *, cred_t *);
572eda14cbcSMatt Macy extern int zfs_secpolicy_destroy_perms(const char *, cred_t *);
573eda14cbcSMatt Macy extern void zfs_unmount_snap(const char *);
574eda14cbcSMatt Macy extern void zfs_destroy_unmount_origin(const char *);
575eda14cbcSMatt Macy extern int getzfsvfs_impl(struct objset *, struct zfsvfs **);
576eda14cbcSMatt Macy extern int getzfsvfs(const char *, struct zfsvfs **);
577eda14cbcSMatt Macy 
578eda14cbcSMatt Macy enum zfsdev_state_type {
579eda14cbcSMatt Macy 	ZST_ONEXIT,
580eda14cbcSMatt Macy 	ZST_ZEVENT,
581eda14cbcSMatt Macy 	ZST_ALL,
582eda14cbcSMatt Macy };
583eda14cbcSMatt Macy 
584eda14cbcSMatt Macy /*
585eda14cbcSMatt Macy  * The zfsdev_state_t structure is managed as a singly-linked list
586eda14cbcSMatt Macy  * from which items are never deleted.  This allows for lock-free
587eda14cbcSMatt Macy  * reading of the list so long as assignments to the zs_next and
588eda14cbcSMatt Macy  * reads from zs_minor are performed atomically.  Empty items are
589eda14cbcSMatt Macy  * indicated by storing -1 into zs_minor.
590eda14cbcSMatt Macy  */
591eda14cbcSMatt Macy typedef struct zfsdev_state {
592eda14cbcSMatt Macy 	struct zfsdev_state	*zs_next;	/* next zfsdev_state_t link */
593eda14cbcSMatt Macy 	minor_t			zs_minor;	/* made up minor number */
594eda14cbcSMatt Macy 	void			*zs_onexit;	/* onexit data */
595eda14cbcSMatt Macy 	void			*zs_zevent;	/* zevent data */
596eda14cbcSMatt Macy } zfsdev_state_t;
597eda14cbcSMatt Macy 
598eda14cbcSMatt Macy extern void *zfsdev_get_state(minor_t minor, enum zfsdev_state_type which);
5995eb61f6cSMartin Matuska extern int zfsdev_getminor(zfs_file_t *fp, minor_t *minorp);
600eda14cbcSMatt Macy 
601eda14cbcSMatt Macy extern uint_t zfs_allow_log_key;
602eda14cbcSMatt Macy 
603eda14cbcSMatt Macy #endif	/* _KERNEL */
604eda14cbcSMatt Macy 
605eda14cbcSMatt Macy #ifdef	__cplusplus
606eda14cbcSMatt Macy }
607eda14cbcSMatt Macy #endif
608eda14cbcSMatt Macy 
609eda14cbcSMatt Macy #endif	/* _SYS_ZFS_IOCTL_H */
610