xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision 33c72b7598992897b94815b1f47b7b8077e53808)
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, 2016 by Delphix. All rights reserved.
24  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25  * Copyright (c) 2014 Integros [integros.com]
26  * Copyright 2016, Joyent, Inc.
27  */
28 
29 /* Portions Copyright 2010 Robert Milkowski */
30 
31 #include <sys/zio.h>
32 #include <sys/spa.h>
33 #include <sys/u8_textprep.h>
34 #include <sys/zfs_acl.h>
35 #include <sys/zfs_ioctl.h>
36 #include <sys/zfs_znode.h>
37 #include <sys/dsl_crypt.h>
38 
39 #include "zfs_prop.h"
40 #include "zfs_deleg.h"
41 
42 #if defined(_KERNEL)
43 #include <sys/systm.h>
44 #else
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 };
59 
60 zprop_desc_t *
61 zfs_prop_get_table(void)
62 {
63 	return (zfs_prop_table);
64 }
65 
66 void
67 zfs_prop_init(void)
68 {
69 	static zprop_index_t checksum_table[] = {
70 		{ "on",		ZIO_CHECKSUM_ON },
71 		{ "off",	ZIO_CHECKSUM_OFF },
72 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
73 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
74 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
75 		{ "noparity",	ZIO_CHECKSUM_NOPARITY },
76 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
77 		{ "skein",	ZIO_CHECKSUM_SKEIN },
78 		{ "edonr",	ZIO_CHECKSUM_EDONR },
79 		{ NULL }
80 	};
81 
82 	static zprop_index_t dedup_table[] = {
83 		{ "on",		ZIO_CHECKSUM_ON },
84 		{ "off",	ZIO_CHECKSUM_OFF },
85 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
86 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
87 		{ "sha256,verify",
88 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
89 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
90 		{ "sha512,verify",
91 				ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
92 		{ "skein",	ZIO_CHECKSUM_SKEIN },
93 		{ "skein,verify",
94 				ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
95 		{ "edonr,verify",
96 				ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
97 		{ NULL }
98 	};
99 
100 	static zprop_index_t compress_table[] = {
101 		{ "on",		ZIO_COMPRESS_ON },
102 		{ "off",	ZIO_COMPRESS_OFF },
103 		{ "lzjb",	ZIO_COMPRESS_LZJB },
104 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
105 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
106 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
107 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
108 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
109 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
110 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
111 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
112 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
113 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
114 		{ "zle",	ZIO_COMPRESS_ZLE },
115 		{ "lz4",	ZIO_COMPRESS_LZ4 },
116 		{ NULL }
117 	};
118 
119 	static zprop_index_t crypto_table[] = {
120 		{ "on",			ZIO_CRYPT_ON },
121 		{ "off",		ZIO_CRYPT_OFF },
122 		{ "aes-128-ccm",	ZIO_CRYPT_AES_128_CCM },
123 		{ "aes-192-ccm",	ZIO_CRYPT_AES_192_CCM },
124 		{ "aes-256-ccm",	ZIO_CRYPT_AES_256_CCM },
125 		{ "aes-128-gcm",	ZIO_CRYPT_AES_128_GCM },
126 		{ "aes-192-gcm",	ZIO_CRYPT_AES_192_GCM },
127 		{ "aes-256-gcm",	ZIO_CRYPT_AES_256_GCM },
128 		{ NULL }
129 	};
130 
131 	static zprop_index_t keyformat_table[] = {
132 		{ "none",		ZFS_KEYFORMAT_NONE },
133 		{ "raw",		ZFS_KEYFORMAT_RAW },
134 		{ "hex",		ZFS_KEYFORMAT_HEX },
135 		{ "passphrase",		ZFS_KEYFORMAT_PASSPHRASE },
136 		{ NULL }
137 	};
138 
139 	static zprop_index_t snapdir_table[] = {
140 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
141 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
142 		{ NULL }
143 	};
144 
145 	static zprop_index_t acl_mode_table[] = {
146 		{ "discard",	ZFS_ACL_DISCARD },
147 		{ "groupmask",	ZFS_ACL_GROUPMASK },
148 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
149 		{ "restricted", ZFS_ACL_RESTRICTED },
150 		{ NULL }
151 	};
152 
153 	static zprop_index_t acl_inherit_table[] = {
154 		{ "discard",	ZFS_ACL_DISCARD },
155 		{ "noallow",	ZFS_ACL_NOALLOW },
156 		{ "restricted",	ZFS_ACL_RESTRICTED },
157 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
158 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
159 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
160 		{ NULL }
161 	};
162 
163 	static zprop_index_t case_table[] = {
164 		{ "sensitive",		ZFS_CASE_SENSITIVE },
165 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
166 		{ "mixed",		ZFS_CASE_MIXED },
167 		{ NULL }
168 	};
169 
170 	static zprop_index_t copies_table[] = {
171 		{ "1",		1 },
172 		{ "2",		2 },
173 		{ "3",		3 },
174 		{ NULL }
175 	};
176 
177 	/*
178 	 * Use the unique flags we have to send to u8_strcmp() and/or
179 	 * u8_textprep() to represent the various normalization property
180 	 * values.
181 	 */
182 	static zprop_index_t normalize_table[] = {
183 		{ "none",	0 },
184 		{ "formD",	U8_TEXTPREP_NFD },
185 		{ "formKC",	U8_TEXTPREP_NFKC },
186 		{ "formC",	U8_TEXTPREP_NFC },
187 		{ "formKD",	U8_TEXTPREP_NFKD },
188 		{ NULL }
189 	};
190 
191 	static zprop_index_t version_table[] = {
192 		{ "1",		1 },
193 		{ "2",		2 },
194 		{ "3",		3 },
195 		{ "4",		4 },
196 		{ "5",		5 },
197 		{ "current",	ZPL_VERSION },
198 		{ NULL }
199 	};
200 
201 	static zprop_index_t boolean_table[] = {
202 		{ "off",	0 },
203 		{ "on",		1 },
204 		{ NULL }
205 	};
206 
207 	static zprop_index_t keystatus_table[] = {
208 		{ "none",		ZFS_KEYSTATUS_NONE },
209 		{ "unavailable",	ZFS_KEYSTATUS_UNAVAILABLE },
210 		{ "available",		ZFS_KEYSTATUS_AVAILABLE },
211 		{ NULL }
212 	};
213 
214 	static zprop_index_t logbias_table[] = {
215 		{ "latency",	ZFS_LOGBIAS_LATENCY },
216 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
217 		{ NULL }
218 	};
219 
220 	static zprop_index_t canmount_table[] = {
221 		{ "off",	ZFS_CANMOUNT_OFF },
222 		{ "on",		ZFS_CANMOUNT_ON },
223 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
224 		{ NULL }
225 	};
226 
227 	static zprop_index_t cache_table[] = {
228 		{ "none",	ZFS_CACHE_NONE },
229 		{ "metadata",	ZFS_CACHE_METADATA },
230 		{ "all",	ZFS_CACHE_ALL },
231 		{ NULL }
232 	};
233 
234 	static zprop_index_t sync_table[] = {
235 		{ "standard",	ZFS_SYNC_STANDARD },
236 		{ "always",	ZFS_SYNC_ALWAYS },
237 		{ "disabled",	ZFS_SYNC_DISABLED },
238 		{ NULL }
239 	};
240 
241 	static zprop_index_t dnsize_table[] = {
242 		{ "legacy",	ZFS_DNSIZE_LEGACY },
243 		{ "auto",	ZFS_DNSIZE_AUTO },
244 		{ "1k",		ZFS_DNSIZE_1K },
245 		{ "2k",		ZFS_DNSIZE_2K },
246 		{ "4k",		ZFS_DNSIZE_4K },
247 		{ "8k",		ZFS_DNSIZE_8K },
248 		{ "16k",	ZFS_DNSIZE_16K },
249 		{ NULL }
250 	};
251 
252 	static zprop_index_t redundant_metadata_table[] = {
253 		{ "all",	ZFS_REDUNDANT_METADATA_ALL },
254 		{ "most",	ZFS_REDUNDANT_METADATA_MOST },
255 		{ NULL }
256 	};
257 
258 	/* inherit index properties */
259 	zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
260 	    ZFS_REDUNDANT_METADATA_ALL,
261 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
262 	    "all | most", "REDUND_MD",
263 	    redundant_metadata_table);
264 	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
265 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
266 	    "standard | always | disabled", "SYNC",
267 	    sync_table);
268 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
269 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
270 	    ZFS_TYPE_VOLUME,
271 	    "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
272 	    "skein | edonr", "CHECKSUM", checksum_table);
273 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
274 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
275 	    "on | off | verify | sha256[,verify], sha512[,verify], "
276 	    "skein[,verify], edonr,verify", "DEDUP", dedup_table);
277 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
278 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
279 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
280 	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
281 	    "COMPRESS", compress_table);
282 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
283 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
284 	    "hidden | visible", "SNAPDIR", snapdir_table);
285 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
286 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
287 	    "discard | groupmask | passthrough | restricted", "ACLMODE",
288 	    acl_mode_table);
289 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
290 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
291 	    "discard | noallow | restricted | passthrough | passthrough-x",
292 	    "ACLINHERIT", acl_inherit_table);
293 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
294 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
295 	    "1 | 2 | 3", "COPIES", copies_table);
296 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
297 	    ZFS_CACHE_ALL, PROP_INHERIT,
298 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
299 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
300 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
301 	    ZFS_CACHE_ALL, PROP_INHERIT,
302 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
303 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
304 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
305 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
306 	    "latency | throughput", "LOGBIAS", logbias_table);
307 
308 	zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
309 	    ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
310 	    "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
311 
312 	/* inherit index (boolean) properties */
313 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
314 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
315 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
316 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
317 	    boolean_table);
318 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
319 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
320 	    boolean_table);
321 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
322 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
323 	    boolean_table);
324 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
325 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
326 	    boolean_table);
327 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
328 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
329 	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
330 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
331 	    boolean_table);
332 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
333 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
334 	    boolean_table);
335 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
336 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
337 	    boolean_table);
338 
339 	/* default index properties */
340 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
341 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
342 	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
343 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
344 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
345 	    "CANMOUNT", canmount_table);
346 
347 	/* readonly index properties */
348 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
349 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
350 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
351 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
352 	    boolean_table);
353 	zprop_register_index(ZFS_PROP_KEYSTATUS, "keystatus",
354 	    ZFS_KEYSTATUS_NONE, PROP_READONLY, ZFS_TYPE_DATASET,
355 	    "none | unavailable | available",
356 	    "KEYSTATUS", keystatus_table);
357 
358 	/* set once index properties */
359 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
360 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
361 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
362 	    normalize_table);
363 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
364 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
365 	    ZFS_TYPE_SNAPSHOT,
366 	    "sensitive | insensitive | mixed", "CASE", case_table);
367 	zprop_register_index(ZFS_PROP_KEYFORMAT, "keyformat",
368 	    ZFS_KEYFORMAT_NONE, PROP_ONETIME_DEFAULT,
369 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
370 	    "none | raw | hex | passphrase", "KEYFORMAT", keyformat_table);
371 	zprop_register_index(ZFS_PROP_ENCRYPTION, "encryption",
372 	    ZIO_CRYPT_DEFAULT, PROP_ONETIME, ZFS_TYPE_DATASET,
373 	    "on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | "
374 	    "aes-128-gcm | aes-192-gcm | aes-256-gcm", "ENCRYPTION",
375 	    crypto_table);
376 
377 	/* set once index (boolean) properties */
378 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
379 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
380 	    "on | off", "UTF8ONLY", boolean_table);
381 
382 	/* string properties */
383 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
384 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
385 	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
386 	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
387 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
388 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
389 	    "MOUNTPOINT");
390 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
391 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
392 	    "SHARENFS");
393 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
394 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
395 	    "filesystem | volume | snapshot | bookmark", "TYPE");
396 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
397 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
398 	    "on | off | sharemgr(1M) options", "SHARESMB");
399 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
400 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
401 	    "<sensitivity label>", "MLSLABEL");
402 	zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
403 	    "receive_resume_token",
404 	    NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
405 	    "<string token>", "RESUMETOK");
406 	zprop_register_string(ZFS_PROP_ENCRYPTION_ROOT, "encryptionroot", NULL,
407 	    PROP_READONLY, ZFS_TYPE_DATASET, "<filesystem | volume>",
408 	    "ENCROOT");
409 	zprop_register_string(ZFS_PROP_KEYLOCATION, "keylocation",
410 	    "none", PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
411 	    "prompt | <file URI>", "KEYLOCATION");
412 
413 	/* readonly number properties */
414 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
415 	    ZFS_TYPE_DATASET, "<size>", "USED");
416 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
417 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
418 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
419 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
420 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
421 	    PROP_READONLY, ZFS_TYPE_DATASET,
422 	    "<1.00x or higher if compressed>", "RATIO");
423 	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
424 	    PROP_READONLY, ZFS_TYPE_DATASET,
425 	    "<1.00x or higher if compressed>", "REFRATIO");
426 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
427 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
428 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
429 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
430 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
431 	    "USEDSNAP");
432 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
433 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
434 	    "USEDDS");
435 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
436 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
437 	    "USEDCHILD");
438 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
439 	    PROP_READONLY,
440 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
441 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
442 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
443 	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
444 	    ZFS_TYPE_DATASET, "<size>", "WRITTEN");
445 	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
446 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
447 	    "LUSED");
448 	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
449 	    0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
450 	zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
451 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
452 	    "<count>", "FSCOUNT");
453 	zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
454 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
455 	    "<count>", "SSCOUNT");
456 	zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
457 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
458 	zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
459 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
460 	zprop_register_number(ZFS_PROP_PBKDF2_ITERS, "pbkdf2iters",
461 	    0, PROP_ONETIME_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
462 	    "<iters>", "PBKDF2ITERS");
463 
464 	/* default number properties */
465 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
466 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
467 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
468 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
469 	    "<size> | none", "RESERV");
470 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
471 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
472 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
473 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
474 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
475 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
476 	    "<size> | none", "REFRESERV");
477 	zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
478 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
479 	    "<count> | none", "FSLIMIT");
480 	zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
481 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
482 	    "<count> | none", "SSLIMIT");
483 
484 	/* inherit number properties */
485 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
486 	    SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
487 	    ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
488 	zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
489 	    "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
490 	    "zero or 512 to 128K, power of 2", "SPECIAL_SMALL_BLOCKS");
491 
492 	/* hidden properties */
493 	zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
494 	    PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG");
495 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
496 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
497 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
498 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
499 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
500 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
501 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
502 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
503 	    "STMF_SBD_LU");
504 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
505 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
506 	    "USERACCOUNTING");
507 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
508 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
509 	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
510 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
511 	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
512 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
513 	zprop_register_hidden(ZFS_PROP_IVSET_GUID, "ivsetguid",
514 	    PROP_TYPE_NUMBER, PROP_READONLY,
515 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "IVSETGUID");
516 	zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
517 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
518 	zprop_register_hidden(ZFS_PROP_PBKDF2_SALT, "pbkdf2salt",
519 	    PROP_TYPE_NUMBER, PROP_ONETIME_DEFAULT,
520 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PBKDF2SALT");
521 	zprop_register_hidden(ZFS_PROP_KEY_GUID, "keyguid", PROP_TYPE_NUMBER,
522 	    PROP_READONLY, ZFS_TYPE_DATASET, "KEYGUID");
523 
524 	/* oddball properties */
525 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
526 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
527 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
528 }
529 
530 boolean_t
531 zfs_prop_delegatable(zfs_prop_t prop)
532 {
533 	zprop_desc_t *pd = &zfs_prop_table[prop];
534 
535 	/* The mlslabel property is never delegatable. */
536 	if (prop == ZFS_PROP_MLSLABEL)
537 		return (B_FALSE);
538 
539 	return (pd->pd_attr != PROP_READONLY);
540 }
541 
542 /*
543  * Given a zfs dataset property name, returns the corresponding property ID.
544  */
545 zfs_prop_t
546 zfs_name_to_prop(const char *propname)
547 {
548 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
549 }
550 
551 /*
552  * For user property names, we allow all lowercase alphanumeric characters, plus
553  * a few useful punctuation characters.
554  */
555 static int
556 valid_char(char c)
557 {
558 	return ((c >= 'a' && c <= 'z') ||
559 	    (c >= '0' && c <= '9') ||
560 	    c == '-' || c == '_' || c == '.' || c == ':');
561 }
562 
563 /*
564  * Returns true if this is a valid user-defined property (one with a ':').
565  */
566 boolean_t
567 zfs_prop_user(const char *name)
568 {
569 	int i;
570 	char c;
571 	boolean_t foundsep = B_FALSE;
572 
573 	for (i = 0; i < strlen(name); i++) {
574 		c = name[i];
575 		if (!valid_char(c))
576 			return (B_FALSE);
577 		if (c == ':')
578 			foundsep = B_TRUE;
579 	}
580 
581 	if (!foundsep)
582 		return (B_FALSE);
583 
584 	return (B_TRUE);
585 }
586 
587 /*
588  * Returns true if this is a valid userspace-type property (one with a '@').
589  * Note that after the @, any character is valid (eg, another @, for SID
590  * user@domain).
591  */
592 boolean_t
593 zfs_prop_userquota(const char *name)
594 {
595 	zfs_userquota_prop_t prop;
596 
597 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
598 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
599 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
600 			return (B_TRUE);
601 		}
602 	}
603 
604 	return (B_FALSE);
605 }
606 
607 /*
608  * Returns true if this is a valid written@ property.
609  * Note that after the @, any character is valid (eg, another @, for
610  * written@pool/fs@origin).
611  */
612 boolean_t
613 zfs_prop_written(const char *name)
614 {
615 	static const char *prefix = "written@";
616 	return (strncmp(name, prefix, strlen(prefix)) == 0);
617 }
618 
619 /*
620  * Tables of index types, plus functions to convert between the user view
621  * (strings) and internal representation (uint64_t).
622  */
623 int
624 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
625 {
626 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
627 }
628 
629 int
630 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
631 {
632 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
633 }
634 
635 uint64_t
636 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
637 {
638 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
639 }
640 
641 /*
642  * Returns TRUE if the property applies to any of the given dataset types.
643  */
644 boolean_t
645 zfs_prop_valid_for_type(int prop, zfs_type_t types)
646 {
647 	return (zprop_valid_for_type(prop, types));
648 }
649 
650 zprop_type_t
651 zfs_prop_get_type(zfs_prop_t prop)
652 {
653 	return (zfs_prop_table[prop].pd_proptype);
654 }
655 
656 /*
657  * Returns TRUE if the property is readonly.
658  */
659 boolean_t
660 zfs_prop_readonly(zfs_prop_t prop)
661 {
662 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
663 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
664 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
665 }
666 
667 /*
668  * Returns TRUE if the property is visible (not hidden).
669  */
670 boolean_t
671 zfs_prop_visible(zfs_prop_t prop)
672 {
673 	return (zfs_prop_table[prop].pd_visible);
674 }
675 
676 /*
677  * Returns TRUE if the property is only allowed to be set once.
678  */
679 boolean_t
680 zfs_prop_setonce(zfs_prop_t prop)
681 {
682 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
683 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
684 }
685 
686 const char *
687 zfs_prop_default_string(zfs_prop_t prop)
688 {
689 	return (zfs_prop_table[prop].pd_strdefault);
690 }
691 
692 uint64_t
693 zfs_prop_default_numeric(zfs_prop_t prop)
694 {
695 	return (zfs_prop_table[prop].pd_numdefault);
696 }
697 
698 /*
699  * Given a dataset property ID, returns the corresponding name.
700  * Assuming the zfs dataset property ID is valid.
701  */
702 const char *
703 zfs_prop_to_name(zfs_prop_t prop)
704 {
705 	return (zfs_prop_table[prop].pd_name);
706 }
707 
708 /*
709  * Returns TRUE if the property is inheritable.
710  */
711 boolean_t
712 zfs_prop_inheritable(zfs_prop_t prop)
713 {
714 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
715 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
716 }
717 
718 /*
719  * Returns TRUE if property is one of the encryption properties that requires
720  * a loaded encryption key to modify.
721  */
722 boolean_t
723 zfs_prop_encryption_key_param(zfs_prop_t prop)
724 {
725 	/*
726 	 * keylocation does not count as an encryption property. It can be
727 	 * changed at will without needing the master keys.
728 	 */
729 	return (prop == ZFS_PROP_PBKDF2_SALT || prop == ZFS_PROP_PBKDF2_ITERS ||
730 	    prop == ZFS_PROP_KEYFORMAT);
731 }
732 
733 /*
734  * Helper function used by both kernelspace and userspace to check the
735  * keylocation property. If encrypted is set, the keylocation must be valid
736  * for an encrypted dataset.
737  */
738 boolean_t
739 zfs_prop_valid_keylocation(const char *str, boolean_t encrypted)
740 {
741 	if (strcmp("none", str) == 0)
742 		return (!encrypted);
743 	else if (strcmp("prompt", str) == 0)
744 		return (B_TRUE);
745 	else if (strlen(str) > 8 && strncmp("file:///", str, 8) == 0)
746 		return (B_TRUE);
747 
748 	return (B_FALSE);
749 }
750 
751 
752 #ifndef _KERNEL
753 
754 /*
755  * Returns a string describing the set of acceptable values for the given
756  * zfs property, or NULL if it cannot be set.
757  */
758 const char *
759 zfs_prop_values(zfs_prop_t prop)
760 {
761 	return (zfs_prop_table[prop].pd_values);
762 }
763 
764 /*
765  * Returns TRUE if this property is a string type.  Note that index types
766  * (compression, checksum) are treated as strings in userland, even though they
767  * are stored numerically on disk.
768  */
769 int
770 zfs_prop_is_string(zfs_prop_t prop)
771 {
772 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
773 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
774 }
775 
776 /*
777  * Returns the column header for the given property.  Used only in
778  * 'zfs list -o', but centralized here with the other property information.
779  */
780 const char *
781 zfs_prop_column_name(zfs_prop_t prop)
782 {
783 	return (zfs_prop_table[prop].pd_colname);
784 }
785 
786 /*
787  * Returns whether the given property should be displayed right-justified for
788  * 'zfs list'.
789  */
790 boolean_t
791 zfs_prop_align_right(zfs_prop_t prop)
792 {
793 	return (zfs_prop_table[prop].pd_rightalign);
794 }
795 
796 #endif
797