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