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