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