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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24 * Copyright 2016 RackTop Systems.
25 * Copyright (c) 2017, Intel Corporation.
28 #ifndef _SYS_ZFS_IOCTL_H
29 #define _SYS_ZFS_IOCTL_H
34 #include <sys/dsl_deleg.h>
36 #include <sys/zfs_stat.h>
39 #include <sys/nvpair.h>
47 * The structures in this file are passed between userland and the
48 * kernel. Userland may be running a 32-bit process, while the kernel
49 * is 64-bit. Therefore, these structures need to compile the same in
50 * 32-bit and 64-bit. This means not using type "long", and adding
51 * explicit padding so that the 32-bit structure will not be packed more
52 * tightly than the 64-bit structure (which requires 64-bit alignment).
56 * Property values for snapdir
58 #define ZFS_SNAPDIR_HIDDEN 0
59 #define ZFS_SNAPDIR_VISIBLE 1
62 * Property values for snapdev
64 #define ZFS_SNAPDEV_HIDDEN 0
65 #define ZFS_SNAPDEV_VISIBLE 1
67 * Property values for acltype
69 #define ZFS_ACLTYPE_OFF 0
70 #define ZFS_ACLTYPE_POSIXACL 1
73 * Field manipulation macros for the drr_versioninfo field of the
78 * Header types for zfs send streams.
80 typedef enum drr_headertype {
82 DMU_COMPOUNDSTREAM = 0x2
85 #define DMU_GET_STREAM_HDRTYPE(vi) BF64_GET((vi), 0, 2)
86 #define DMU_SET_STREAM_HDRTYPE(vi, x) BF64_SET((vi), 0, 2, x)
88 #define DMU_GET_FEATUREFLAGS(vi) BF64_GET((vi), 2, 30)
89 #define DMU_SET_FEATUREFLAGS(vi, x) BF64_SET((vi), 2, 30, x)
92 * Feature flags for zfs send streams (flags in drr_versioninfo)
95 #define DMU_BACKUP_FEATURE_DEDUP (1 << 0)
96 #define DMU_BACKUP_FEATURE_DEDUPPROPS (1 << 1)
97 #define DMU_BACKUP_FEATURE_SA_SPILL (1 << 2)
98 /* flags #3 - #15 are reserved for incompatible closed-source implementations */
99 #define DMU_BACKUP_FEATURE_EMBED_DATA (1 << 16)
100 #define DMU_BACKUP_FEATURE_LZ4 (1 << 17)
101 /* flag #18 is reserved for a Delphix feature */
102 #define DMU_BACKUP_FEATURE_LARGE_BLOCKS (1 << 19)
103 #define DMU_BACKUP_FEATURE_RESUMING (1 << 20)
104 /* flag #21 is reserved for a Delphix feature */
105 #define DMU_BACKUP_FEATURE_COMPRESSED (1 << 22)
106 #define DMU_BACKUP_FEATURE_LARGE_DNODE (1 << 23)
109 * Mask of all supported backup features
111 #define DMU_BACKUP_FEATURE_MASK (DMU_BACKUP_FEATURE_DEDUP | \
112 DMU_BACKUP_FEATURE_DEDUPPROPS | DMU_BACKUP_FEATURE_SA_SPILL | \
113 DMU_BACKUP_FEATURE_EMBED_DATA | DMU_BACKUP_FEATURE_LZ4 | \
114 DMU_BACKUP_FEATURE_RESUMING | DMU_BACKUP_FEATURE_LARGE_BLOCKS | \
115 DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_LARGE_DNODE)
117 /* Are all features in the given flag word currently supported? */
118 #define DMU_STREAM_SUPPORTED(x) (!((x) & ~DMU_BACKUP_FEATURE_MASK))
120 typedef enum dmu_send_resume_token_version {
121 ZFS_SEND_RESUME_TOKEN_VERSION = 1
122 } dmu_send_resume_token_version_t;
125 * The drr_versioninfo field of the dmu_replay_record has the
128 * 64 56 48 40 32 24 16 8 0
129 * +-------+-------+-------+-------+-------+-------+-------+-------+
130 * | reserved | feature-flags |C|S|
131 * +-------+-------+-------+-------+-------+-------+-------+-------+
133 * The low order two bits indicate the header type: SUBSTREAM (0x1)
134 * or COMPOUNDSTREAM (0x2). Using two bits for this is historical:
135 * this field used to be a version number, where the two version types
136 * were 1 and 2. Using two bits for this allows earlier versions of
137 * the code to be able to recognize send streams that don't use any
138 * of the features indicated by feature flags.
141 #define DMU_BACKUP_MAGIC 0x2F5bacbacULL
144 * Send stream flags. Bits 24-31 are reserved for vendor-specific
145 * implementations and should not be used.
147 #define DRR_FLAG_CLONE (1<<0)
148 #define DRR_FLAG_CI_DATA (1<<1)
150 * This send stream, if it is a full send, includes the FREE and FREEOBJECT
151 * records that are created by the sending process. This means that the send
152 * stream can be received as a clone, even though it is not an incremental.
153 * This is not implemented as a feature flag, because the receiving side does
154 * not need to have implemented it to receive this stream; it is fully backwards
155 * compatible. We need a flag, though, because full send streams without it
156 * cannot necessarily be received as a clone correctly.
158 #define DRR_FLAG_FREERECORDS (1<<2)
161 * flags in the drr_checksumflags field in the DRR_WRITE and
162 * DRR_WRITE_BYREF blocks
164 #define DRR_CHECKSUM_DEDUP (1<<0)
166 #define DRR_IS_DEDUP_CAPABLE(flags) ((flags) & DRR_CHECKSUM_DEDUP)
168 /* deal with compressed drr_write replay records */
169 #define DRR_WRITE_COMPRESSED(drrw) ((drrw)->drr_compressiontype != 0)
170 #define DRR_WRITE_PAYLOAD_SIZE(drrw) \
171 (DRR_WRITE_COMPRESSED(drrw) ? (drrw)->drr_compressed_size : \
172 (drrw)->drr_logical_size)
175 * zfs ioctl command structure
177 typedef struct dmu_replay_record {
179 DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
180 DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
181 DRR_SPILL, DRR_WRITE_EMBEDDED, DRR_NUMTYPES
183 uint32_t drr_payloadlen;
187 uint64_t drr_versioninfo; /* was drr_version */
188 uint64_t drr_creation_time;
189 dmu_objset_type_t drr_type;
192 uint64_t drr_fromguid;
193 char drr_toname[MAXNAMELEN];
196 zio_cksum_t drr_checksum;
201 dmu_object_type_t drr_type;
202 dmu_object_type_t drr_bonustype;
204 uint32_t drr_bonuslen;
205 uint8_t drr_checksumtype;
206 uint8_t drr_compress;
207 uint8_t drr_dn_slots;
210 /* bonus content follows */
212 struct drr_freeobjects {
213 uint64_t drr_firstobj;
214 uint64_t drr_numobjs;
219 dmu_object_type_t drr_type;
222 uint64_t drr_logical_size;
224 uint8_t drr_checksumtype;
225 uint8_t drr_checksumflags;
226 uint8_t drr_compressiontype;
228 /* deduplication key */
230 /* only nonzero if drr_compressiontype is not 0 */
231 uint64_t drr_compressed_size;
232 /* content follows */
240 struct drr_write_byref {
241 /* where to put the data */
246 /* where to find the prior copy of the data */
247 uint64_t drr_refguid;
248 uint64_t drr_refobject;
249 uint64_t drr_refoffset;
250 /* properties of the data */
251 uint8_t drr_checksumtype;
252 uint8_t drr_checksumflags;
254 ddt_key_t drr_key; /* deduplication key */
260 uint64_t drr_pad[4]; /* needed for crypto */
261 /* spill data follows */
263 struct drr_write_embedded {
266 /* logical length, should equal blocksize */
269 uint8_t drr_compression;
272 uint32_t drr_lsize; /* uncompressed size of payload */
273 uint32_t drr_psize; /* compr. (real) size of payload */
274 /* (possibly compressed) content follows */
275 } drr_write_embedded;
278 * Nore: drr_checksum is overlaid with all record types
279 * except DRR_BEGIN. Therefore its (non-pad) members
280 * must not overlap with members from the other structs.
281 * We accomplish this by putting its members at the very
284 struct drr_checksum {
285 uint64_t drr_pad[34];
287 * fletcher-4 checksum of everything preceding the
290 zio_cksum_t drr_checksum;
293 } dmu_replay_record_t;
295 /* diff record range types */
296 typedef enum diff_type {
303 * The diff reports back ranges of free or in-use objects.
305 typedef struct dmu_diff_record {
311 typedef struct zinject_record {
321 uint32_t zi_failfast;
322 char zi_func[MAXNAMELEN];
331 #define ZINJECT_NULL 0x1
332 #define ZINJECT_FLUSH_ARC 0x2
333 #define ZINJECT_UNLOAD_SPA 0x4
335 #define ZEVENT_NONE 0x0
336 #define ZEVENT_NONBLOCK 0x1
337 #define ZEVENT_SIZE 1024
339 #define ZEVENT_SEEK_START 0
340 #define ZEVENT_SEEK_END UINT64_MAX
342 /* scaled frequency ranges */
343 #define ZI_PERCENTAGE_MIN 4294UL
344 #define ZI_PERCENTAGE_MAX UINT32_MAX
346 typedef enum zinject_type {
347 ZINJECT_UNINITIALIZED,
349 ZINJECT_DEVICE_FAULT,
351 ZINJECT_IGNORED_WRITES,
356 typedef struct zfs_share {
357 uint64_t z_exportdata;
358 uint64_t z_sharedata;
359 uint64_t z_sharetype; /* 0 = share, 1 = unshare */
360 uint64_t z_sharemax; /* max length of share string */
364 * ZFS file systems may behave the usual, POSIX-compliant way, where
365 * name lookups are case-sensitive. They may also be set up so that
366 * all the name lookups are case-insensitive, or so that only some
367 * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
369 typedef enum zfs_case {
371 ZFS_CASE_INSENSITIVE,
376 * Note: this struct must have the same layout in 32-bit and 64-bit, so
377 * that 32-bit processes (like /sbin/zfs) can pass it to the 64-bit
378 * kernel. Therefore, we add padding to it so that no "hidden" padding
379 * is automatically added on 64-bit (but not on 32-bit).
381 typedef struct zfs_cmd {
382 char zc_name[MAXPATHLEN]; /* name of pool or dataset */
383 uint64_t zc_nvlist_src; /* really (char *) */
384 uint64_t zc_nvlist_src_size;
385 uint64_t zc_nvlist_dst; /* really (char *) */
386 uint64_t zc_nvlist_dst_size;
387 boolean_t zc_nvlist_dst_filled; /* put an nvlist in dst? */
391 * The following members are for legacy ioctls which haven't been
392 * converted to the new method.
394 uint64_t zc_history; /* really (char *) */
395 char zc_value[MAXPATHLEN * 2];
396 char zc_string[MAXNAMELEN];
398 uint64_t zc_nvlist_conf; /* really (char *) */
399 uint64_t zc_nvlist_conf_size;
401 uint64_t zc_objset_type;
402 uint64_t zc_perm_action;
403 uint64_t zc_history_len;
404 uint64_t zc_history_offset;
406 uint64_t zc_iflags; /* internal to zfs(7fs) */
407 zfs_share_t zc_share;
408 dmu_objset_stats_t zc_objset_stats;
409 struct drr_begin zc_begin_record;
410 zinject_record_t zc_inject_record;
411 uint32_t zc_defer_destroy;
413 uint64_t zc_action_handle;
416 uint8_t zc_pad[3]; /* alignment */
419 uint64_t zc_createtxg;
423 typedef struct zfs_useracct {
430 #define ZFSDEV_MAX_MINOR (1 << 16)
431 #define ZFS_MIN_MINOR (ZFSDEV_MAX_MINOR + 1)
433 #define ZPOOL_EXPORT_AFTER_SPLIT 0x1
437 typedef struct zfs_creat {
438 nvlist_t *zct_zplprops;
442 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
443 extern int zfs_secpolicy_rename_perms(const char *from,
444 const char *to, cred_t *cr);
445 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
446 extern int zfs_unmount_snap(const char *);
447 extern void zfs_destroy_unmount_origin(const char *);
449 extern boolean_t dataset_name_hidden(const char *name);
451 enum zfsdev_state_type {
458 * The zfsdev_state_t structure is managed as a singly-linked list
459 * from which items are never deleted. This allows for lock-free
460 * reading of the list so long as assignments to the zs_next and
461 * reads from zs_minor are performed atomically. Empty items are
462 * indicated by storing -1 into zs_minor.
464 typedef struct zfsdev_state {
465 struct zfsdev_state *zs_next; /* next zfsdev_state_t link */
466 struct file *zs_file; /* associated file struct */
467 minor_t zs_minor; /* made up minor number */
468 void *zs_onexit; /* onexit data */
469 void *zs_zevent; /* zevent data */
472 extern void *zfsdev_get_state(minor_t minor, enum zfsdev_state_type which);
473 extern int zfsdev_getminor(struct file *filp, minor_t *minorp);
474 extern minor_t zfsdev_minor_alloc(void);
482 #endif /* _SYS_ZFS_IOCTL_H */