xref: /titanic_52/usr/src/common/zfs/zfs_prop.c (revision 478ed9ada0b6efe1318150a700986aa47e6a926d)
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 /*
2214843421SMatthew Ahrens  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #include <sys/zio.h>
27fa9e4066Sahrens #include <sys/spa.h>
28de8267e0Stimh #include <sys/u8_textprep.h>
29fa9e4066Sahrens #include <sys/zfs_acl.h>
30fa9e4066Sahrens #include <sys/zfs_ioctl.h>
31e7437265Sahrens #include <sys/zfs_znode.h>
32fa9e4066Sahrens 
33fa9e4066Sahrens #include "zfs_prop.h"
34ecd6cf80Smarks #include "zfs_deleg.h"
35fa9e4066Sahrens 
36fa9e4066Sahrens #if defined(_KERNEL)
37fa9e4066Sahrens #include <sys/systm.h>
38fa9e4066Sahrens #else
39fa9e4066Sahrens #include <stdlib.h>
40fa9e4066Sahrens #include <string.h>
41fa9e4066Sahrens #include <ctype.h>
42fa9e4066Sahrens #endif
43fa9e4066Sahrens 
44990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
45fa9e4066Sahrens 
4614843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
4714843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = {
4814843421SMatthew Ahrens 	"userused@",
4914843421SMatthew Ahrens 	"userquota@",
5014843421SMatthew Ahrens 	"groupused@",
5114843421SMatthew Ahrens 	"groupquota@"
5214843421SMatthew Ahrens };
5314843421SMatthew Ahrens 
54990b4856Slling zprop_desc_t *
55990b4856Slling zfs_prop_get_table(void)
5691ebeef5Sahrens {
57990b4856Slling 	return (zfs_prop_table);
5891ebeef5Sahrens }
5991ebeef5Sahrens 
6091ebeef5Sahrens void
6191ebeef5Sahrens zfs_prop_init(void)
6291ebeef5Sahrens {
63990b4856Slling 	static zprop_index_t checksum_table[] = {
6491ebeef5Sahrens 		{ "on",		ZIO_CHECKSUM_ON },
6591ebeef5Sahrens 		{ "off",	ZIO_CHECKSUM_OFF },
6691ebeef5Sahrens 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
6791ebeef5Sahrens 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
6891ebeef5Sahrens 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
6991ebeef5Sahrens 		{ NULL }
70fa9e4066Sahrens 	};
71fa9e4066Sahrens 
72990b4856Slling 	static zprop_index_t compress_table[] = {
7391ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
7491ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
7591ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
7691ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
7791ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
7891ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
7991ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
8091ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
8191ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
8291ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
8391ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
8491ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
8591ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
8691ebeef5Sahrens 		{ NULL }
8791ebeef5Sahrens 	};
8891ebeef5Sahrens 
89990b4856Slling 	static zprop_index_t snapdir_table[] = {
9091ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
9191ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
9291ebeef5Sahrens 		{ NULL }
9391ebeef5Sahrens 	};
9491ebeef5Sahrens 
95990b4856Slling 	static zprop_index_t acl_mode_table[] = {
9691ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
9791ebeef5Sahrens 		{ "groupmask",	ZFS_ACL_GROUPMASK },
9891ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
9991ebeef5Sahrens 		{ NULL }
10091ebeef5Sahrens 	};
10191ebeef5Sahrens 
102990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
10391ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
10491ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
105b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
10691ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
107b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
108d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
10991ebeef5Sahrens 		{ NULL }
11091ebeef5Sahrens 	};
11191ebeef5Sahrens 
112da6c28aaSamw 	static zprop_index_t case_table[] = {
113da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
114da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
115da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
116da6c28aaSamw 		{ NULL }
117da6c28aaSamw 	};
118da6c28aaSamw 
119990b4856Slling 	static zprop_index_t copies_table[] = {
12091ebeef5Sahrens 		{ "1",		1 },
12191ebeef5Sahrens 		{ "2",		2 },
12291ebeef5Sahrens 		{ "3",		3 },
12391ebeef5Sahrens 		{ NULL }
12491ebeef5Sahrens 	};
12591ebeef5Sahrens 
126de8267e0Stimh 	/*
127de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
128de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
129de8267e0Stimh 	 * values.
130de8267e0Stimh 	 */
131da6c28aaSamw 	static zprop_index_t normalize_table[] = {
132de8267e0Stimh 		{ "none",	0 },
133de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
134de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
135de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
136de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
137da6c28aaSamw 		{ NULL }
138da6c28aaSamw 	};
139da6c28aaSamw 
140990b4856Slling 	static zprop_index_t version_table[] = {
14191ebeef5Sahrens 		{ "1",		1 },
14291ebeef5Sahrens 		{ "2",		2 },
143da6c28aaSamw 		{ "3",		3 },
14414843421SMatthew Ahrens 		{ "4",		4 },
14591ebeef5Sahrens 		{ "current",	ZPL_VERSION },
14691ebeef5Sahrens 		{ NULL }
14791ebeef5Sahrens 	};
14891ebeef5Sahrens 
149990b4856Slling 	static zprop_index_t boolean_table[] = {
150e45ce728Sahrens 		{ "off",	0 },
151e45ce728Sahrens 		{ "on",		1 },
152e45ce728Sahrens 		{ NULL }
153e45ce728Sahrens 	};
154e45ce728Sahrens 
155a227b7f4Shs24103 	static zprop_index_t canmount_table[] = {
156a227b7f4Shs24103 		{ "off",	ZFS_CANMOUNT_OFF },
157a227b7f4Shs24103 		{ "on",		ZFS_CANMOUNT_ON },
158a227b7f4Shs24103 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
159a227b7f4Shs24103 		{ NULL }
160a227b7f4Shs24103 	};
161a227b7f4Shs24103 
1623baa08fcSek110237 	static zprop_index_t cache_table[] = {
1633baa08fcSek110237 		{ "none",	ZFS_CACHE_NONE },
1643baa08fcSek110237 		{ "metadata",	ZFS_CACHE_METADATA },
1653baa08fcSek110237 		{ "all",	ZFS_CACHE_ALL },
1663baa08fcSek110237 		{ NULL }
1673baa08fcSek110237 	};
1683baa08fcSek110237 
16991ebeef5Sahrens 	/* inherit index properties */
17091ebeef5Sahrens 	register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT,
171e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
17291ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
17391ebeef5Sahrens 	    checksum_table);
17491ebeef5Sahrens 	register_index(ZFS_PROP_COMPRESSION, "compression",
175e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
176e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
17791ebeef5Sahrens 	    "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table);
17891ebeef5Sahrens 	register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
179e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
180e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
18191ebeef5Sahrens 	register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK,
182e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
183990b4856Slling 	    "discard | groupmask | passthrough", "ACLMODE", acl_mode_table);
184b3d141f8Smarks 	register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED,
185e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
186d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
187b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
18891ebeef5Sahrens 	register_index(ZFS_PROP_COPIES, "copies", 1,
189e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
19091ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
1913baa08fcSek110237 	register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
1923baa08fcSek110237 	    ZFS_CACHE_ALL, PROP_INHERIT,
1933baa08fcSek110237 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
1943baa08fcSek110237 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
1953baa08fcSek110237 	register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
1963baa08fcSek110237 	    ZFS_CACHE_ALL, PROP_INHERIT,
1973baa08fcSek110237 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
1983baa08fcSek110237 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
199e45ce728Sahrens 
200e45ce728Sahrens 	/* inherit index (boolean) properties */
201e45ce728Sahrens 	register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
202e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
203e45ce728Sahrens 	register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
204e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
205e45ce728Sahrens 	    boolean_table);
206e45ce728Sahrens 	register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
207e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
208e45ce728Sahrens 	    boolean_table);
209e45ce728Sahrens 	register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
210e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
211e45ce728Sahrens 	    boolean_table);
212e45ce728Sahrens 	register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
213e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
214e45ce728Sahrens 	    boolean_table);
215e45ce728Sahrens 	register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
216e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
217e45ce728Sahrens 	register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
218e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
219e45ce728Sahrens 	    boolean_table);
220da6c28aaSamw 	register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
221da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
222da6c28aaSamw 	    boolean_table);
223da6c28aaSamw 	register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
224da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
225da6c28aaSamw 	    boolean_table);
226e45ce728Sahrens 
227e45ce728Sahrens 	/* default index properties */
228e45ce728Sahrens 	register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
22991ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
23014843421SMatthew Ahrens 	    "1 | 2 | 3 | 4 | current", "VERSION", version_table);
231a227b7f4Shs24103 	register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
232a227b7f4Shs24103 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
233a227b7f4Shs24103 	    "CANMOUNT", canmount_table);
234e45ce728Sahrens 
235e45ce728Sahrens 	/* readonly index (boolean) properties */
236e45ce728Sahrens 	register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
237990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
238e45ce728Sahrens 
239da6c28aaSamw 	/* set once index properties */
240de8267e0Stimh 	register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
241da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
242da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
243da6c28aaSamw 	    normalize_table);
244da6c28aaSamw 	register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE,
245da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
246da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
247da6c28aaSamw 
248da6c28aaSamw 	/* set once index (boolean) properties */
249da6c28aaSamw 	register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
250da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
251da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
252da6c28aaSamw 
25391ebeef5Sahrens 	/* string properties */
25491ebeef5Sahrens 	register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
25591ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
25691ebeef5Sahrens 	register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT,
25791ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT");
25891ebeef5Sahrens 	register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT,
25991ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS");
26091ebeef5Sahrens 	register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT,
261990b4856Slling 	    ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI");
26291ebeef5Sahrens 	register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
263990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
264da6c28aaSamw 	register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT,
265da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB");
26691ebeef5Sahrens 
26791ebeef5Sahrens 	/* readonly number properties */
26891ebeef5Sahrens 	register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
269990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
27091ebeef5Sahrens 	register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
271990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
27291ebeef5Sahrens 	register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY,
273990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "REFER");
27491ebeef5Sahrens 	register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
275990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
27691ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
27791ebeef5Sahrens 	register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192,
278da6c28aaSamw 	    PROP_ONETIME,
279da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
28074e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY,
28174e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP");
28274e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY,
28374e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS");
28474e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY,
28574e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD");
28674e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
28774e7dc98SMatthew Ahrens 	    PROP_READONLY,
28874e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
28991ebeef5Sahrens 
29091ebeef5Sahrens 	/* default number properties */
29191ebeef5Sahrens 	register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
29291ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
29391ebeef5Sahrens 	register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT,
29491ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV");
29591ebeef5Sahrens 	register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
29691ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
297a9799022Sck153898 	register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
298a9799022Sck153898 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
299a9799022Sck153898 	register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
300a9799022Sck153898 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
301a9799022Sck153898 	    "<size> | none", "REFRESERV");
30291ebeef5Sahrens 
30391ebeef5Sahrens 	/* inherit number properties */
30491ebeef5Sahrens 	register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE,
30591ebeef5Sahrens 	    PROP_INHERIT,
30691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
30791ebeef5Sahrens 
30891ebeef5Sahrens 	/* hidden properties */
30991ebeef5Sahrens 	register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
310990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, NULL);
31191ebeef5Sahrens 	register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
31291ebeef5Sahrens 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL);
31391ebeef5Sahrens 	register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
314990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
31591ebeef5Sahrens 	register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING,
31691ebeef5Sahrens 	    PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
317*478ed9adSEric Taylor 	register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
318*478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
319*478ed9adSEric Taylor 	    "STMF_SBD_LU");
320c5904d13Seschrock 	register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY,
321c5904d13Seschrock 	    ZFS_TYPE_DATASET, "GUID");
32214843421SMatthew Ahrens 	register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
32314843421SMatthew Ahrens 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, NULL);
32491ebeef5Sahrens 
32591ebeef5Sahrens 	/* oddball properties */
32691ebeef5Sahrens 	register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL,
327990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
32891ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
32991ebeef5Sahrens }
33091ebeef5Sahrens 
331b1b8ab34Slling boolean_t
332990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
333b1b8ab34Slling {
334990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
335990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
336b1b8ab34Slling }
337b1b8ab34Slling 
338b1b8ab34Slling /*
339b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
340fa9e4066Sahrens  */
341fa9e4066Sahrens zfs_prop_t
342fa9e4066Sahrens zfs_name_to_prop(const char *propname)
343fa9e4066Sahrens {
344990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
345b1b8ab34Slling }
346fa9e4066Sahrens 
347fa9e4066Sahrens /*
348e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
349e9dbad6fSeschrock  * a few useful punctuation characters.
350e9dbad6fSeschrock  */
351e9dbad6fSeschrock static int
352e9dbad6fSeschrock valid_char(char c)
353e9dbad6fSeschrock {
354e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
355e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
356e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
357e9dbad6fSeschrock }
358e9dbad6fSeschrock 
359e9dbad6fSeschrock /*
360e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
361e9dbad6fSeschrock  */
362e9dbad6fSeschrock boolean_t
363e9dbad6fSeschrock zfs_prop_user(const char *name)
364e9dbad6fSeschrock {
365e9dbad6fSeschrock 	int i;
366e9dbad6fSeschrock 	char c;
367e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
368e9dbad6fSeschrock 
369e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
370e9dbad6fSeschrock 		c = name[i];
371e9dbad6fSeschrock 		if (!valid_char(c))
372e9dbad6fSeschrock 			return (B_FALSE);
373e9dbad6fSeschrock 		if (c == ':')
374e9dbad6fSeschrock 			foundsep = B_TRUE;
375e9dbad6fSeschrock 	}
376e9dbad6fSeschrock 
377e9dbad6fSeschrock 	if (!foundsep)
378e9dbad6fSeschrock 		return (B_FALSE);
379e9dbad6fSeschrock 
380e9dbad6fSeschrock 	return (B_TRUE);
381e9dbad6fSeschrock }
382e9dbad6fSeschrock 
383e9dbad6fSeschrock /*
38414843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
38514843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
38614843421SMatthew Ahrens  * user@domain).
38714843421SMatthew Ahrens  */
38814843421SMatthew Ahrens boolean_t
38914843421SMatthew Ahrens zfs_prop_userquota(const char *name)
39014843421SMatthew Ahrens {
39114843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
39214843421SMatthew Ahrens 
39314843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
39414843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
39514843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
39614843421SMatthew Ahrens 			return (B_TRUE);
39714843421SMatthew Ahrens 		}
39814843421SMatthew Ahrens 	}
39914843421SMatthew Ahrens 
40014843421SMatthew Ahrens 	return (B_FALSE);
40114843421SMatthew Ahrens }
40214843421SMatthew Ahrens 
40314843421SMatthew Ahrens /*
404990b4856Slling  * Tables of index types, plus functions to convert between the user view
405990b4856Slling  * (strings) and internal representation (uint64_t).
406fa9e4066Sahrens  */
407990b4856Slling int
408990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
409fa9e4066Sahrens {
410990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
411990b4856Slling }
412990b4856Slling 
413990b4856Slling int
414990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
415990b4856Slling {
416990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
417990b4856Slling }
418990b4856Slling 
419990b4856Slling /*
420990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
421990b4856Slling  */
4224853e976Sgw25295 boolean_t
423990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
424990b4856Slling {
425990b4856Slling 	return (zprop_valid_for_type(prop, types));
426990b4856Slling }
427990b4856Slling 
428990b4856Slling zprop_type_t
429990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
430990b4856Slling {
431990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
432990b4856Slling }
433990b4856Slling 
434990b4856Slling /*
435990b4856Slling  * Returns TRUE if the property is readonly.
436990b4856Slling  */
437990b4856Slling boolean_t
438990b4856Slling zfs_prop_readonly(zfs_prop_t prop)
439990b4856Slling {
440da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
441da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
442da6c28aaSamw }
443da6c28aaSamw 
444da6c28aaSamw /*
445da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
446da6c28aaSamw  */
447da6c28aaSamw boolean_t
448da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
449da6c28aaSamw {
450da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
451fa9e4066Sahrens }
452fa9e4066Sahrens 
4533d7072f8Seschrock const char *
454990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
4553d7072f8Seschrock {
4563d7072f8Seschrock 	return (zfs_prop_table[prop].pd_strdefault);
4573d7072f8Seschrock }
4583d7072f8Seschrock 
459fa9e4066Sahrens uint64_t
460fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop)
461fa9e4066Sahrens {
462fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_numdefault);
463fa9e4066Sahrens }
464fa9e4066Sahrens 
465fa9e4066Sahrens /*
466b1b8ab34Slling  * Given a dataset property ID, returns the corresponding name.
4673d7072f8Seschrock  * Assuming the zfs dataset property ID is valid.
468fa9e4066Sahrens  */
469fa9e4066Sahrens const char *
470fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop)
471fa9e4066Sahrens {
472fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_name);
473fa9e4066Sahrens }
474fa9e4066Sahrens 
475fa9e4066Sahrens /*
476fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
477fa9e4066Sahrens  */
478990b4856Slling boolean_t
479fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
480fa9e4066Sahrens {
481da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
482da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
483e9dbad6fSeschrock }
484e9dbad6fSeschrock 
485acd76fe5Seschrock #ifndef _KERNEL
486acd76fe5Seschrock 
487fa9e4066Sahrens /*
488fa9e4066Sahrens  * Returns a string describing the set of acceptable values for the given
489b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
490fa9e4066Sahrens  */
491fa9e4066Sahrens const char *
492fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop)
493fa9e4066Sahrens {
494fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
495fa9e4066Sahrens }
496fa9e4066Sahrens 
497fa9e4066Sahrens /*
498fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
499fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
500fa9e4066Sahrens  * are stored numerically on disk.
501fa9e4066Sahrens  */
502fa9e4066Sahrens int
503fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
504fa9e4066Sahrens {
50591ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
50691ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
507fa9e4066Sahrens }
508fa9e4066Sahrens 
509fa9e4066Sahrens /*
510fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
511fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
512fa9e4066Sahrens  */
513fa9e4066Sahrens const char *
514fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
515fa9e4066Sahrens {
516fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
517fa9e4066Sahrens }
518fa9e4066Sahrens 
519fa9e4066Sahrens /*
520e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
521e9dbad6fSeschrock  * 'zfs list'.
522fa9e4066Sahrens  */
523e9dbad6fSeschrock boolean_t
524e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
525fa9e4066Sahrens {
526e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
527fa9e4066Sahrens }
528da6c28aaSamw 
529fa9e4066Sahrens #endif
530