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