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