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