xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision 663207adb1669640c01c5ec6949ce78fd806efae)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5906d120cSlling  * Common Development and Distribution License (the "License").
6906d120cSlling  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
2227dd1e87SMark Shellenbaum  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23dfc11533SChris Williamson  * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
24a6f561b4SSašo Kiselkov  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
26007a6c1fSJerry Jelinek  * Copyright 2016, Joyent, Inc.
27fa9e4066Sahrens  */
28fa9e4066Sahrens 
2955da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
3055da60b9SMark J Musante 
31fa9e4066Sahrens #include <sys/zio.h>
32fa9e4066Sahrens #include <sys/spa.h>
33de8267e0Stimh #include <sys/u8_textprep.h>
34fa9e4066Sahrens #include <sys/zfs_acl.h>
35fa9e4066Sahrens #include <sys/zfs_ioctl.h>
36e7437265Sahrens #include <sys/zfs_znode.h>
37fa9e4066Sahrens 
38fa9e4066Sahrens #include "zfs_prop.h"
39ecd6cf80Smarks #include "zfs_deleg.h"
40fa9e4066Sahrens 
41fa9e4066Sahrens #if defined(_KERNEL)
42fa9e4066Sahrens #include <sys/systm.h>
43fa9e4066Sahrens #else
44fa9e4066Sahrens #include <stdlib.h>
45fa9e4066Sahrens #include <string.h>
46fa9e4066Sahrens #include <ctype.h>
47fa9e4066Sahrens #endif
48fa9e4066Sahrens 
49990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
5091ebeef5Sahrens 
5114843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
5214843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = {
5314843421SMatthew Ahrens 	"userused@",
5414843421SMatthew Ahrens 	"userquota@",
5514843421SMatthew Ahrens 	"groupused@",
5614843421SMatthew Ahrens 	"groupquota@"
5714843421SMatthew Ahrens };
5814843421SMatthew Ahrens 
59990b4856Slling zprop_desc_t *
60990b4856Slling zfs_prop_get_table(void)
6191ebeef5Sahrens {
62990b4856Slling 	return (zfs_prop_table);
6391ebeef5Sahrens }
6491ebeef5Sahrens 
6591ebeef5Sahrens void
6691ebeef5Sahrens zfs_prop_init(void)
6791ebeef5Sahrens {
68990b4856Slling 	static zprop_index_t checksum_table[] = {
6991ebeef5Sahrens 		{ "on",		ZIO_CHECKSUM_ON },
7091ebeef5Sahrens 		{ "off",	ZIO_CHECKSUM_OFF },
7191ebeef5Sahrens 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
7291ebeef5Sahrens 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
7391ebeef5Sahrens 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
74810e43b2SBill Pijewski 		{ "noparity",	ZIO_CHECKSUM_NOPARITY },
7545818ee1SMatthew Ahrens 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
7645818ee1SMatthew Ahrens 		{ "skein",	ZIO_CHECKSUM_SKEIN },
7745818ee1SMatthew Ahrens 		{ "edonr",	ZIO_CHECKSUM_EDONR },
7891ebeef5Sahrens 		{ NULL }
7991ebeef5Sahrens 	};
8091ebeef5Sahrens 
81b24ab676SJeff Bonwick 	static zprop_index_t dedup_table[] = {
82b24ab676SJeff Bonwick 		{ "on",		ZIO_CHECKSUM_ON },
83b24ab676SJeff Bonwick 		{ "off",	ZIO_CHECKSUM_OFF },
84b24ab676SJeff Bonwick 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
85b24ab676SJeff Bonwick 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
86b24ab676SJeff Bonwick 		{ "sha256,verify",
87b24ab676SJeff Bonwick 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
8845818ee1SMatthew Ahrens 		{ "sha512",	ZIO_CHECKSUM_SHA512 },
8945818ee1SMatthew Ahrens 		{ "sha512,verify",
9045818ee1SMatthew Ahrens 				ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
9145818ee1SMatthew Ahrens 		{ "skein",	ZIO_CHECKSUM_SKEIN },
9245818ee1SMatthew Ahrens 		{ "skein,verify",
9345818ee1SMatthew Ahrens 				ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
9445818ee1SMatthew Ahrens 		{ "edonr,verify",
9545818ee1SMatthew Ahrens 				ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
96b24ab676SJeff Bonwick 		{ NULL }
97b24ab676SJeff Bonwick 	};
98b24ab676SJeff Bonwick 
99990b4856Slling 	static zprop_index_t compress_table[] = {
10091ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
10191ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
10291ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
10391ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
10491ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
10591ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
10691ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
10791ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
10891ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
10991ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
11091ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
11191ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
11291ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
113b24ab676SJeff Bonwick 		{ "zle",	ZIO_COMPRESS_ZLE },
114a6f561b4SSašo Kiselkov 		{ "lz4",	ZIO_COMPRESS_LZ4 },
11591ebeef5Sahrens 		{ NULL }
11691ebeef5Sahrens 	};
11791ebeef5Sahrens 
118990b4856Slling 	static zprop_index_t snapdir_table[] = {
11991ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
12091ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
12191ebeef5Sahrens 		{ NULL }
12291ebeef5Sahrens 	};
12391ebeef5Sahrens 
124a3c49ce1SAlbert Lee 	static zprop_index_t acl_mode_table[] = {
125a3c49ce1SAlbert Lee 		{ "discard",	ZFS_ACL_DISCARD },
126a3c49ce1SAlbert Lee 		{ "groupmask",	ZFS_ACL_GROUPMASK },
127a3c49ce1SAlbert Lee 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
12871dbfc28SPaul B. Henson 		{ "restricted", ZFS_ACL_RESTRICTED },
129a3c49ce1SAlbert Lee 		{ NULL }
130a3c49ce1SAlbert Lee 	};
131a3c49ce1SAlbert Lee 
132990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
13391ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
13491ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
135b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
13691ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
137b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
138d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
13991ebeef5Sahrens 		{ NULL }
14091ebeef5Sahrens 	};
14191ebeef5Sahrens 
142da6c28aaSamw 	static zprop_index_t case_table[] = {
143da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
144da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
145da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
146da6c28aaSamw 		{ NULL }
147da6c28aaSamw 	};
148da6c28aaSamw 
149990b4856Slling 	static zprop_index_t copies_table[] = {
15091ebeef5Sahrens 		{ "1",		1 },
15191ebeef5Sahrens 		{ "2",		2 },
15291ebeef5Sahrens 		{ "3",		3 },
15391ebeef5Sahrens 		{ NULL }
15491ebeef5Sahrens 	};
15591ebeef5Sahrens 
156de8267e0Stimh 	/*
157de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
158de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
159de8267e0Stimh 	 * values.
160de8267e0Stimh 	 */
161da6c28aaSamw 	static zprop_index_t normalize_table[] = {
162de8267e0Stimh 		{ "none",	0 },
163de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
164de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
165de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
166de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
167da6c28aaSamw 		{ NULL }
168da6c28aaSamw 	};
169da6c28aaSamw 
170990b4856Slling 	static zprop_index_t version_table[] = {
17191ebeef5Sahrens 		{ "1",		1 },
17291ebeef5Sahrens 		{ "2",		2 },
173da6c28aaSamw 		{ "3",		3 },
17414843421SMatthew Ahrens 		{ "4",		4 },
1750a586ceaSMark Shellenbaum 		{ "5",		5 },
17691ebeef5Sahrens 		{ "current",	ZPL_VERSION },
17791ebeef5Sahrens 		{ NULL }
17891ebeef5Sahrens 	};
17991ebeef5Sahrens 
180990b4856Slling 	static zprop_index_t boolean_table[] = {
181e45ce728Sahrens 		{ "off",	0 },
182e45ce728Sahrens 		{ "on",		1 },
183e45ce728Sahrens 		{ NULL }
184e45ce728Sahrens 	};
185e45ce728Sahrens 
186e09fa4daSNeil Perrin 	static zprop_index_t logbias_table[] = {
187e09fa4daSNeil Perrin 		{ "latency",	ZFS_LOGBIAS_LATENCY },
188e09fa4daSNeil Perrin 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
189e09fa4daSNeil Perrin 		{ NULL }
190e09fa4daSNeil Perrin 	};
191e09fa4daSNeil Perrin 
192a227b7f4Shs 	static zprop_index_t canmount_table[] = {
193a227b7f4Shs 		{ "off",	ZFS_CANMOUNT_OFF },
194a227b7f4Shs 		{ "on",		ZFS_CANMOUNT_ON },
195a227b7f4Shs 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
196a227b7f4Shs 		{ NULL }
197a227b7f4Shs 	};
198a227b7f4Shs 
1993baa08fcSek 	static zprop_index_t cache_table[] = {
2003baa08fcSek 		{ "none",	ZFS_CACHE_NONE },
2013baa08fcSek 		{ "metadata",	ZFS_CACHE_METADATA },
2023baa08fcSek 		{ "all",	ZFS_CACHE_ALL },
2033baa08fcSek 		{ NULL }
2043baa08fcSek 	};
2053baa08fcSek 
20655da60b9SMark J Musante 	static zprop_index_t sync_table[] = {
20755da60b9SMark J Musante 		{ "standard",	ZFS_SYNC_STANDARD },
20855da60b9SMark J Musante 		{ "always",	ZFS_SYNC_ALWAYS },
20955da60b9SMark J Musante 		{ "disabled",	ZFS_SYNC_DISABLED },
21055da60b9SMark J Musante 		{ NULL }
21155da60b9SMark J Musante 	};
21255da60b9SMark J Musante 
21354811da5SToomas Soome 	static zprop_index_t dnsize_table[] = {
21454811da5SToomas Soome 		{ "legacy",	ZFS_DNSIZE_LEGACY },
21554811da5SToomas Soome 		{ "auto",	ZFS_DNSIZE_AUTO },
21654811da5SToomas Soome 		{ "1k",		ZFS_DNSIZE_1K },
21754811da5SToomas Soome 		{ "2k",		ZFS_DNSIZE_2K },
21854811da5SToomas Soome 		{ "4k",		ZFS_DNSIZE_4K },
21954811da5SToomas Soome 		{ "8k",		ZFS_DNSIZE_8K },
22054811da5SToomas Soome 		{ "16k",	ZFS_DNSIZE_16K },
22154811da5SToomas Soome 		{ NULL }
22254811da5SToomas Soome 	};
22354811da5SToomas Soome 
224edf345e6SMatthew Ahrens 	static zprop_index_t redundant_metadata_table[] = {
225edf345e6SMatthew Ahrens 		{ "all",	ZFS_REDUNDANT_METADATA_ALL },
226edf345e6SMatthew Ahrens 		{ "most",	ZFS_REDUNDANT_METADATA_MOST },
227edf345e6SMatthew Ahrens 		{ NULL }
228edf345e6SMatthew Ahrens 	};
229edf345e6SMatthew Ahrens 
23091ebeef5Sahrens 	/* inherit index properties */
231edf345e6SMatthew Ahrens 	zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
232edf345e6SMatthew Ahrens 	    ZFS_REDUNDANT_METADATA_ALL,
233edf345e6SMatthew Ahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
234edf345e6SMatthew Ahrens 	    "all | most", "REDUND_MD",
235edf345e6SMatthew Ahrens 	    redundant_metadata_table);
23655da60b9SMark J Musante 	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
23755da60b9SMark J Musante 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
23855da60b9SMark J Musante 	    "standard | always | disabled", "SYNC",
23955da60b9SMark J Musante 	    sync_table);
24083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
24183d7f9feSTom Erickson 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
24283d7f9feSTom Erickson 	    ZFS_TYPE_VOLUME,
24345818ee1SMatthew Ahrens 	    "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
24445818ee1SMatthew Ahrens 	    "skein | edonr", "CHECKSUM", checksum_table);
24583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
246b24ab676SJeff Bonwick 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
24745818ee1SMatthew Ahrens 	    "on | off | verify | sha256[,verify], sha512[,verify], "
24845818ee1SMatthew Ahrens 	    "skein[,verify], edonr,verify", "DEDUP", dedup_table);
24983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
250e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
251e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
252a6f561b4SSašo Kiselkov 	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
253a6f561b4SSašo Kiselkov 	    "COMPRESS", compress_table);
25483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
255e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
256e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
257a3c49ce1SAlbert Lee 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
258a3c49ce1SAlbert Lee 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
25971dbfc28SPaul B. Henson 	    "discard | groupmask | passthrough | restricted", "ACLMODE",
26071dbfc28SPaul B. Henson 	    acl_mode_table);
26183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
26283d7f9feSTom Erickson 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
263d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
264b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
26583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
26683d7f9feSTom Erickson 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
26791ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
26883d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
2693baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2703baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2713baa08fcSek 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
27283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
2733baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2743baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2753baa08fcSek 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
27683d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
277e09fa4daSNeil Perrin 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
278e09fa4daSNeil Perrin 	    "latency | throughput", "LOGBIAS", logbias_table);
27954811da5SToomas Soome 
28054811da5SToomas Soome 	zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
28154811da5SToomas Soome 	    ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
28254811da5SToomas Soome 	    "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
283e45ce728Sahrens 
284e45ce728Sahrens 	/* inherit index (boolean) properties */
28583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
286e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
28783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
288e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
289e45ce728Sahrens 	    boolean_table);
29083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
291e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
292e45ce728Sahrens 	    boolean_table);
29383d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
294e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
295e45ce728Sahrens 	    boolean_table);
29683d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
297e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
298e45ce728Sahrens 	    boolean_table);
29983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
300e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
30183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
302e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
303e45ce728Sahrens 	    boolean_table);
30483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
305da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
306da6c28aaSamw 	    boolean_table);
30783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
308da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
309da6c28aaSamw 	    boolean_table);
310e45ce728Sahrens 
311e45ce728Sahrens 	/* default index properties */
31283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
3137b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
31419b94df9SMatthew Ahrens 	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
31583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
316a227b7f4Shs 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
317a227b7f4Shs 	    "CANMOUNT", canmount_table);
318e45ce728Sahrens 
319e45ce728Sahrens 	/* readonly index (boolean) properties */
32083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
321990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
32283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
323842727c2SChris Kirby 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
324842727c2SChris Kirby 	    boolean_table);
325e45ce728Sahrens 
326da6c28aaSamw 	/* set once index properties */
32783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
328da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
329da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
330da6c28aaSamw 	    normalize_table);
33183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
33283d7f9feSTom Erickson 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
33383d7f9feSTom Erickson 	    ZFS_TYPE_SNAPSHOT,
334da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
335da6c28aaSamw 
336da6c28aaSamw 	/* set once index (boolean) properties */
33783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
338da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
339da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
340da6c28aaSamw 
34191ebeef5Sahrens 	/* string properties */
34283d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
34391ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
34419b94df9SMatthew Ahrens 	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
34519b94df9SMatthew Ahrens 	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
34683d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
34783d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
34883d7f9feSTom Erickson 	    "MOUNTPOINT");
34983d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
35083d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
35183d7f9feSTom Erickson 	    "SHARENFS");
35283d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
35378f17100SMatthew Ahrens 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
35478f17100SMatthew Ahrens 	    "filesystem | volume | snapshot | bookmark", "TYPE");
35583d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
35683d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
35783d7f9feSTom Erickson 	    "on | off | sharemgr(1M) options", "SHARESMB");
35883d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
35983d7f9feSTom Erickson 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
36083d7f9feSTom Erickson 	    "<sensitivity label>", "MLSLABEL");
3619c3fd121SMatthew Ahrens 	zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
3629c3fd121SMatthew Ahrens 	    "receive_resume_token",
3639c3fd121SMatthew Ahrens 	    NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
3649c3fd121SMatthew Ahrens 	    "<string token>", "RESUMETOK");
36591ebeef5Sahrens 
36691ebeef5Sahrens 	/* readonly number properties */
36783d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
368990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
36983d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
370990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
37183d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
37283d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
37383d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
374990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
37591ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
376187d6ac0SMatt Ahrens 	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
377187d6ac0SMatt Ahrens 	    PROP_READONLY, ZFS_TYPE_DATASET,
378187d6ac0SMatt Ahrens 	    "<1.00x or higher if compressed>", "REFRATIO");
37983d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
380c1449561SEric Taylor 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
381da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
38283d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
38383d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
38483d7f9feSTom Erickson 	    "USEDSNAP");
38583d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
38683d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
38783d7f9feSTom Erickson 	    "USEDDS");
38883d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
38983d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
39083d7f9feSTom Erickson 	    "USEDCHILD");
39183d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
39274e7dc98SMatthew Ahrens 	    PROP_READONLY,
39374e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
39483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
395842727c2SChris Kirby 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
39619b94df9SMatthew Ahrens 	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
39719b94df9SMatthew Ahrens 	    ZFS_TYPE_DATASET, "<size>", "WRITTEN");
39877372cb0SMatthew Ahrens 	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
399dfc11533SChris Williamson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
400dfc11533SChris Williamson 	    "LUSED");
40177372cb0SMatthew Ahrens 	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
40277372cb0SMatthew Ahrens 	    0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
403007a6c1fSJerry Jelinek 	zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
404007a6c1fSJerry Jelinek 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
405007a6c1fSJerry Jelinek 	    "<count>", "FSCOUNT");
406007a6c1fSJerry Jelinek 	zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
407007a6c1fSJerry Jelinek 	    UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
408007a6c1fSJerry Jelinek 	    "<count>", "SSCOUNT");
409e8d4a73cSJosh Paetzel 	zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
410e8d4a73cSJosh Paetzel 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
411e8d4a73cSJosh Paetzel 	zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
412e8d4a73cSJosh Paetzel 	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
41391ebeef5Sahrens 
41491ebeef5Sahrens 	/* default number properties */
41583d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
41691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
41783d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
41883d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
41983d7f9feSTom Erickson 	    "<size> | none", "RESERV");
42083d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
42191ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
42283d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
423a9799022Sck 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
42483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
425a9799022Sck 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
426a9799022Sck 	    "<size> | none", "REFRESERV");
427a2afb611SJerry Jelinek 	zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
428a2afb611SJerry Jelinek 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
429a2afb611SJerry Jelinek 	    "<count> | none", "FSLIMIT");
430a2afb611SJerry Jelinek 	zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
431a2afb611SJerry Jelinek 	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
432a2afb611SJerry Jelinek 	    "<count> | none", "SSLIMIT");
43391ebeef5Sahrens 
43491ebeef5Sahrens 	/* inherit number properties */
43583d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
436b5152584SMatthew Ahrens 	    SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
437b5152584SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
438*663207adSDon Brady 	zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS,
439*663207adSDon Brady 	    "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
440*663207adSDon Brady 	    "zero or 512 to 128K, power of 2", "SPECIAL_SMALL_BLOCKS");
44191ebeef5Sahrens 
44291ebeef5Sahrens 	/* hidden properties */
4435cabbc6bSPrashanth Sreenivasa 	zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
4445cabbc6bSPrashanth Sreenivasa 	    PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG");
44583d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
446b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
44783d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
44878f17100SMatthew Ahrens 	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
44983d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
45083d7f9feSTom Erickson 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
45183d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
452478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
453478ed9adSEric Taylor 	    "STMF_SBD_LU");
45483d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
455b24ab676SJeff Bonwick 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
456b24ab676SJeff Bonwick 	    "USERACCOUNTING");
45783d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
458b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
45983d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
4601d713200SEric Schrock 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
461ca48f36fSKeith M Wesolowski 	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
462ca48f36fSKeith M Wesolowski 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
463b461c746SMatthew Ahrens 	zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
464b461c746SMatthew Ahrens 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
46591ebeef5Sahrens 
46691ebeef5Sahrens 	/* oddball properties */
46783d7f9feSTom Erickson 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
46878f17100SMatthew Ahrens 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
46991ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
47091ebeef5Sahrens }
47191ebeef5Sahrens 
472b1b8ab34Slling boolean_t
473990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
474fa9e4066Sahrens {
475990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
4764201a95eSRic Aleshire 
4774201a95eSRic Aleshire 	/* The mlslabel property is never delegatable. */
4784201a95eSRic Aleshire 	if (prop == ZFS_PROP_MLSLABEL)
4794201a95eSRic Aleshire 		return (B_FALSE);
4804201a95eSRic Aleshire 
481990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
482fa9e4066Sahrens }
483fa9e4066Sahrens 
484b1b8ab34Slling /*
485b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
486b1b8ab34Slling  */
487b1b8ab34Slling zfs_prop_t
488b1b8ab34Slling zfs_name_to_prop(const char *propname)
489b1b8ab34Slling {
490990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
491b1b8ab34Slling }
492b1b8ab34Slling 
493e9dbad6fSeschrock /*
494e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
495e9dbad6fSeschrock  * a few useful punctuation characters.
496e9dbad6fSeschrock  */
497e9dbad6fSeschrock static int
498e9dbad6fSeschrock valid_char(char c)
499e9dbad6fSeschrock {
500e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
501e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
502e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
503e9dbad6fSeschrock }
504e9dbad6fSeschrock 
505e9dbad6fSeschrock /*
506e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
507e9dbad6fSeschrock  */
508e9dbad6fSeschrock boolean_t
509e9dbad6fSeschrock zfs_prop_user(const char *name)
510e9dbad6fSeschrock {
511e9dbad6fSeschrock 	int i;
512e9dbad6fSeschrock 	char c;
513e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
514e9dbad6fSeschrock 
515e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
516e9dbad6fSeschrock 		c = name[i];
517e9dbad6fSeschrock 		if (!valid_char(c))
518e9dbad6fSeschrock 			return (B_FALSE);
519e9dbad6fSeschrock 		if (c == ':')
520e9dbad6fSeschrock 			foundsep = B_TRUE;
521e9dbad6fSeschrock 	}
522e9dbad6fSeschrock 
523e9dbad6fSeschrock 	if (!foundsep)
524e9dbad6fSeschrock 		return (B_FALSE);
525e9dbad6fSeschrock 
526e9dbad6fSeschrock 	return (B_TRUE);
527e9dbad6fSeschrock }
528e9dbad6fSeschrock 
52914843421SMatthew Ahrens /*
53014843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
53114843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
53214843421SMatthew Ahrens  * user@domain).
53314843421SMatthew Ahrens  */
53414843421SMatthew Ahrens boolean_t
53514843421SMatthew Ahrens zfs_prop_userquota(const char *name)
53614843421SMatthew Ahrens {
53714843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
53814843421SMatthew Ahrens 
53914843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
54014843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
54114843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
54214843421SMatthew Ahrens 			return (B_TRUE);
54314843421SMatthew Ahrens 		}
54414843421SMatthew Ahrens 	}
54514843421SMatthew Ahrens 
54614843421SMatthew Ahrens 	return (B_FALSE);
54714843421SMatthew Ahrens }
54814843421SMatthew Ahrens 
54919b94df9SMatthew Ahrens /*
55019b94df9SMatthew Ahrens  * Returns true if this is a valid written@ property.
55119b94df9SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for
55219b94df9SMatthew Ahrens  * written@pool/fs@origin).
55319b94df9SMatthew Ahrens  */
55419b94df9SMatthew Ahrens boolean_t
55519b94df9SMatthew Ahrens zfs_prop_written(const char *name)
55619b94df9SMatthew Ahrens {
55719b94df9SMatthew Ahrens 	static const char *prefix = "written@";
55819b94df9SMatthew Ahrens 	return (strncmp(name, prefix, strlen(prefix)) == 0);
55919b94df9SMatthew Ahrens }
56019b94df9SMatthew Ahrens 
561fa9e4066Sahrens /*
562990b4856Slling  * Tables of index types, plus functions to convert between the user view
563990b4856Slling  * (strings) and internal representation (uint64_t).
564fa9e4066Sahrens  */
565990b4856Slling int
566990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
567fa9e4066Sahrens {
568990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
569fa9e4066Sahrens }
570fa9e4066Sahrens 
571990b4856Slling int
572990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
5733d7072f8Seschrock {
574990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
5753d7072f8Seschrock }
5763d7072f8Seschrock 
577b24ab676SJeff Bonwick uint64_t
578b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
579b24ab676SJeff Bonwick {
580b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
581b24ab676SJeff Bonwick }
582b24ab676SJeff Bonwick 
583990b4856Slling /*
584990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
585990b4856Slling  */
5864853e976Sgw boolean_t
587990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
588fa9e4066Sahrens {
589990b4856Slling 	return (zprop_valid_for_type(prop, types));
590fa9e4066Sahrens }
591fa9e4066Sahrens 
592990b4856Slling zprop_type_t
593990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
5943d7072f8Seschrock {
595990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
5963d7072f8Seschrock }
5973d7072f8Seschrock 
598fa9e4066Sahrens /*
599fa9e4066Sahrens  * Returns TRUE if the property is readonly.
600fa9e4066Sahrens  */
601990b4856Slling boolean_t
602fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
603fa9e4066Sahrens {
604da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
605da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
606da6c28aaSamw }
607da6c28aaSamw 
608dfc11533SChris Williamson /*
609dfc11533SChris Williamson  * Returns TRUE if the property is visible (not hidden).
610dfc11533SChris Williamson  */
611dfc11533SChris Williamson boolean_t
612dfc11533SChris Williamson zfs_prop_visible(zfs_prop_t prop)
613dfc11533SChris Williamson {
614dfc11533SChris Williamson 	return (zfs_prop_table[prop].pd_visible);
615dfc11533SChris Williamson }
616dfc11533SChris Williamson 
617da6c28aaSamw /*
618da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
619da6c28aaSamw  */
620da6c28aaSamw boolean_t
621da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
622da6c28aaSamw {
623da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
624fa9e4066Sahrens }
625fa9e4066Sahrens 
626fa9e4066Sahrens const char *
627990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
628fa9e4066Sahrens {
629990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
630990b4856Slling }
631990b4856Slling 
632990b4856Slling uint64_t
633990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
634990b4856Slling {
635990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
636fa9e4066Sahrens }
637fa9e4066Sahrens 
638b1b8ab34Slling /*
639990b4856Slling  * Given a dataset property ID, returns the corresponding name.
640990b4856Slling  * Assuming the zfs dataset property ID is valid.
641b1b8ab34Slling  */
642b1b8ab34Slling const char *
643990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
644b1b8ab34Slling {
645b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
646b1b8ab34Slling }
647b1b8ab34Slling 
648fa9e4066Sahrens /*
649fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
650fa9e4066Sahrens  */
651990b4856Slling boolean_t
652fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
653fa9e4066Sahrens {
654da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
655da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
656e9dbad6fSeschrock }
657e9dbad6fSeschrock 
658acd76fe5Seschrock #ifndef _KERNEL
659acd76fe5Seschrock 
660fa9e4066Sahrens /*
661b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
662b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
663fa9e4066Sahrens  */
664b1b8ab34Slling const char *
665b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
666fa9e4066Sahrens {
667fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
668fa9e4066Sahrens }
669fa9e4066Sahrens 
670fa9e4066Sahrens /*
671fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
672fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
673fa9e4066Sahrens  * are stored numerically on disk.
674fa9e4066Sahrens  */
675fa9e4066Sahrens int
676fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
677fa9e4066Sahrens {
67891ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
67991ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
680fa9e4066Sahrens }
681fa9e4066Sahrens 
682fa9e4066Sahrens /*
683fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
684fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
685fa9e4066Sahrens  */
686fa9e4066Sahrens const char *
687fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
688fa9e4066Sahrens {
689fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
690fa9e4066Sahrens }
691fa9e4066Sahrens 
692fa9e4066Sahrens /*
693e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
694e9dbad6fSeschrock  * 'zfs list'.
695fa9e4066Sahrens  */
696e9dbad6fSeschrock boolean_t
697e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
698fa9e4066Sahrens {
699e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
700fa9e4066Sahrens }
701da6c28aaSamw 
702fa9e4066Sahrens #endif
703