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