xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision 27dd1e87cd3d939264769dd4af7e6a529cde001f)
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 /*
22*27dd1e87SMark Shellenbaum  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23fa9e4066Sahrens  */
24fa9e4066Sahrens 
25fa9e4066Sahrens #include <sys/zio.h>
26fa9e4066Sahrens #include <sys/spa.h>
27de8267e0Stimh #include <sys/u8_textprep.h>
28fa9e4066Sahrens #include <sys/zfs_acl.h>
29fa9e4066Sahrens #include <sys/zfs_ioctl.h>
30e7437265Sahrens #include <sys/zfs_znode.h>
31fa9e4066Sahrens 
32fa9e4066Sahrens #include "zfs_prop.h"
33ecd6cf80Smarks #include "zfs_deleg.h"
34fa9e4066Sahrens 
35fa9e4066Sahrens #if defined(_KERNEL)
36fa9e4066Sahrens #include <sys/systm.h>
37fa9e4066Sahrens #else
38fa9e4066Sahrens #include <stdlib.h>
39fa9e4066Sahrens #include <string.h>
40fa9e4066Sahrens #include <ctype.h>
41fa9e4066Sahrens #endif
42fa9e4066Sahrens 
43990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
4491ebeef5Sahrens 
4514843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
4614843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = {
4714843421SMatthew Ahrens 	"userused@",
4814843421SMatthew Ahrens 	"userquota@",
4914843421SMatthew Ahrens 	"groupused@",
5014843421SMatthew Ahrens 	"groupquota@"
5114843421SMatthew Ahrens };
5214843421SMatthew Ahrens 
53990b4856Slling zprop_desc_t *
54990b4856Slling zfs_prop_get_table(void)
5591ebeef5Sahrens {
56990b4856Slling 	return (zfs_prop_table);
5791ebeef5Sahrens }
5891ebeef5Sahrens 
5991ebeef5Sahrens void
6091ebeef5Sahrens zfs_prop_init(void)
6191ebeef5Sahrens {
62990b4856Slling 	static zprop_index_t checksum_table[] = {
6391ebeef5Sahrens 		{ "on",		ZIO_CHECKSUM_ON },
6491ebeef5Sahrens 		{ "off",	ZIO_CHECKSUM_OFF },
6591ebeef5Sahrens 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
6691ebeef5Sahrens 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
6791ebeef5Sahrens 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
6891ebeef5Sahrens 		{ NULL }
6991ebeef5Sahrens 	};
7091ebeef5Sahrens 
71b24ab676SJeff Bonwick 	static zprop_index_t dedup_table[] = {
72b24ab676SJeff Bonwick 		{ "on",		ZIO_CHECKSUM_ON },
73b24ab676SJeff Bonwick 		{ "off",	ZIO_CHECKSUM_OFF },
74b24ab676SJeff Bonwick 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
75b24ab676SJeff Bonwick 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
76b24ab676SJeff Bonwick 		{ "sha256,verify",
77b24ab676SJeff Bonwick 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
78b24ab676SJeff Bonwick 		{ NULL }
79b24ab676SJeff Bonwick 	};
80b24ab676SJeff Bonwick 
81990b4856Slling 	static zprop_index_t compress_table[] = {
8291ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
8391ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
8491ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
8591ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
8691ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
8791ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
8891ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
8991ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
9091ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
9191ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
9291ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
9391ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
9491ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
95b24ab676SJeff Bonwick 		{ "zle",	ZIO_COMPRESS_ZLE },
9691ebeef5Sahrens 		{ NULL }
9791ebeef5Sahrens 	};
9891ebeef5Sahrens 
99990b4856Slling 	static zprop_index_t snapdir_table[] = {
10091ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
10191ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
10291ebeef5Sahrens 		{ NULL }
10391ebeef5Sahrens 	};
10491ebeef5Sahrens 
105990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
10691ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
10791ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
108b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
10991ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
110b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
111d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
11291ebeef5Sahrens 		{ NULL }
11391ebeef5Sahrens 	};
11491ebeef5Sahrens 
115da6c28aaSamw 	static zprop_index_t case_table[] = {
116da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
117da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
118da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
119da6c28aaSamw 		{ NULL }
120da6c28aaSamw 	};
121da6c28aaSamw 
122990b4856Slling 	static zprop_index_t copies_table[] = {
12391ebeef5Sahrens 		{ "1",		1 },
12491ebeef5Sahrens 		{ "2",		2 },
12591ebeef5Sahrens 		{ "3",		3 },
12691ebeef5Sahrens 		{ NULL }
12791ebeef5Sahrens 	};
12891ebeef5Sahrens 
129de8267e0Stimh 	/*
130de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
131de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
132de8267e0Stimh 	 * values.
133de8267e0Stimh 	 */
134da6c28aaSamw 	static zprop_index_t normalize_table[] = {
135de8267e0Stimh 		{ "none",	0 },
136de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
137de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
138de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
139de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
140da6c28aaSamw 		{ NULL }
141da6c28aaSamw 	};
142da6c28aaSamw 
143990b4856Slling 	static zprop_index_t version_table[] = {
14491ebeef5Sahrens 		{ "1",		1 },
14591ebeef5Sahrens 		{ "2",		2 },
146da6c28aaSamw 		{ "3",		3 },
14714843421SMatthew Ahrens 		{ "4",		4 },
1480a586ceaSMark Shellenbaum 		{ "5",		5 },
14991ebeef5Sahrens 		{ "current",	ZPL_VERSION },
15091ebeef5Sahrens 		{ NULL }
15191ebeef5Sahrens 	};
15291ebeef5Sahrens 
153990b4856Slling 	static zprop_index_t boolean_table[] = {
154e45ce728Sahrens 		{ "off",	0 },
155e45ce728Sahrens 		{ "on",		1 },
156e45ce728Sahrens 		{ NULL }
157e45ce728Sahrens 	};
158e45ce728Sahrens 
159e09fa4daSNeil Perrin 	static zprop_index_t logbias_table[] = {
160e09fa4daSNeil Perrin 		{ "latency",	ZFS_LOGBIAS_LATENCY },
161e09fa4daSNeil Perrin 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
162e09fa4daSNeil Perrin 		{ NULL }
163e09fa4daSNeil Perrin 	};
164e09fa4daSNeil Perrin 
165a227b7f4Shs 	static zprop_index_t canmount_table[] = {
166a227b7f4Shs 		{ "off",	ZFS_CANMOUNT_OFF },
167a227b7f4Shs 		{ "on",		ZFS_CANMOUNT_ON },
168a227b7f4Shs 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
169a227b7f4Shs 		{ NULL }
170a227b7f4Shs 	};
171a227b7f4Shs 
1723baa08fcSek 	static zprop_index_t cache_table[] = {
1733baa08fcSek 		{ "none",	ZFS_CACHE_NONE },
1743baa08fcSek 		{ "metadata",	ZFS_CACHE_METADATA },
1753baa08fcSek 		{ "all",	ZFS_CACHE_ALL },
1763baa08fcSek 		{ NULL }
1773baa08fcSek 	};
1783baa08fcSek 
17991ebeef5Sahrens 	/* inherit index properties */
18083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
18183d7f9feSTom Erickson 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
18283d7f9feSTom Erickson 	    ZFS_TYPE_VOLUME,
18391ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
18491ebeef5Sahrens 	    checksum_table);
18583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
186b24ab676SJeff Bonwick 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
187b1033ae2SMatthew Ahrens 	    "on | off | verify | sha256[,verify]", "DEDUP",
188b24ab676SJeff Bonwick 	    dedup_table);
18983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
190e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
191e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
192b24ab676SJeff Bonwick 	    "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS",
193b24ab676SJeff Bonwick 	    compress_table);
19483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
195e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
196e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
19783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
19883d7f9feSTom Erickson 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
199d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
200b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
20183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
20283d7f9feSTom Erickson 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
20391ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
20483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
2053baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2063baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2073baa08fcSek 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
20883d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
2093baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2103baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2113baa08fcSek 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
21283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
213e09fa4daSNeil Perrin 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
214e09fa4daSNeil Perrin 	    "latency | throughput", "LOGBIAS", logbias_table);
215e45ce728Sahrens 
216e45ce728Sahrens 	/* inherit index (boolean) properties */
21783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
218e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
21983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
220e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
221e45ce728Sahrens 	    boolean_table);
22283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
223e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
224e45ce728Sahrens 	    boolean_table);
22583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
226e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
227e45ce728Sahrens 	    boolean_table);
22883d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
229e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
230e45ce728Sahrens 	    boolean_table);
23183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
232e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
23383d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
234e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
235e45ce728Sahrens 	    boolean_table);
23683d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
237da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
238da6c28aaSamw 	    boolean_table);
23983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
240da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
241da6c28aaSamw 	    boolean_table);
242e45ce728Sahrens 
243e45ce728Sahrens 	/* default index properties */
24483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
2457b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
24614843421SMatthew Ahrens 	    "1 | 2 | 3 | 4 | current", "VERSION", version_table);
24783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
248a227b7f4Shs 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
249a227b7f4Shs 	    "CANMOUNT", canmount_table);
250e45ce728Sahrens 
251e45ce728Sahrens 	/* readonly index (boolean) properties */
25283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
253990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
25483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
255842727c2SChris Kirby 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
256842727c2SChris Kirby 	    boolean_table);
257e45ce728Sahrens 
258da6c28aaSamw 	/* set once index properties */
25983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
260da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
261da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
262da6c28aaSamw 	    normalize_table);
26383d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
26483d7f9feSTom Erickson 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
26583d7f9feSTom Erickson 	    ZFS_TYPE_SNAPSHOT,
266da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
267da6c28aaSamw 
268da6c28aaSamw 	/* set once index (boolean) properties */
26983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
270da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
271da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
272da6c28aaSamw 
27391ebeef5Sahrens 	/* string properties */
27483d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
27591ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
27683d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
27783d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
27883d7f9feSTom Erickson 	    "MOUNTPOINT");
27983d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
28083d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
28183d7f9feSTom Erickson 	    "SHARENFS");
28283d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
283990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
28483d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
28583d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
28683d7f9feSTom Erickson 	    "on | off | sharemgr(1M) options", "SHARESMB");
28783d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
28883d7f9feSTom Erickson 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
28983d7f9feSTom Erickson 	    "<sensitivity label>", "MLSLABEL");
29091ebeef5Sahrens 
29191ebeef5Sahrens 	/* readonly number properties */
29283d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
293990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
29483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
295990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
29683d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
29783d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
29883d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
299990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
30091ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
30183d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
302c1449561SEric Taylor 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
303da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
30483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
30583d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
30683d7f9feSTom Erickson 	    "USEDSNAP");
30783d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
30883d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
30983d7f9feSTom Erickson 	    "USEDDS");
31083d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
31183d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
31283d7f9feSTom Erickson 	    "USEDCHILD");
31383d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
31474e7dc98SMatthew Ahrens 	    PROP_READONLY,
31574e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
31683d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
317842727c2SChris Kirby 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
31891ebeef5Sahrens 
31991ebeef5Sahrens 	/* default number properties */
32083d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
32191ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
32283d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
32383d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
32483d7f9feSTom Erickson 	    "<size> | none", "RESERV");
32583d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
32691ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
32783d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
328a9799022Sck 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
32983d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
330a9799022Sck 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
331a9799022Sck 	    "<size> | none", "REFRESERV");
33291ebeef5Sahrens 
33391ebeef5Sahrens 	/* inherit number properties */
33483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
33583d7f9feSTom Erickson 	    SPA_MAXBLOCKSIZE, PROP_INHERIT,
33691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
33791ebeef5Sahrens 
33891ebeef5Sahrens 	/* hidden properties */
33983d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
340b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
34183d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
342b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
34383d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
344990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
34583d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
34683d7f9feSTom Erickson 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
34783d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
348478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
349478ed9adSEric Taylor 	    "STMF_SBD_LU");
35083d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
35183d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "GUID");
35283d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
353b24ab676SJeff Bonwick 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
354b24ab676SJeff Bonwick 	    "USERACCOUNTING");
35583d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
356b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
35783d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
3581d713200SEric Schrock 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
35991ebeef5Sahrens 
360*27dd1e87SMark Shellenbaum 	/*
361*27dd1e87SMark Shellenbaum 	 * Property to be removed once libbe is integrated
362*27dd1e87SMark Shellenbaum 	 */
363*27dd1e87SMark Shellenbaum 	zprop_register_hidden(ZFS_PROP_PRIVATE, "priv_prop",
364*27dd1e87SMark Shellenbaum 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
365*27dd1e87SMark Shellenbaum 	    "PRIV_PROP");
366*27dd1e87SMark Shellenbaum 
36791ebeef5Sahrens 	/* oddball properties */
36883d7f9feSTom Erickson 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
36983d7f9feSTom Erickson 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET,
37091ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
37191ebeef5Sahrens }
37291ebeef5Sahrens 
373b1b8ab34Slling boolean_t
374990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
375fa9e4066Sahrens {
376990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
3774201a95eSRic Aleshire 
3784201a95eSRic Aleshire 	/* The mlslabel property is never delegatable. */
3794201a95eSRic Aleshire 	if (prop == ZFS_PROP_MLSLABEL)
3804201a95eSRic Aleshire 		return (B_FALSE);
3814201a95eSRic Aleshire 
382990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
383fa9e4066Sahrens }
384fa9e4066Sahrens 
385b1b8ab34Slling /*
386b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
387b1b8ab34Slling  */
388b1b8ab34Slling zfs_prop_t
389b1b8ab34Slling zfs_name_to_prop(const char *propname)
390b1b8ab34Slling {
391990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
392b1b8ab34Slling }
393b1b8ab34Slling 
394e9dbad6fSeschrock /*
395e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
396e9dbad6fSeschrock  * a few useful punctuation characters.
397e9dbad6fSeschrock  */
398e9dbad6fSeschrock static int
399e9dbad6fSeschrock valid_char(char c)
400e9dbad6fSeschrock {
401e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
402e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
403e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
404e9dbad6fSeschrock }
405e9dbad6fSeschrock 
406e9dbad6fSeschrock /*
407e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
408e9dbad6fSeschrock  */
409e9dbad6fSeschrock boolean_t
410e9dbad6fSeschrock zfs_prop_user(const char *name)
411e9dbad6fSeschrock {
412e9dbad6fSeschrock 	int i;
413e9dbad6fSeschrock 	char c;
414e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
415e9dbad6fSeschrock 
416e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
417e9dbad6fSeschrock 		c = name[i];
418e9dbad6fSeschrock 		if (!valid_char(c))
419e9dbad6fSeschrock 			return (B_FALSE);
420e9dbad6fSeschrock 		if (c == ':')
421e9dbad6fSeschrock 			foundsep = B_TRUE;
422e9dbad6fSeschrock 	}
423e9dbad6fSeschrock 
424e9dbad6fSeschrock 	if (!foundsep)
425e9dbad6fSeschrock 		return (B_FALSE);
426e9dbad6fSeschrock 
427e9dbad6fSeschrock 	return (B_TRUE);
428e9dbad6fSeschrock }
429e9dbad6fSeschrock 
43014843421SMatthew Ahrens /*
43114843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
43214843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
43314843421SMatthew Ahrens  * user@domain).
43414843421SMatthew Ahrens  */
43514843421SMatthew Ahrens boolean_t
43614843421SMatthew Ahrens zfs_prop_userquota(const char *name)
43714843421SMatthew Ahrens {
43814843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
43914843421SMatthew Ahrens 
44014843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
44114843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
44214843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
44314843421SMatthew Ahrens 			return (B_TRUE);
44414843421SMatthew Ahrens 		}
44514843421SMatthew Ahrens 	}
44614843421SMatthew Ahrens 
44714843421SMatthew Ahrens 	return (B_FALSE);
44814843421SMatthew Ahrens }
44914843421SMatthew Ahrens 
450fa9e4066Sahrens /*
451990b4856Slling  * Tables of index types, plus functions to convert between the user view
452990b4856Slling  * (strings) and internal representation (uint64_t).
453fa9e4066Sahrens  */
454990b4856Slling int
455990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
456fa9e4066Sahrens {
457990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
458fa9e4066Sahrens }
459fa9e4066Sahrens 
460990b4856Slling int
461990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
4623d7072f8Seschrock {
463990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
4643d7072f8Seschrock }
4653d7072f8Seschrock 
466b24ab676SJeff Bonwick uint64_t
467b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
468b24ab676SJeff Bonwick {
469b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
470b24ab676SJeff Bonwick }
471b24ab676SJeff Bonwick 
472990b4856Slling /*
473990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
474990b4856Slling  */
4754853e976Sgw boolean_t
476990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
477fa9e4066Sahrens {
478990b4856Slling 	return (zprop_valid_for_type(prop, types));
479fa9e4066Sahrens }
480fa9e4066Sahrens 
481990b4856Slling zprop_type_t
482990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
4833d7072f8Seschrock {
484990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
4853d7072f8Seschrock }
4863d7072f8Seschrock 
487fa9e4066Sahrens /*
488fa9e4066Sahrens  * Returns TRUE if the property is readonly.
489fa9e4066Sahrens  */
490990b4856Slling boolean_t
491fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
492fa9e4066Sahrens {
493da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
494da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
495da6c28aaSamw }
496da6c28aaSamw 
497da6c28aaSamw /*
498da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
499da6c28aaSamw  */
500da6c28aaSamw boolean_t
501da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
502da6c28aaSamw {
503da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
504fa9e4066Sahrens }
505fa9e4066Sahrens 
506fa9e4066Sahrens const char *
507990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
508fa9e4066Sahrens {
509990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
510990b4856Slling }
511990b4856Slling 
512990b4856Slling uint64_t
513990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
514990b4856Slling {
515990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
516fa9e4066Sahrens }
517fa9e4066Sahrens 
518b1b8ab34Slling /*
519990b4856Slling  * Given a dataset property ID, returns the corresponding name.
520990b4856Slling  * Assuming the zfs dataset property ID is valid.
521b1b8ab34Slling  */
522b1b8ab34Slling const char *
523990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
524b1b8ab34Slling {
525b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
526b1b8ab34Slling }
527b1b8ab34Slling 
528fa9e4066Sahrens /*
529fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
530fa9e4066Sahrens  */
531990b4856Slling boolean_t
532fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
533fa9e4066Sahrens {
534da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
535da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
536e9dbad6fSeschrock }
537e9dbad6fSeschrock 
538acd76fe5Seschrock #ifndef _KERNEL
539acd76fe5Seschrock 
540fa9e4066Sahrens /*
541b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
542b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
543fa9e4066Sahrens  */
544b1b8ab34Slling const char *
545b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
546fa9e4066Sahrens {
547fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
548fa9e4066Sahrens }
549fa9e4066Sahrens 
550fa9e4066Sahrens /*
551fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
552fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
553fa9e4066Sahrens  * are stored numerically on disk.
554fa9e4066Sahrens  */
555fa9e4066Sahrens int
556fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
557fa9e4066Sahrens {
55891ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
55991ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
560fa9e4066Sahrens }
561fa9e4066Sahrens 
562fa9e4066Sahrens /*
563fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
564fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
565fa9e4066Sahrens  */
566fa9e4066Sahrens const char *
567fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
568fa9e4066Sahrens {
569fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
570fa9e4066Sahrens }
571fa9e4066Sahrens 
572fa9e4066Sahrens /*
573e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
574e9dbad6fSeschrock  * 'zfs list'.
575fa9e4066Sahrens  */
576e9dbad6fSeschrock boolean_t
577e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
578fa9e4066Sahrens {
579e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
580fa9e4066Sahrens }
581da6c28aaSamw 
582fa9e4066Sahrens #endif
583