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