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