xref: /freebsd/sys/contrib/openzfs/module/zcommon/zfs_prop.c (revision f7c32ed617858bcd22f8d1b03199099d50125721)
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 *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 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 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 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 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 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 zprop_index_t snapdir_table[] = {
229 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
230 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
231 		{ NULL }
232 	};
233 
234 	static zprop_index_t snapdev_table[] = {
235 		{ "hidden",	ZFS_SNAPDEV_HIDDEN },
236 		{ "visible",	ZFS_SNAPDEV_VISIBLE },
237 		{ NULL }
238 	};
239 
240 	static 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 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 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 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 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 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 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 zprop_index_t boolean_table[] = {
307 		{ "off",	0 },
308 		{ "on",		1 },
309 		{ NULL }
310 	};
311 
312 	static 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 zprop_index_t logbias_table[] = {
320 		{ "latency",	ZFS_LOGBIAS_LATENCY },
321 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
322 		{ NULL }
323 	};
324 
325 	static 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 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 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 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 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 zprop_index_t redundant_metadata_table[] = {
366 		{ "all",	ZFS_REDUNDANT_METADATA_ALL },
367 		{ "most",	ZFS_REDUNDANT_METADATA_MOST },
368 		{ NULL }
369 	};
370 
371 	static 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 	/* inherit index properties */
381 	zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
382 	    ZFS_REDUNDANT_METADATA_ALL,
383 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
384 	    "all | most", "REDUND_MD",
385 	    redundant_metadata_table);
386 	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
387 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
388 	    "standard | always | disabled", "SYNC",
389 	    sync_table);
390 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
391 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
392 	    ZFS_TYPE_VOLUME,
393 	    "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein"
394 	    " | edonr",
395 	    "CHECKSUM", checksum_table);
396 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
397 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
398 	    "on | off | verify | sha256[,verify] | sha512[,verify] | "
399 	    "skein[,verify] | edonr,verify",
400 	    "DEDUP", dedup_table);
401 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
402 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
403 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
404 	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4 | "
405 	    "zstd | zstd-[1-19] | "
406 	    "zstd-fast | zstd-fast-[1-10,20,30,40,50,60,70,80,90,100,500,1000]",
407 	    "COMPRESS", compress_table);
408 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
409 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
410 	    "hidden | visible", "SNAPDIR", snapdir_table);
411 	zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN,
412 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
413 	    "hidden | visible", "SNAPDEV", snapdev_table);
414 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
415 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
416 	    "discard | groupmask | passthrough | restricted", "ACLMODE",
417 	    acl_mode_table);
418 	zprop_register_index(ZFS_PROP_ACLTYPE, "acltype",
419 #ifdef __linux__
420 	    /* Linux doesn't natively support ZFS's NFSv4-style ACLs. */
421 	    ZFS_ACLTYPE_OFF,
422 #else
423 	    ZFS_ACLTYPE_NFSV4,
424 #endif
425 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
426 	    "off | nfsv4 | posix", "ACLTYPE", acltype_table);
427 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
428 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
429 	    "discard | noallow | restricted | passthrough | passthrough-x",
430 	    "ACLINHERIT", acl_inherit_table);
431 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
432 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
433 	    "1 | 2 | 3", "COPIES", copies_table);
434 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
435 	    ZFS_CACHE_ALL, PROP_INHERIT,
436 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
437 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
438 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
439 	    ZFS_CACHE_ALL, PROP_INHERIT,
440 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
441 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
442 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
443 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
444 	    "latency | throughput", "LOGBIAS", logbias_table);
445 	zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR,
446 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
447 	    "on | off | dir | sa", "XATTR", xattr_table);
448 	zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
449 	    ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
450 	    "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
451 	zprop_register_index(ZFS_PROP_VOLMODE, "volmode",
452 	    ZFS_VOLMODE_DEFAULT, PROP_INHERIT,
453 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
454 	    "default | full | geom | dev | none", "VOLMODE", volmode_table);
455 
456 	/* inherit index (boolean) properties */
457 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
458 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
459 	zprop_register_index(ZFS_PROP_RELATIME, "relatime", 0, PROP_INHERIT,
460 	    ZFS_TYPE_FILESYSTEM, "on | off", "RELATIME", boolean_table);
461 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
462 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
463 	    boolean_table);
464 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
465 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
466 	    boolean_table);
467 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
468 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
469 	    boolean_table);
470 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
471 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
472 	    boolean_table);
473 #ifdef __FreeBSD__
474 	zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
475 	    ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table);
476 #else
477 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
478 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
479 #endif
480 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
481 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table);
482 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
483 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
484 	    boolean_table);
485 	zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 1, PROP_INHERIT,
486 	    ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table);
487 
488 	/* default index properties */
489 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
490 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
491 	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
492 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
493 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
494 	    "CANMOUNT", canmount_table);
495 
496 	/* readonly index properties */
497 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
498 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
499 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
500 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
501 	    boolean_table);
502 	zprop_register_index(ZFS_PROP_KEYSTATUS, "keystatus",
503 	    ZFS_KEYSTATUS_NONE, PROP_READONLY, ZFS_TYPE_DATASET,
504 	    "none | unavailable | available",
505 	    "KEYSTATUS", keystatus_table);
506 
507 	/* set once index properties */
508 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
509 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
510 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
511 	    normalize_table);
512 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
513 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
514 	    ZFS_TYPE_SNAPSHOT,
515 	    "sensitive | insensitive | mixed", "CASE", case_table);
516 	zprop_register_index(ZFS_PROP_KEYFORMAT, "keyformat",
517 	    ZFS_KEYFORMAT_NONE, PROP_ONETIME_DEFAULT,
518 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
519 	    "none | raw | hex | passphrase", "KEYFORMAT", keyformat_table);
520 	zprop_register_index(ZFS_PROP_ENCRYPTION, "encryption",
521 	    ZIO_CRYPT_DEFAULT, PROP_ONETIME, ZFS_TYPE_DATASET,
522 	    "on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | "
523 	    "aes-128-gcm | aes-192-gcm | aes-256-gcm", "ENCRYPTION",
524 	    crypto_table);
525 
526 	/* set once index (boolean) properties */
527 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
528 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
529 	    "on | off", "UTF8ONLY", boolean_table);
530 
531 	/* string properties */
532 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
533 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
534 	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
535 	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
536 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
537 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
538 	    "MOUNTPOINT");
539 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
540 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | NFS share options",
541 	    "SHARENFS");
542 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
543 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
544 	    "filesystem | volume | snapshot | bookmark", "TYPE");
545 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
546 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
547 	    "on | off | SMB share options", "SHARESMB");
548 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
549 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
550 	    "<sensitivity label>", "MLSLABEL");
551 	zprop_register_string(ZFS_PROP_SELINUX_CONTEXT, "context",
552 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux context>",
553 	    "CONTEXT");
554 	zprop_register_string(ZFS_PROP_SELINUX_FSCONTEXT, "fscontext",
555 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux fscontext>",
556 	    "FSCONTEXT");
557 	zprop_register_string(ZFS_PROP_SELINUX_DEFCONTEXT, "defcontext",
558 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux defcontext>",
559 	    "DEFCONTEXT");
560 	zprop_register_string(ZFS_PROP_SELINUX_ROOTCONTEXT, "rootcontext",
561 	    "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux rootcontext>",
562 	    "ROOTCONTEXT");
563 	zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
564 	    "receive_resume_token",
565 	    NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
566 	    "<string token>", "RESUMETOK");
567 	zprop_register_string(ZFS_PROP_ENCRYPTION_ROOT, "encryptionroot", NULL,
568 	    PROP_READONLY, ZFS_TYPE_DATASET, "<filesystem | volume>",
569 	    "ENCROOT");
570 	zprop_register_string(ZFS_PROP_KEYLOCATION, "keylocation",
571 	    "none", PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
572 	    "prompt | <file URI> | <https URL> | <http URL>", "KEYLOCATION");
573 	zprop_register_string(ZFS_PROP_REDACT_SNAPS,
574 	    "redact_snaps", NULL, PROP_READONLY,
575 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<snapshot>[,...]",
576 	    "RSNAPS");
577 
578 	/* readonly number properties */
579 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
580 	    ZFS_TYPE_DATASET, "<size>", "USED");
581 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
582 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
583 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
584 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>",
585 	    "REFER");
586 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
587 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
588 	    "<1.00x or higher if compressed>", "RATIO");
589 	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
590 	    PROP_READONLY, ZFS_TYPE_DATASET,
591 	    "<1.00x or higher if compressed>", "REFRATIO");
592 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
593 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
594 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
595 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
596 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
597 	    "USEDSNAP");
598 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
599 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
600 	    "USEDDS");
601 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
602 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
603 	    "USEDCHILD");
604 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
605 	    PROP_READONLY,
606 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
607 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
608 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
609 	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
610 	    ZFS_TYPE_DATASET, "<size>", "WRITTEN");
611 	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
612 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
613 	    "LUSED");
614 	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
615 	    0, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>",
616 	    "LREFER");
617 	zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
618 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
619 	    "<count>", "FSCOUNT");
620 	zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
621 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
622 	    "<count>", "SSCOUNT");
623 	zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
624 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
625 	zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
626 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
627 	zprop_register_number(ZFS_PROP_PBKDF2_ITERS, "pbkdf2iters",
628 	    0, PROP_ONETIME_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
629 	    "<iters>", "PBKDF2ITERS");
630 	zprop_register_number(ZFS_PROP_OBJSETID, "objsetid", 0,
631 	    PROP_READONLY, ZFS_TYPE_DATASET, "<uint64>", "OBJSETID");
632 
633 	/* default number properties */
634 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
635 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
636 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
637 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
638 	    "<size> | none", "RESERV");
639 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
640 	    ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
641 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
642 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
643 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
644 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
645 	    "<size> | none", "REFRESERV");
646 	zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
647 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
648 	    "<count> | none", "FSLIMIT");
649 	zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
650 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
651 	    "<count> | none", "SSLIMIT");
652 
653 	/* inherit number properties */
654 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
655 	    SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
656 	    ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
657 	zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
658 	    "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
659 	    "zero or 512 to 1M, power of 2", "SPECIAL_SMALL_BLOCKS");
660 
661 	/* hidden properties */
662 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
663 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
664 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
665 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
666 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
667 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
668 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
669 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
670 	    "STMF_SBD_LU");
671 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
672 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
673 	    "USERACCOUNTING");
674 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
675 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
676 	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
677 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
678 	zprop_register_hidden(ZFS_PROP_IVSET_GUID, "ivsetguid",
679 	    PROP_TYPE_NUMBER, PROP_READONLY,
680 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "IVSETGUID");
681 	zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
682 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
683 	zprop_register_hidden(ZFS_PROP_PBKDF2_SALT, "pbkdf2salt",
684 	    PROP_TYPE_NUMBER, PROP_ONETIME_DEFAULT,
685 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PBKDF2SALT");
686 	zprop_register_hidden(ZFS_PROP_KEY_GUID, "keyguid", PROP_TYPE_NUMBER,
687 	    PROP_READONLY, ZFS_TYPE_DATASET, "KEYGUID");
688 	zprop_register_hidden(ZFS_PROP_REDACTED, "redacted", PROP_TYPE_NUMBER,
689 	    PROP_READONLY, ZFS_TYPE_DATASET, "REDACTED");
690 
691 	/*
692 	 * Properties that are obsolete and not used.  These are retained so
693 	 * that we don't have to change the values of the zfs_prop_t enum, or
694 	 * have NULL pointers in the zfs_prop_table[].
695 	 */
696 	zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
697 	    PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG");
698 
699 	/* oddball properties */
700 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
701 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
702 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
703 }
704 
705 boolean_t
706 zfs_prop_delegatable(zfs_prop_t prop)
707 {
708 	zprop_desc_t *pd = &zfs_prop_table[prop];
709 
710 	/* The mlslabel property is never delegatable. */
711 	if (prop == ZFS_PROP_MLSLABEL)
712 		return (B_FALSE);
713 
714 	return (pd->pd_attr != PROP_READONLY);
715 }
716 
717 /*
718  * Given a zfs dataset property name, returns the corresponding property ID.
719  */
720 zfs_prop_t
721 zfs_name_to_prop(const char *propname)
722 {
723 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
724 }
725 
726 /*
727  * For user property names, we allow all lowercase alphanumeric characters, plus
728  * a few useful punctuation characters.
729  */
730 static int
731 valid_char(char c)
732 {
733 	return ((c >= 'a' && c <= 'z') ||
734 	    (c >= '0' && c <= '9') ||
735 	    c == '-' || c == '_' || c == '.' || c == ':');
736 }
737 
738 /*
739  * Returns true if this is a valid user-defined property (one with a ':').
740  */
741 boolean_t
742 zfs_prop_user(const char *name)
743 {
744 	int i;
745 	char c;
746 	boolean_t foundsep = B_FALSE;
747 
748 	for (i = 0; i < strlen(name); i++) {
749 		c = name[i];
750 		if (!valid_char(c))
751 			return (B_FALSE);
752 		if (c == ':')
753 			foundsep = B_TRUE;
754 	}
755 
756 	if (!foundsep)
757 		return (B_FALSE);
758 
759 	return (B_TRUE);
760 }
761 
762 /*
763  * Returns true if this is a valid userspace-type property (one with a '@').
764  * Note that after the @, any character is valid (eg, another @, for SID
765  * user@domain).
766  */
767 boolean_t
768 zfs_prop_userquota(const char *name)
769 {
770 	zfs_userquota_prop_t prop;
771 
772 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
773 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
774 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
775 			return (B_TRUE);
776 		}
777 	}
778 
779 	return (B_FALSE);
780 }
781 
782 /*
783  * Returns true if this is a valid written@ property.
784  * Note that after the @, any character is valid (eg, another @, for
785  * written@pool/fs@origin).
786  */
787 boolean_t
788 zfs_prop_written(const char *name)
789 {
790 	static const char *prop_prefix = "written@";
791 	static const char *book_prefix = "written#";
792 	return (strncmp(name, prop_prefix, strlen(prop_prefix)) == 0 ||
793 	    strncmp(name, book_prefix, strlen(book_prefix)) == 0);
794 }
795 
796 /*
797  * Tables of index types, plus functions to convert between the user view
798  * (strings) and internal representation (uint64_t).
799  */
800 int
801 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
802 {
803 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
804 }
805 
806 int
807 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
808 {
809 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
810 }
811 
812 uint64_t
813 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
814 {
815 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
816 }
817 
818 /*
819  * Returns TRUE if the property applies to any of the given dataset types.
820  */
821 boolean_t
822 zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck)
823 {
824 	return (zprop_valid_for_type(prop, types, headcheck));
825 }
826 
827 zprop_type_t
828 zfs_prop_get_type(zfs_prop_t prop)
829 {
830 	return (zfs_prop_table[prop].pd_proptype);
831 }
832 
833 /*
834  * Returns TRUE if the property is readonly.
835  */
836 boolean_t
837 zfs_prop_readonly(zfs_prop_t prop)
838 {
839 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
840 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
841 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
842 }
843 
844 /*
845  * Returns TRUE if the property is visible (not hidden).
846  */
847 boolean_t
848 zfs_prop_visible(zfs_prop_t prop)
849 {
850 	return (zfs_prop_table[prop].pd_visible &&
851 	    zfs_prop_table[prop].pd_zfs_mod_supported);
852 }
853 
854 /*
855  * Returns TRUE if the property is only allowed to be set once.
856  */
857 boolean_t
858 zfs_prop_setonce(zfs_prop_t prop)
859 {
860 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
861 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
862 }
863 
864 const char *
865 zfs_prop_default_string(zfs_prop_t prop)
866 {
867 	return (zfs_prop_table[prop].pd_strdefault);
868 }
869 
870 uint64_t
871 zfs_prop_default_numeric(zfs_prop_t prop)
872 {
873 	return (zfs_prop_table[prop].pd_numdefault);
874 }
875 
876 /*
877  * Given a dataset property ID, returns the corresponding name.
878  * Assuming the zfs dataset property ID is valid.
879  */
880 const char *
881 zfs_prop_to_name(zfs_prop_t prop)
882 {
883 	return (zfs_prop_table[prop].pd_name);
884 }
885 
886 /*
887  * Returns TRUE if the property is inheritable.
888  */
889 boolean_t
890 zfs_prop_inheritable(zfs_prop_t prop)
891 {
892 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
893 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
894 }
895 
896 /*
897  * Returns TRUE if property is one of the encryption properties that requires
898  * a loaded encryption key to modify.
899  */
900 boolean_t
901 zfs_prop_encryption_key_param(zfs_prop_t prop)
902 {
903 	/*
904 	 * keylocation does not count as an encryption property. It can be
905 	 * changed at will without needing the master keys.
906 	 */
907 	return (prop == ZFS_PROP_PBKDF2_SALT || prop == ZFS_PROP_PBKDF2_ITERS ||
908 	    prop == ZFS_PROP_KEYFORMAT);
909 }
910 
911 /*
912  * Helper function used by both kernelspace and userspace to check the
913  * keylocation property. If encrypted is set, the keylocation must be valid
914  * for an encrypted dataset.
915  */
916 boolean_t
917 zfs_prop_valid_keylocation(const char *str, boolean_t encrypted)
918 {
919 	if (strcmp("none", str) == 0)
920 		return (!encrypted);
921 	else if (strcmp("prompt", str) == 0)
922 		return (B_TRUE);
923 	else if (strlen(str) > 8 && strncmp("file:///", str, 8) == 0)
924 		return (B_TRUE);
925 	else if (strlen(str) > 8 && strncmp("https://", str, 8) == 0)
926 		return (B_TRUE);
927 	else if (strlen(str) > 7 && strncmp("http://", str, 7) == 0)
928 		return (B_TRUE);
929 
930 	return (B_FALSE);
931 }
932 
933 
934 #ifndef _KERNEL
935 #include <libzfs.h>
936 
937 /*
938  * Returns a string describing the set of acceptable values for the given
939  * zfs property, or NULL if it cannot be set.
940  */
941 const char *
942 zfs_prop_values(zfs_prop_t prop)
943 {
944 	return (zfs_prop_table[prop].pd_values);
945 }
946 
947 /*
948  * Returns TRUE if this property is a string type.  Note that index types
949  * (compression, checksum) are treated as strings in userland, even though they
950  * are stored numerically on disk.
951  */
952 int
953 zfs_prop_is_string(zfs_prop_t prop)
954 {
955 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
956 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
957 }
958 
959 /*
960  * Returns the column header for the given property.  Used only in
961  * 'zfs list -o', but centralized here with the other property information.
962  */
963 const char *
964 zfs_prop_column_name(zfs_prop_t prop)
965 {
966 	return (zfs_prop_table[prop].pd_colname);
967 }
968 
969 /*
970  * Returns whether the given property should be displayed right-justified for
971  * 'zfs list'.
972  */
973 boolean_t
974 zfs_prop_align_right(zfs_prop_t prop)
975 {
976 	return (zfs_prop_table[prop].pd_rightalign);
977 }
978 
979 #endif
980 
981 #if defined(_KERNEL)
982 
983 #include <sys/simd.h>
984 
985 #if defined(HAVE_KERNEL_FPU_INTERNAL)
986 union fpregs_state **zfs_kfpu_fpregs;
987 EXPORT_SYMBOL(zfs_kfpu_fpregs);
988 #endif /* HAVE_KERNEL_FPU_INTERNAL */
989 
990 static int __init
991 zcommon_init(void)
992 {
993 	int error = kfpu_init();
994 	if (error)
995 		return (error);
996 
997 	fletcher_4_init();
998 
999 	return (0);
1000 }
1001 
1002 static void __exit
1003 zcommon_fini(void)
1004 {
1005 	fletcher_4_fini();
1006 	kfpu_fini();
1007 }
1008 
1009 module_init_early(zcommon_init);
1010 module_exit(zcommon_fini);
1011 
1012 #endif
1013 
1014 ZFS_MODULE_DESCRIPTION("Generic ZFS support");
1015 ZFS_MODULE_AUTHOR(ZFS_META_AUTHOR);
1016 ZFS_MODULE_LICENSE(ZFS_META_LICENSE);
1017 ZFS_MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
1018 
1019 /* zfs dataset property functions */
1020 EXPORT_SYMBOL(zfs_userquota_prop_prefixes);
1021 EXPORT_SYMBOL(zfs_prop_init);
1022 EXPORT_SYMBOL(zfs_prop_get_type);
1023 EXPORT_SYMBOL(zfs_prop_get_table);
1024 EXPORT_SYMBOL(zfs_prop_delegatable);
1025 EXPORT_SYMBOL(zfs_prop_visible);
1026 
1027 /* Dataset property functions shared between libzfs and kernel. */
1028 EXPORT_SYMBOL(zfs_prop_default_string);
1029 EXPORT_SYMBOL(zfs_prop_default_numeric);
1030 EXPORT_SYMBOL(zfs_prop_readonly);
1031 EXPORT_SYMBOL(zfs_prop_inheritable);
1032 EXPORT_SYMBOL(zfs_prop_encryption_key_param);
1033 EXPORT_SYMBOL(zfs_prop_valid_keylocation);
1034 EXPORT_SYMBOL(zfs_prop_setonce);
1035 EXPORT_SYMBOL(zfs_prop_to_name);
1036 EXPORT_SYMBOL(zfs_name_to_prop);
1037 EXPORT_SYMBOL(zfs_prop_user);
1038 EXPORT_SYMBOL(zfs_prop_userquota);
1039 EXPORT_SYMBOL(zfs_prop_index_to_string);
1040 EXPORT_SYMBOL(zfs_prop_string_to_index);
1041 EXPORT_SYMBOL(zfs_prop_valid_for_type);
1042 EXPORT_SYMBOL(zfs_prop_written);
1043