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