xref: /freebsd/sys/contrib/openzfs/module/zcommon/zfs_prop.c (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
24  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25  * Copyright 2016, Joyent, Inc.
26  * Copyright (c) 2019, Klara Inc.
27  * Copyright (c) 2019, Allan Jude
28  */
29 
30 /* Portions Copyright 2010 Robert Milkowski */
31 
32 #include <sys/zio.h>
33 #include <sys/spa.h>
34 #include <sys/u8_textprep.h>
35 #include <sys/zfs_acl.h>
36 #include <sys/zfs_ioctl.h>
37 #include <sys/zfs_znode.h>
38 #include <sys/dsl_crypt.h>
39 
40 #include "zfs_prop.h"
41 #include "zfs_deleg.h"
42 #include "zfs_fletcher.h"
43 
44 #if !defined(_KERNEL)
45 #include <stdlib.h>
46 #include <string.h>
47 #include <ctype.h>
48 #endif
49 
50 static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
51 
52 /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
53 const char *const zfs_userquota_prop_prefixes[] = {
54 	"userused@",
55 	"userquota@",
56 	"groupused@",
57 	"groupquota@",
58 	"userobjused@",
59 	"userobjquota@",
60 	"groupobjused@",
61 	"groupobjquota@",
62 	"projectused@",
63 	"projectquota@",
64 	"projectobjused@",
65 	"projectobjquota@"
66 };
67 
68 zprop_desc_t *
69 zfs_prop_get_table(void)
70 {
71 	return (zfs_prop_table);
72 }
73 
74 void
75 zfs_prop_init(void)
76 {
77 	static const zprop_index_t checksum_table[] = {
78 		{ "on",		ZIO_CHECKSUM_ON },
79 		{ "off",	ZIO_CHECKSUM_OFF },
80 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
81 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
82 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
83 		{ "noparity",   ZIO_CHECKSUM_NOPARITY },
84 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
85 		{ "skein",	ZIO_CHECKSUM_SKEIN },
86 		{ "edonr",	ZIO_CHECKSUM_EDONR },
87 		{ NULL }
88 	};
89 
90 	static const zprop_index_t dedup_table[] = {
91 		{ "on",		ZIO_CHECKSUM_ON },
92 		{ "off",	ZIO_CHECKSUM_OFF },
93 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
94 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
95 		{ "sha256,verify",
96 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
97 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
98 		{ "sha512,verify",
99 				ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
100 		{ "skein",	ZIO_CHECKSUM_SKEIN },
101 		{ "skein,verify",
102 				ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
103 		{ "edonr,verify",
104 				ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
105 		{ NULL }
106 	};
107 
108 	static const zprop_index_t compress_table[] = {
109 		{ "on",		ZIO_COMPRESS_ON },
110 		{ "off",	ZIO_COMPRESS_OFF },
111 		{ "lzjb",	ZIO_COMPRESS_LZJB },
112 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
113 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
114 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
115 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
116 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
117 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
118 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
119 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
120 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
121 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
122 		{ "zle",	ZIO_COMPRESS_ZLE },
123 		{ "lz4",	ZIO_COMPRESS_LZ4 },
124 		{ "zstd",	ZIO_COMPRESS_ZSTD },
125 		{ "zstd-fast",
126 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_DEFAULT) },
127 
128 		/*
129 		 * ZSTD 1-19 are synthetic. We store the compression level in a
130 		 * separate hidden property to avoid wasting a large amount of
131 		 * space in the ZIO_COMPRESS enum.
132 		 *
133 		 * The compression level is also stored within the header of the
134 		 * compressed block since we may need it for later recompression
135 		 * to avoid checksum errors (L2ARC).
136 		 *
137 		 * Note that the level here is defined as bit shifted mask on
138 		 * top of the method.
139 		 */
140 		{ "zstd-1",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_1) },
141 		{ "zstd-2",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_2) },
142 		{ "zstd-3",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_3) },
143 		{ "zstd-4",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_4) },
144 		{ "zstd-5",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_5) },
145 		{ "zstd-6",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_6) },
146 		{ "zstd-7",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_7) },
147 		{ "zstd-8",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_8) },
148 		{ "zstd-9",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_9) },
149 		{ "zstd-10",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_10) },
150 		{ "zstd-11",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_11) },
151 		{ "zstd-12",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_12) },
152 		{ "zstd-13",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_13) },
153 		{ "zstd-14",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_14) },
154 		{ "zstd-15",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_15) },
155 		{ "zstd-16",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_16) },
156 		{ "zstd-17",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_17) },
157 		{ "zstd-18",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_18) },
158 		{ "zstd-19",	ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_19) },
159 
160 		/*
161 		 * The ZSTD-Fast levels are also synthetic.
162 		 */
163 		{ "zstd-fast-1",
164 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_1) },
165 		{ "zstd-fast-2",
166 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_2) },
167 		{ "zstd-fast-3",
168 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_3) },
169 		{ "zstd-fast-4",
170 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_4) },
171 		{ "zstd-fast-5",
172 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_5) },
173 		{ "zstd-fast-6",
174 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_6) },
175 		{ "zstd-fast-7",
176 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_7) },
177 		{ "zstd-fast-8",
178 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_8) },
179 		{ "zstd-fast-9",
180 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_9) },
181 		{ "zstd-fast-10",
182 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_10) },
183 		{ "zstd-fast-20",
184 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_20) },
185 		{ "zstd-fast-30",
186 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_30) },
187 		{ "zstd-fast-40",
188 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_40) },
189 		{ "zstd-fast-50",
190 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_50) },
191 		{ "zstd-fast-60",
192 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_60) },
193 		{ "zstd-fast-70",
194 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_70) },
195 		{ "zstd-fast-80",
196 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_80) },
197 		{ "zstd-fast-90",
198 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_90) },
199 		{ "zstd-fast-100",
200 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_100) },
201 		{ "zstd-fast-500",
202 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_500) },
203 		{ "zstd-fast-1000",
204 		    ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_1000) },
205 		{ NULL }
206 	};
207 
208 	static const zprop_index_t crypto_table[] = {
209 		{ "on",			ZIO_CRYPT_ON },
210 		{ "off",		ZIO_CRYPT_OFF },
211 		{ "aes-128-ccm",	ZIO_CRYPT_AES_128_CCM },
212 		{ "aes-192-ccm",	ZIO_CRYPT_AES_192_CCM },
213 		{ "aes-256-ccm",	ZIO_CRYPT_AES_256_CCM },
214 		{ "aes-128-gcm",	ZIO_CRYPT_AES_128_GCM },
215 		{ "aes-192-gcm",	ZIO_CRYPT_AES_192_GCM },
216 		{ "aes-256-gcm",	ZIO_CRYPT_AES_256_GCM },
217 		{ NULL }
218 	};
219 
220 	static const zprop_index_t keyformat_table[] = {
221 		{ "none",		ZFS_KEYFORMAT_NONE },
222 		{ "raw",		ZFS_KEYFORMAT_RAW },
223 		{ "hex",		ZFS_KEYFORMAT_HEX },
224 		{ "passphrase",		ZFS_KEYFORMAT_PASSPHRASE },
225 		{ NULL }
226 	};
227 
228 	static const zprop_index_t snapdir_table[] = {
229 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
230 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
231 		{ NULL }
232 	};
233 
234 	static const zprop_index_t snapdev_table[] = {
235 		{ "hidden",	ZFS_SNAPDEV_HIDDEN },
236 		{ "visible",	ZFS_SNAPDEV_VISIBLE },
237 		{ NULL }
238 	};
239 
240 	static const zprop_index_t acl_mode_table[] = {
241 		{ "discard",	ZFS_ACL_DISCARD },
242 		{ "groupmask",	ZFS_ACL_GROUPMASK },
243 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
244 		{ "restricted",	ZFS_ACL_RESTRICTED },
245 		{ NULL }
246 	};
247 
248 	static const zprop_index_t acltype_table[] = {
249 		{ "off",	ZFS_ACLTYPE_OFF },
250 		{ "posix",	ZFS_ACLTYPE_POSIX },
251 		{ "nfsv4",	ZFS_ACLTYPE_NFSV4 },
252 		{ "disabled",	ZFS_ACLTYPE_OFF }, /* bkwrd compatibility */
253 		{ "noacl",	ZFS_ACLTYPE_OFF }, /* bkwrd compatibility */
254 		{ "posixacl",	ZFS_ACLTYPE_POSIX }, /* bkwrd compatibility */
255 		{ NULL }
256 	};
257 
258 	static const zprop_index_t acl_inherit_table[] = {
259 		{ "discard",	ZFS_ACL_DISCARD },
260 		{ "noallow",	ZFS_ACL_NOALLOW },
261 		{ "restricted",	ZFS_ACL_RESTRICTED },
262 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
263 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatibility */
264 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
265 		{ NULL }
266 	};
267 
268 	static const zprop_index_t case_table[] = {
269 		{ "sensitive",		ZFS_CASE_SENSITIVE },
270 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
271 		{ "mixed",		ZFS_CASE_MIXED },
272 		{ NULL }
273 	};
274 
275 	static const zprop_index_t copies_table[] = {
276 		{ "1",		1 },
277 		{ "2",		2 },
278 		{ "3",		3 },
279 		{ NULL }
280 	};
281 
282 	/*
283 	 * Use the unique flags we have to send to u8_strcmp() and/or
284 	 * u8_textprep() to represent the various normalization property
285 	 * values.
286 	 */
287 	static const zprop_index_t normalize_table[] = {
288 		{ "none",	0 },
289 		{ "formD",	U8_TEXTPREP_NFD },
290 		{ "formKC",	U8_TEXTPREP_NFKC },
291 		{ "formC",	U8_TEXTPREP_NFC },
292 		{ "formKD",	U8_TEXTPREP_NFKD },
293 		{ NULL }
294 	};
295 
296 	static const zprop_index_t version_table[] = {
297 		{ "1",		1 },
298 		{ "2",		2 },
299 		{ "3",		3 },
300 		{ "4",		4 },
301 		{ "5",		5 },
302 		{ "current",	ZPL_VERSION },
303 		{ NULL }
304 	};
305 
306 	static const zprop_index_t boolean_table[] = {
307 		{ "off",	0 },
308 		{ "on",		1 },
309 		{ NULL }
310 	};
311 
312 	static const zprop_index_t keystatus_table[] = {
313 		{ "none",		ZFS_KEYSTATUS_NONE},
314 		{ "unavailable",	ZFS_KEYSTATUS_UNAVAILABLE},
315 		{ "available",		ZFS_KEYSTATUS_AVAILABLE},
316 		{ NULL }
317 	};
318 
319 	static const zprop_index_t logbias_table[] = {
320 		{ "latency",	ZFS_LOGBIAS_LATENCY },
321 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
322 		{ NULL }
323 	};
324 
325 	static const zprop_index_t canmount_table[] = {
326 		{ "off",	ZFS_CANMOUNT_OFF },
327 		{ "on",		ZFS_CANMOUNT_ON },
328 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
329 		{ NULL }
330 	};
331 
332 	static const zprop_index_t cache_table[] = {
333 		{ "none",	ZFS_CACHE_NONE },
334 		{ "metadata",	ZFS_CACHE_METADATA },
335 		{ "all",	ZFS_CACHE_ALL },
336 		{ NULL }
337 	};
338 
339 	static const zprop_index_t sync_table[] = {
340 		{ "standard",	ZFS_SYNC_STANDARD },
341 		{ "always",	ZFS_SYNC_ALWAYS },
342 		{ "disabled",	ZFS_SYNC_DISABLED },
343 		{ NULL }
344 	};
345 
346 	static const zprop_index_t xattr_table[] = {
347 		{ "off",	ZFS_XATTR_OFF },
348 		{ "on",		ZFS_XATTR_DIR },
349 		{ "sa",		ZFS_XATTR_SA },
350 		{ "dir",	ZFS_XATTR_DIR },
351 		{ NULL }
352 	};
353 
354 	static const zprop_index_t dnsize_table[] = {
355 		{ "legacy",	ZFS_DNSIZE_LEGACY },
356 		{ "auto",	ZFS_DNSIZE_AUTO },
357 		{ "1k",		ZFS_DNSIZE_1K },
358 		{ "2k",		ZFS_DNSIZE_2K },
359 		{ "4k",		ZFS_DNSIZE_4K },
360 		{ "8k",		ZFS_DNSIZE_8K },
361 		{ "16k",	ZFS_DNSIZE_16K },
362 		{ NULL }
363 	};
364 
365 	static const zprop_index_t redundant_metadata_table[] = {
366 		{ "all",	ZFS_REDUNDANT_METADATA_ALL },
367 		{ "most",	ZFS_REDUNDANT_METADATA_MOST },
368 		{ NULL }
369 	};
370 
371 	static const zprop_index_t volmode_table[] = {
372 		{ "default",	ZFS_VOLMODE_DEFAULT },
373 		{ "full",	ZFS_VOLMODE_GEOM },
374 		{ "geom",	ZFS_VOLMODE_GEOM },
375 		{ "dev",	ZFS_VOLMODE_DEV },
376 		{ "none",	ZFS_VOLMODE_NONE },
377 		{ NULL }
378 	};
379 
380 	struct zfs_mod_supported_features *sfeatures =
381 	    zfs_mod_list_supported(ZFS_SYSFS_DATASET_PROPERTIES);
382 
383 	/* inherit index properties */
384 	zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
385 	    ZFS_REDUNDANT_METADATA_ALL,
386 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
387 	    "all | most", "REDUND_MD",
388 	    redundant_metadata_table, sfeatures);
389 	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
390 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
391 	    "standard | always | disabled", "SYNC",
392 	    sync_table, sfeatures);
393 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
394 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
395 	    ZFS_TYPE_VOLUME,
396 	    "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein"
397 	    " | edonr",
398 	    "CHECKSUM", checksum_table, sfeatures);
399 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
400 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
401 	    "on | off | verify | sha256[,verify] | sha512[,verify] | "
402 	    "skein[,verify] | edonr,verify",
403 	    "DEDUP", dedup_table, sfeatures);
404 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
405 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
406 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
407 	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4 | "
408 	    "zstd | zstd-[1-19] | "
409 	    "zstd-fast | zstd-fast-[1-10,20,30,40,50,60,70,80,90,100,500,1000]",
410 	    "COMPRESS", compress_table, sfeatures);
411 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
412 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
413 	    "hidden | visible", "SNAPDIR", snapdir_table, sfeatures);
414 	zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN,
415 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
416 	    "hidden | visible", "SNAPDEV", snapdev_table, sfeatures);
417 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
418 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
419 	    "discard | groupmask | passthrough | restricted", "ACLMODE",
420 	    acl_mode_table, sfeatures);
421 	zprop_register_index(ZFS_PROP_ACLTYPE, "acltype",
422 #ifdef __linux__
423 	    /* Linux doesn't natively support ZFS's NFSv4-style ACLs. */
424 	    ZFS_ACLTYPE_OFF,
425 #else
426 	    ZFS_ACLTYPE_NFSV4,
427 #endif
428 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
429 	    "off | nfsv4 | posix", "ACLTYPE", acltype_table, sfeatures);
430 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
431 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
432 	    "discard | noallow | restricted | passthrough | passthrough-x",
433 	    "ACLINHERIT", acl_inherit_table, sfeatures);
434 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
435 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
436 	    "1 | 2 | 3", "COPIES", copies_table, sfeatures);
437 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
438 	    ZFS_CACHE_ALL, PROP_INHERIT,
439 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
440 	    "all | none | metadata", "PRIMARYCACHE", cache_table, sfeatures);
441 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
442 	    ZFS_CACHE_ALL, PROP_INHERIT,
443 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
444 	    "all | none | metadata", "SECONDARYCACHE", cache_table, sfeatures);
445 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
446 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
447 	    "latency | throughput", "LOGBIAS", logbias_table, sfeatures);
448 	zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR,
449 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
450 	    "on | off | dir | sa", "XATTR", xattr_table, sfeatures);
451 	zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
452 	    ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
453 	    "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table,
454 	    sfeatures);
455 	zprop_register_index(ZFS_PROP_VOLMODE, "volmode",
456 	    ZFS_VOLMODE_DEFAULT, PROP_INHERIT,
457 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
458 	    "default | full | geom | dev | none", "VOLMODE", volmode_table,
459 	    sfeatures);
460 
461 	/* inherit index (boolean) properties */
462 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
463 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table, sfeatures);
464 	zprop_register_index(ZFS_PROP_RELATIME, "relatime", 0, PROP_INHERIT,
465 	    ZFS_TYPE_FILESYSTEM, "on | off", "RELATIME", boolean_table,
466 	    sfeatures);
467 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
468 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
469 	    boolean_table, sfeatures);
470 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
471 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
472 	    boolean_table, sfeatures);
473 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
474 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
475 	    boolean_table, sfeatures);
476 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
477 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
478 	    boolean_table, sfeatures);
479 #ifdef __FreeBSD__
480 	zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
481 	    ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table,
482 	    sfeatures);
483 #else
484 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
485 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table, sfeatures);
486 #endif
487 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
488 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table, sfeatures);
489 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
490 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
491 	    boolean_table, sfeatures);
492 	zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 1, PROP_INHERIT,
493 	    ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table,
494 	    sfeatures);
495 
496 	/* default index properties */
497 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
498 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
499 	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table, sfeatures);
500 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
501 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
502 	    "CANMOUNT", canmount_table, sfeatures);
503 
504 	/* readonly index properties */
505 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
506 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table,
507 	    sfeatures);
508 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
509 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
510 	    boolean_table, sfeatures);
511 	zprop_register_index(ZFS_PROP_KEYSTATUS, "keystatus",
512 	    ZFS_KEYSTATUS_NONE, PROP_READONLY, ZFS_TYPE_DATASET,
513 	    "none | unavailable | available",
514 	    "KEYSTATUS", keystatus_table, sfeatures);
515 
516 	/* set once index properties */
517 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
518 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
519 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
520 	    normalize_table, sfeatures);
521 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
522 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
523 	    ZFS_TYPE_SNAPSHOT,
524 	    "sensitive | insensitive | mixed", "CASE", case_table, sfeatures);
525 	zprop_register_index(ZFS_PROP_KEYFORMAT, "keyformat",
526 	    ZFS_KEYFORMAT_NONE, PROP_ONETIME_DEFAULT,
527 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
528 	    "none | raw | hex | passphrase", "KEYFORMAT", keyformat_table,
529 	    sfeatures);
530 	zprop_register_index(ZFS_PROP_ENCRYPTION, "encryption",
531 	    ZIO_CRYPT_DEFAULT, PROP_ONETIME, ZFS_TYPE_DATASET,
532 	    "on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | "
533 	    "aes-128-gcm | aes-192-gcm | aes-256-gcm", "ENCRYPTION",
534 	    crypto_table, sfeatures);
535 
536 	/* set once index (boolean) properties */
537 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
538 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
539 	    "on | off", "UTF8ONLY", boolean_table, sfeatures);
540 
541 	/* string properties */
542 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
543 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN",
544 	    sfeatures);
545 	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
546 	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES", sfeatures);
547 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
548 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
549 	    "MOUNTPOINT", sfeatures);
550 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
551 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | NFS share options",
552 	    "SHARENFS", sfeatures);
553 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
554 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
555 	    "filesystem | volume | snapshot | bookmark", "TYPE", sfeatures);
556 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
557 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
558 	    "on | off | SMB share options", "SHARESMB", sfeatures);
559 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
560 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
561 	    "<sensitivity label>", "MLSLABEL", sfeatures);
562 	zprop_register_string(ZFS_PROP_SELINUX_CONTEXT, "context",
563 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux context>",
564 	    "CONTEXT", sfeatures);
565 	zprop_register_string(ZFS_PROP_SELINUX_FSCONTEXT, "fscontext",
566 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux fscontext>",
567 	    "FSCONTEXT", sfeatures);
568 	zprop_register_string(ZFS_PROP_SELINUX_DEFCONTEXT, "defcontext",
569 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux defcontext>",
570 	    "DEFCONTEXT", sfeatures);
571 	zprop_register_string(ZFS_PROP_SELINUX_ROOTCONTEXT, "rootcontext",
572 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux rootcontext>",
573 	    "ROOTCONTEXT", sfeatures);
574 	zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
575 	    "receive_resume_token",
576 	    NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
577 	    "<string token>", "RESUMETOK", sfeatures);
578 	zprop_register_string(ZFS_PROP_ENCRYPTION_ROOT, "encryptionroot", NULL,
579 	    PROP_READONLY, ZFS_TYPE_DATASET, "<filesystem | volume>",
580 	    "ENCROOT", sfeatures);
581 	zprop_register_string(ZFS_PROP_KEYLOCATION, "keylocation",
582 	    "none", PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
583 	    "prompt | <file URI> | <https URL> | <http URL>", "KEYLOCATION",
584 	    sfeatures);
585 	zprop_register_string(ZFS_PROP_REDACT_SNAPS,
586 	    "redact_snaps", NULL, PROP_READONLY,
587 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<snapshot>[,...]",
588 	    "RSNAPS", sfeatures);
589 
590 	/* readonly number properties */
591 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
592 	    ZFS_TYPE_DATASET, "<size>", "USED", sfeatures);
593 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
594 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL",
595 	    sfeatures);
596 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
597 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>",
598 	    "REFER", sfeatures);
599 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
600 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
601 	    "<1.00x or higher if compressed>", "RATIO", sfeatures);
602 	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
603 	    PROP_READONLY, ZFS_TYPE_DATASET,
604 	    "<1.00x or higher if compressed>", "REFRATIO", sfeatures);
605 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
606 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
607 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK", sfeatures);
608 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
609 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
610 	    "USEDSNAP", sfeatures);
611 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
612 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
613 	    "USEDDS", sfeatures);
614 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
615 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
616 	    "USEDCHILD", sfeatures);
617 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
618 	    PROP_READONLY,
619 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV",
620 	    sfeatures);
621 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
622 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS", sfeatures);
623 	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
624 	    ZFS_TYPE_DATASET, "<size>", "WRITTEN", sfeatures);
625 	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
626 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
627 	    "LUSED", sfeatures);
628 	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
629 	    0, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>",
630 	    "LREFER", sfeatures);
631 	zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
632 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
633 	    "<count>", "FSCOUNT", sfeatures);
634 	zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
635 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
636 	    "<count>", "SSCOUNT", sfeatures);
637 	zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
638 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID",
639 	    sfeatures);
640 	zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
641 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG",
642 	    sfeatures);
643 	zprop_register_number(ZFS_PROP_PBKDF2_ITERS, "pbkdf2iters",
644 	    0, PROP_ONETIME_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
645 	    "<iters>", "PBKDF2ITERS", sfeatures);
646 	zprop_register_number(ZFS_PROP_OBJSETID, "objsetid", 0,
647 	    PROP_READONLY, ZFS_TYPE_DATASET, "<uint64>", "OBJSETID", sfeatures);
648 
649 	/* default number properties */
650 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
651 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA", sfeatures);
652 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
653 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
654 	    "<size> | none", "RESERV", sfeatures);
655 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
656 	    ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE",
657 	    sfeatures);
658 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
659 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA", sfeatures);
660 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
661 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
662 	    "<size> | none", "REFRESERV", sfeatures);
663 	zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
664 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
665 	    "<count> | none", "FSLIMIT", sfeatures);
666 	zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
667 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
668 	    "<count> | none", "SSLIMIT", sfeatures);
669 
670 	/* inherit number properties */
671 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
672 	    SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
673 	    ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE", sfeatures);
674 	zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
675 	    "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
676 	    "zero or 512 to 1M, power of 2", "SPECIAL_SMALL_BLOCKS", sfeatures);
677 
678 	/* hidden properties */
679 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
680 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES", sfeatures);
681 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
682 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME",
683 	    sfeatures);
684 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
685 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS",
686 	    sfeatures);
687 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
688 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
689 	    "STMF_SBD_LU", sfeatures);
690 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
691 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
692 	    "USERACCOUNTING", sfeatures);
693 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
694 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE", sfeatures);
695 	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
696 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT",
697 	    sfeatures);
698 	zprop_register_hidden(ZFS_PROP_IVSET_GUID, "ivsetguid",
699 	    PROP_TYPE_NUMBER, PROP_READONLY,
700 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "IVSETGUID", sfeatures);
701 	zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
702 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP",
703 	    sfeatures);
704 	zprop_register_hidden(ZFS_PROP_PBKDF2_SALT, "pbkdf2salt",
705 	    PROP_TYPE_NUMBER, PROP_ONETIME_DEFAULT,
706 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PBKDF2SALT", sfeatures);
707 	zprop_register_hidden(ZFS_PROP_KEY_GUID, "keyguid", PROP_TYPE_NUMBER,
708 	    PROP_READONLY, ZFS_TYPE_DATASET, "KEYGUID", sfeatures);
709 	zprop_register_hidden(ZFS_PROP_REDACTED, "redacted", PROP_TYPE_NUMBER,
710 	    PROP_READONLY, ZFS_TYPE_DATASET, "REDACTED", sfeatures);
711 
712 	/*
713 	 * Properties that are obsolete and not used.  These are retained so
714 	 * that we don't have to change the values of the zfs_prop_t enum, or
715 	 * have NULL pointers in the zfs_prop_table[].
716 	 */
717 	zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
718 	    PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG", sfeatures);
719 
720 	/* oddball properties */
721 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
722 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
723 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL, sfeatures);
724 
725 	zfs_mod_list_supported_free(sfeatures);
726 }
727 
728 boolean_t
729 zfs_prop_delegatable(zfs_prop_t prop)
730 {
731 	zprop_desc_t *pd = &zfs_prop_table[prop];
732 
733 	/* The mlslabel property is never delegatable. */
734 	if (prop == ZFS_PROP_MLSLABEL)
735 		return (B_FALSE);
736 
737 	return (pd->pd_attr != PROP_READONLY);
738 }
739 
740 /*
741  * Given a zfs dataset property name, returns the corresponding property ID.
742  */
743 zfs_prop_t
744 zfs_name_to_prop(const char *propname)
745 {
746 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
747 }
748 
749 /*
750  * Returns true if this is a valid user-defined property (one with a ':').
751  */
752 boolean_t
753 zfs_prop_user(const char *name)
754 {
755 	int i;
756 	char c;
757 	boolean_t foundsep = B_FALSE;
758 
759 	for (i = 0; i < strlen(name); i++) {
760 		c = name[i];
761 		if (!zprop_valid_char(c))
762 			return (B_FALSE);
763 		if (c == ':')
764 			foundsep = B_TRUE;
765 	}
766 
767 	if (!foundsep)
768 		return (B_FALSE);
769 
770 	return (B_TRUE);
771 }
772 
773 /*
774  * Returns true if this is a valid userspace-type property (one with a '@').
775  * Note that after the @, any character is valid (eg, another @, for SID
776  * user@domain).
777  */
778 boolean_t
779 zfs_prop_userquota(const char *name)
780 {
781 	zfs_userquota_prop_t prop;
782 
783 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
784 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
785 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
786 			return (B_TRUE);
787 		}
788 	}
789 
790 	return (B_FALSE);
791 }
792 
793 /*
794  * Returns true if this is a valid written@ property.
795  * Note that after the @, any character is valid (eg, another @, for
796  * written@pool/fs@origin).
797  */
798 boolean_t
799 zfs_prop_written(const char *name)
800 {
801 	static const char *prop_prefix = "written@";
802 	static const char *book_prefix = "written#";
803 	return (strncmp(name, prop_prefix, strlen(prop_prefix)) == 0 ||
804 	    strncmp(name, book_prefix, strlen(book_prefix)) == 0);
805 }
806 
807 /*
808  * Tables of index types, plus functions to convert between the user view
809  * (strings) and internal representation (uint64_t).
810  */
811 int
812 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
813 {
814 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
815 }
816 
817 int
818 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
819 {
820 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
821 }
822 
823 uint64_t
824 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
825 {
826 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
827 }
828 
829 /*
830  * Returns TRUE if the property applies to any of the given dataset types.
831  */
832 boolean_t
833 zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck)
834 {
835 	return (zprop_valid_for_type(prop, types, headcheck));
836 }
837 
838 zprop_type_t
839 zfs_prop_get_type(zfs_prop_t prop)
840 {
841 	return (zfs_prop_table[prop].pd_proptype);
842 }
843 
844 /*
845  * Returns TRUE if the property is readonly.
846  */
847 boolean_t
848 zfs_prop_readonly(zfs_prop_t prop)
849 {
850 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
851 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
852 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
853 }
854 
855 /*
856  * Returns TRUE if the property is visible (not hidden).
857  */
858 boolean_t
859 zfs_prop_visible(zfs_prop_t prop)
860 {
861 	return (zfs_prop_table[prop].pd_visible &&
862 	    zfs_prop_table[prop].pd_zfs_mod_supported);
863 }
864 
865 /*
866  * Returns TRUE if the property is only allowed to be set once.
867  */
868 boolean_t
869 zfs_prop_setonce(zfs_prop_t prop)
870 {
871 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
872 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
873 }
874 
875 const char *
876 zfs_prop_default_string(zfs_prop_t prop)
877 {
878 	return (zfs_prop_table[prop].pd_strdefault);
879 }
880 
881 uint64_t
882 zfs_prop_default_numeric(zfs_prop_t prop)
883 {
884 	return (zfs_prop_table[prop].pd_numdefault);
885 }
886 
887 /*
888  * Given a dataset property ID, returns the corresponding name.
889  * Assuming the zfs dataset property ID is valid.
890  */
891 const char *
892 zfs_prop_to_name(zfs_prop_t prop)
893 {
894 	return (zfs_prop_table[prop].pd_name);
895 }
896 
897 /*
898  * Returns TRUE if the property is inheritable.
899  */
900 boolean_t
901 zfs_prop_inheritable(zfs_prop_t prop)
902 {
903 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
904 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
905 }
906 
907 /*
908  * Returns TRUE if property is one of the encryption properties that requires
909  * a loaded encryption key to modify.
910  */
911 boolean_t
912 zfs_prop_encryption_key_param(zfs_prop_t prop)
913 {
914 	/*
915 	 * keylocation does not count as an encryption property. It can be
916 	 * changed at will without needing the master keys.
917 	 */
918 	return (prop == ZFS_PROP_PBKDF2_SALT || prop == ZFS_PROP_PBKDF2_ITERS ||
919 	    prop == ZFS_PROP_KEYFORMAT);
920 }
921 
922 /*
923  * Helper function used by both kernelspace and userspace to check the
924  * keylocation property. If encrypted is set, the keylocation must be valid
925  * for an encrypted dataset.
926  */
927 boolean_t
928 zfs_prop_valid_keylocation(const char *str, boolean_t encrypted)
929 {
930 	if (strcmp("none", str) == 0)
931 		return (!encrypted);
932 	else if (strcmp("prompt", str) == 0)
933 		return (B_TRUE);
934 	else if (strlen(str) > 8 && strncmp("file:///", str, 8) == 0)
935 		return (B_TRUE);
936 	else if (strlen(str) > 8 && strncmp("https://", str, 8) == 0)
937 		return (B_TRUE);
938 	else if (strlen(str) > 7 && strncmp("http://", str, 7) == 0)
939 		return (B_TRUE);
940 
941 	return (B_FALSE);
942 }
943 
944 
945 #ifndef _KERNEL
946 #include <libzfs.h>
947 
948 /*
949  * Returns a string describing the set of acceptable values for the given
950  * zfs property, or NULL if it cannot be set.
951  */
952 const char *
953 zfs_prop_values(zfs_prop_t prop)
954 {
955 	return (zfs_prop_table[prop].pd_values);
956 }
957 
958 /*
959  * Returns TRUE if this property is a string type.  Note that index types
960  * (compression, checksum) are treated as strings in userland, even though they
961  * are stored numerically on disk.
962  */
963 int
964 zfs_prop_is_string(zfs_prop_t prop)
965 {
966 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
967 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
968 }
969 
970 /*
971  * Returns the column header for the given property.  Used only in
972  * 'zfs list -o', but centralized here with the other property information.
973  */
974 const char *
975 zfs_prop_column_name(zfs_prop_t prop)
976 {
977 	return (zfs_prop_table[prop].pd_colname);
978 }
979 
980 /*
981  * Returns whether the given property should be displayed right-justified for
982  * 'zfs list'.
983  */
984 boolean_t
985 zfs_prop_align_right(zfs_prop_t prop)
986 {
987 	return (zfs_prop_table[prop].pd_rightalign);
988 }
989 
990 #endif
991 
992 #if defined(_KERNEL)
993 
994 #include <sys/simd.h>
995 
996 #if defined(HAVE_KERNEL_FPU_INTERNAL)
997 union fpregs_state **zfs_kfpu_fpregs;
998 EXPORT_SYMBOL(zfs_kfpu_fpregs);
999 #endif /* HAVE_KERNEL_FPU_INTERNAL */
1000 
1001 static int __init
1002 zcommon_init(void)
1003 {
1004 	int error = kfpu_init();
1005 	if (error)
1006 		return (error);
1007 
1008 	fletcher_4_init();
1009 
1010 	return (0);
1011 }
1012 
1013 static void __exit
1014 zcommon_fini(void)
1015 {
1016 	fletcher_4_fini();
1017 	kfpu_fini();
1018 }
1019 
1020 module_init_early(zcommon_init);
1021 module_exit(zcommon_fini);
1022 
1023 #endif
1024 
1025 ZFS_MODULE_DESCRIPTION("Generic ZFS support");
1026 ZFS_MODULE_AUTHOR(ZFS_META_AUTHOR);
1027 ZFS_MODULE_LICENSE(ZFS_META_LICENSE);
1028 ZFS_MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
1029 
1030 /* zfs dataset property functions */
1031 EXPORT_SYMBOL(zfs_userquota_prop_prefixes);
1032 EXPORT_SYMBOL(zfs_prop_init);
1033 EXPORT_SYMBOL(zfs_prop_get_type);
1034 EXPORT_SYMBOL(zfs_prop_get_table);
1035 EXPORT_SYMBOL(zfs_prop_delegatable);
1036 EXPORT_SYMBOL(zfs_prop_visible);
1037 
1038 /* Dataset property functions shared between libzfs and kernel. */
1039 EXPORT_SYMBOL(zfs_prop_default_string);
1040 EXPORT_SYMBOL(zfs_prop_default_numeric);
1041 EXPORT_SYMBOL(zfs_prop_readonly);
1042 EXPORT_SYMBOL(zfs_prop_inheritable);
1043 EXPORT_SYMBOL(zfs_prop_encryption_key_param);
1044 EXPORT_SYMBOL(zfs_prop_valid_keylocation);
1045 EXPORT_SYMBOL(zfs_prop_setonce);
1046 EXPORT_SYMBOL(zfs_prop_to_name);
1047 EXPORT_SYMBOL(zfs_name_to_prop);
1048 EXPORT_SYMBOL(zfs_prop_user);
1049 EXPORT_SYMBOL(zfs_prop_userquota);
1050 EXPORT_SYMBOL(zfs_prop_index_to_string);
1051 EXPORT_SYMBOL(zfs_prop_string_to_index);
1052 EXPORT_SYMBOL(zfs_prop_valid_for_type);
1053 EXPORT_SYMBOL(zfs_prop_written);
1054