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