xref: /titanic_52/usr/src/common/zfs/zfs_prop.c (revision 83d7f9fe6bbb3e281a1ca55fdc5d1ec82ecc3e70)
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 /*
22c1449561SEric Taylor  * Copyright 2010 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 
72b24ab676SJeff Bonwick 	static zprop_index_t dedup_table[] = {
73b24ab676SJeff Bonwick 		{ "on",		ZIO_CHECKSUM_ON },
74b24ab676SJeff Bonwick 		{ "off",	ZIO_CHECKSUM_OFF },
75b24ab676SJeff Bonwick 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
76b24ab676SJeff Bonwick 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
77b24ab676SJeff Bonwick 		{ "sha256,verify",
78b24ab676SJeff Bonwick 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
79b24ab676SJeff Bonwick 		{ NULL }
80b24ab676SJeff Bonwick 	};
81b24ab676SJeff Bonwick 
82990b4856Slling 	static zprop_index_t compress_table[] = {
8391ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
8491ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
8591ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
8691ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
8791ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
8891ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
8991ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
9091ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
9191ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
9291ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
9391ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
9491ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
9591ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
96b24ab676SJeff Bonwick 		{ "zle",	ZIO_COMPRESS_ZLE },
9791ebeef5Sahrens 		{ NULL }
9891ebeef5Sahrens 	};
9991ebeef5Sahrens 
100990b4856Slling 	static zprop_index_t snapdir_table[] = {
10191ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
10291ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
10391ebeef5Sahrens 		{ NULL }
10491ebeef5Sahrens 	};
10591ebeef5Sahrens 
106990b4856Slling 	static zprop_index_t acl_mode_table[] = {
10791ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
10891ebeef5Sahrens 		{ "groupmask",	ZFS_ACL_GROUPMASK },
10991ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
11091ebeef5Sahrens 		{ NULL }
11191ebeef5Sahrens 	};
11291ebeef5Sahrens 
113990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
11491ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
11591ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
116b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
11791ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
118b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
119d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
12091ebeef5Sahrens 		{ NULL }
12191ebeef5Sahrens 	};
12291ebeef5Sahrens 
123da6c28aaSamw 	static zprop_index_t case_table[] = {
124da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
125da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
126da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
127da6c28aaSamw 		{ NULL }
128da6c28aaSamw 	};
129da6c28aaSamw 
130990b4856Slling 	static zprop_index_t copies_table[] = {
13191ebeef5Sahrens 		{ "1",		1 },
13291ebeef5Sahrens 		{ "2",		2 },
13391ebeef5Sahrens 		{ "3",		3 },
13491ebeef5Sahrens 		{ NULL }
13591ebeef5Sahrens 	};
13691ebeef5Sahrens 
137de8267e0Stimh 	/*
138de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
139de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
140de8267e0Stimh 	 * values.
141de8267e0Stimh 	 */
142da6c28aaSamw 	static zprop_index_t normalize_table[] = {
143de8267e0Stimh 		{ "none",	0 },
144de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
145de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
146de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
147de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
148da6c28aaSamw 		{ NULL }
149da6c28aaSamw 	};
150da6c28aaSamw 
151990b4856Slling 	static zprop_index_t version_table[] = {
15291ebeef5Sahrens 		{ "1",		1 },
15391ebeef5Sahrens 		{ "2",		2 },
154da6c28aaSamw 		{ "3",		3 },
15514843421SMatthew Ahrens 		{ "4",		4 },
1560a586ceaSMark Shellenbaum 		{ "5",		5 },
15791ebeef5Sahrens 		{ "current",	ZPL_VERSION },
15891ebeef5Sahrens 		{ NULL }
15991ebeef5Sahrens 	};
16091ebeef5Sahrens 
161990b4856Slling 	static zprop_index_t boolean_table[] = {
162e45ce728Sahrens 		{ "off",	0 },
163e45ce728Sahrens 		{ "on",		1 },
164e45ce728Sahrens 		{ NULL }
165e45ce728Sahrens 	};
166e45ce728Sahrens 
167e09fa4daSNeil Perrin 	static zprop_index_t logbias_table[] = {
168e09fa4daSNeil Perrin 		{ "latency",	ZFS_LOGBIAS_LATENCY },
169e09fa4daSNeil Perrin 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
170e09fa4daSNeil Perrin 		{ NULL }
171e09fa4daSNeil Perrin 	};
172e09fa4daSNeil Perrin 
173a227b7f4Shs24103 	static zprop_index_t canmount_table[] = {
174a227b7f4Shs24103 		{ "off",	ZFS_CANMOUNT_OFF },
175a227b7f4Shs24103 		{ "on",		ZFS_CANMOUNT_ON },
176a227b7f4Shs24103 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
177a227b7f4Shs24103 		{ NULL }
178a227b7f4Shs24103 	};
179a227b7f4Shs24103 
1803baa08fcSek110237 	static zprop_index_t cache_table[] = {
1813baa08fcSek110237 		{ "none",	ZFS_CACHE_NONE },
1823baa08fcSek110237 		{ "metadata",	ZFS_CACHE_METADATA },
1833baa08fcSek110237 		{ "all",	ZFS_CACHE_ALL },
1843baa08fcSek110237 		{ NULL }
1853baa08fcSek110237 	};
1863baa08fcSek110237 
18791ebeef5Sahrens 	/* inherit index properties */
188*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
189*83d7f9feSTom Erickson 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
190*83d7f9feSTom Erickson 	    ZFS_TYPE_VOLUME,
19191ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
19291ebeef5Sahrens 	    checksum_table);
193*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
194b24ab676SJeff Bonwick 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
195b1033ae2SMatthew Ahrens 	    "on | off | verify | sha256[,verify]", "DEDUP",
196b24ab676SJeff Bonwick 	    dedup_table);
197*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
198e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
199e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
200b24ab676SJeff Bonwick 	    "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS",
201b24ab676SJeff Bonwick 	    compress_table);
202*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
203e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
204e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
205*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK,
206e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
207990b4856Slling 	    "discard | groupmask | passthrough", "ACLMODE", acl_mode_table);
208*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
209*83d7f9feSTom Erickson 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
210d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
211b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
212*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
213*83d7f9feSTom Erickson 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
21491ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
215*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
2163baa08fcSek110237 	    ZFS_CACHE_ALL, PROP_INHERIT,
2173baa08fcSek110237 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2183baa08fcSek110237 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
219*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
2203baa08fcSek110237 	    ZFS_CACHE_ALL, PROP_INHERIT,
2213baa08fcSek110237 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2223baa08fcSek110237 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
223*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
224e09fa4daSNeil Perrin 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
225e09fa4daSNeil Perrin 	    "latency | throughput", "LOGBIAS", logbias_table);
226e45ce728Sahrens 
227e45ce728Sahrens 	/* inherit index (boolean) properties */
228*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
229e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
230*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
231e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
232e45ce728Sahrens 	    boolean_table);
233*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
234e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
235e45ce728Sahrens 	    boolean_table);
236*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
237e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
238e45ce728Sahrens 	    boolean_table);
239*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
240e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
241e45ce728Sahrens 	    boolean_table);
242*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
243e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
244*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
245e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
246e45ce728Sahrens 	    boolean_table);
247*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
248da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
249da6c28aaSamw 	    boolean_table);
250*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
251da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
252da6c28aaSamw 	    boolean_table);
253e45ce728Sahrens 
254e45ce728Sahrens 	/* default index properties */
255*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
25691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
25714843421SMatthew Ahrens 	    "1 | 2 | 3 | 4 | current", "VERSION", version_table);
258*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
259a227b7f4Shs24103 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
260a227b7f4Shs24103 	    "CANMOUNT", canmount_table);
261e45ce728Sahrens 
262e45ce728Sahrens 	/* readonly index (boolean) properties */
263*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
264990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
265*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
266842727c2SChris Kirby 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
267842727c2SChris Kirby 	    boolean_table);
268e45ce728Sahrens 
269da6c28aaSamw 	/* set once index properties */
270*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
271da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
272da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
273da6c28aaSamw 	    normalize_table);
274*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
275*83d7f9feSTom Erickson 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
276*83d7f9feSTom Erickson 	    ZFS_TYPE_SNAPSHOT,
277da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
278da6c28aaSamw 
279da6c28aaSamw 	/* set once index (boolean) properties */
280*83d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
281da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
282da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
283da6c28aaSamw 
28491ebeef5Sahrens 	/* string properties */
285*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
28691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
287*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
288*83d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
289*83d7f9feSTom Erickson 	    "MOUNTPOINT");
290*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
291*83d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
292*83d7f9feSTom Erickson 	    "SHARENFS");
293*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
294990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
295*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
296*83d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
297*83d7f9feSTom Erickson 	    "on | off | sharemgr(1M) options", "SHARESMB");
298*83d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
299*83d7f9feSTom Erickson 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
300*83d7f9feSTom Erickson 	    "<sensitivity label>", "MLSLABEL");
30191ebeef5Sahrens 
30291ebeef5Sahrens 	/* readonly number properties */
303*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
304990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
305*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
306990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
307*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
308*83d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
309*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
310990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
31191ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
312*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
313c1449561SEric Taylor 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
314da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
315*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
316*83d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
317*83d7f9feSTom Erickson 	    "USEDSNAP");
318*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
319*83d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
320*83d7f9feSTom Erickson 	    "USEDDS");
321*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
322*83d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
323*83d7f9feSTom Erickson 	    "USEDCHILD");
324*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
32574e7dc98SMatthew Ahrens 	    PROP_READONLY,
32674e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
327*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
328842727c2SChris Kirby 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
32991ebeef5Sahrens 
33091ebeef5Sahrens 	/* default number properties */
331*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
33291ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
333*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
334*83d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
335*83d7f9feSTom Erickson 	    "<size> | none", "RESERV");
336*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
33791ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
338*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
339a9799022Sck153898 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
340*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
341a9799022Sck153898 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
342a9799022Sck153898 	    "<size> | none", "REFRESERV");
34391ebeef5Sahrens 
34491ebeef5Sahrens 	/* inherit number properties */
345*83d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
346*83d7f9feSTom Erickson 	    SPA_MAXBLOCKSIZE, PROP_INHERIT,
34791ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
34891ebeef5Sahrens 
34991ebeef5Sahrens 	/* hidden properties */
350*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
351b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
352*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
353b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
354*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
355990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
356*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
357*83d7f9feSTom Erickson 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
358*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
359478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
360478ed9adSEric Taylor 	    "STMF_SBD_LU");
361*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
362*83d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "GUID");
363*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
364b24ab676SJeff Bonwick 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
365b24ab676SJeff Bonwick 	    "USERACCOUNTING");
366*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
367b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
368*83d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
3691d713200SEric Schrock 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
37091ebeef5Sahrens 
37191ebeef5Sahrens 	/* oddball properties */
372*83d7f9feSTom Erickson 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
373*83d7f9feSTom Erickson 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET,
37491ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
37591ebeef5Sahrens }
37691ebeef5Sahrens 
377b1b8ab34Slling boolean_t
378990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
379b1b8ab34Slling {
380990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
3814201a95eSRic Aleshire 
3824201a95eSRic Aleshire 	/* The mlslabel property is never delegatable. */
3834201a95eSRic Aleshire 	if (prop == ZFS_PROP_MLSLABEL)
3844201a95eSRic Aleshire 		return (B_FALSE);
3854201a95eSRic Aleshire 
386990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
387b1b8ab34Slling }
388b1b8ab34Slling 
389b1b8ab34Slling /*
390b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
391fa9e4066Sahrens  */
392fa9e4066Sahrens zfs_prop_t
393fa9e4066Sahrens zfs_name_to_prop(const char *propname)
394fa9e4066Sahrens {
395990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
396b1b8ab34Slling }
397fa9e4066Sahrens 
398fa9e4066Sahrens /*
399e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
400e9dbad6fSeschrock  * a few useful punctuation characters.
401e9dbad6fSeschrock  */
402e9dbad6fSeschrock static int
403e9dbad6fSeschrock valid_char(char c)
404e9dbad6fSeschrock {
405e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
406e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
407e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
408e9dbad6fSeschrock }
409e9dbad6fSeschrock 
410e9dbad6fSeschrock /*
411e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
412e9dbad6fSeschrock  */
413e9dbad6fSeschrock boolean_t
414e9dbad6fSeschrock zfs_prop_user(const char *name)
415e9dbad6fSeschrock {
416e9dbad6fSeschrock 	int i;
417e9dbad6fSeschrock 	char c;
418e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
419e9dbad6fSeschrock 
420e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
421e9dbad6fSeschrock 		c = name[i];
422e9dbad6fSeschrock 		if (!valid_char(c))
423e9dbad6fSeschrock 			return (B_FALSE);
424e9dbad6fSeschrock 		if (c == ':')
425e9dbad6fSeschrock 			foundsep = B_TRUE;
426e9dbad6fSeschrock 	}
427e9dbad6fSeschrock 
428e9dbad6fSeschrock 	if (!foundsep)
429e9dbad6fSeschrock 		return (B_FALSE);
430e9dbad6fSeschrock 
431e9dbad6fSeschrock 	return (B_TRUE);
432e9dbad6fSeschrock }
433e9dbad6fSeschrock 
434e9dbad6fSeschrock /*
43514843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
43614843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
43714843421SMatthew Ahrens  * user@domain).
43814843421SMatthew Ahrens  */
43914843421SMatthew Ahrens boolean_t
44014843421SMatthew Ahrens zfs_prop_userquota(const char *name)
44114843421SMatthew Ahrens {
44214843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
44314843421SMatthew Ahrens 
44414843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
44514843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
44614843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
44714843421SMatthew Ahrens 			return (B_TRUE);
44814843421SMatthew Ahrens 		}
44914843421SMatthew Ahrens 	}
45014843421SMatthew Ahrens 
45114843421SMatthew Ahrens 	return (B_FALSE);
45214843421SMatthew Ahrens }
45314843421SMatthew Ahrens 
45414843421SMatthew Ahrens /*
455990b4856Slling  * Tables of index types, plus functions to convert between the user view
456990b4856Slling  * (strings) and internal representation (uint64_t).
457fa9e4066Sahrens  */
458990b4856Slling int
459990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
460fa9e4066Sahrens {
461990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
462990b4856Slling }
463990b4856Slling 
464990b4856Slling int
465990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
466990b4856Slling {
467990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
468990b4856Slling }
469990b4856Slling 
470b24ab676SJeff Bonwick uint64_t
471b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
472b24ab676SJeff Bonwick {
473b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
474b24ab676SJeff Bonwick }
475b24ab676SJeff Bonwick 
476990b4856Slling /*
477990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
478990b4856Slling  */
4794853e976Sgw25295 boolean_t
480990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
481990b4856Slling {
482990b4856Slling 	return (zprop_valid_for_type(prop, types));
483990b4856Slling }
484990b4856Slling 
485990b4856Slling zprop_type_t
486990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
487990b4856Slling {
488990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
489990b4856Slling }
490990b4856Slling 
491990b4856Slling /*
492990b4856Slling  * Returns TRUE if the property is readonly.
493990b4856Slling  */
494990b4856Slling boolean_t
495990b4856Slling zfs_prop_readonly(zfs_prop_t prop)
496990b4856Slling {
497da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
498da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
499da6c28aaSamw }
500da6c28aaSamw 
501da6c28aaSamw /*
502da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
503da6c28aaSamw  */
504da6c28aaSamw boolean_t
505da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
506da6c28aaSamw {
507da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
508fa9e4066Sahrens }
509fa9e4066Sahrens 
5103d7072f8Seschrock const char *
511990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
5123d7072f8Seschrock {
5133d7072f8Seschrock 	return (zfs_prop_table[prop].pd_strdefault);
5143d7072f8Seschrock }
5153d7072f8Seschrock 
516fa9e4066Sahrens uint64_t
517fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop)
518fa9e4066Sahrens {
519fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_numdefault);
520fa9e4066Sahrens }
521fa9e4066Sahrens 
522fa9e4066Sahrens /*
523b1b8ab34Slling  * Given a dataset property ID, returns the corresponding name.
5243d7072f8Seschrock  * Assuming the zfs dataset property ID is valid.
525fa9e4066Sahrens  */
526fa9e4066Sahrens const char *
527fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop)
528fa9e4066Sahrens {
529fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_name);
530fa9e4066Sahrens }
531fa9e4066Sahrens 
532fa9e4066Sahrens /*
533fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
534fa9e4066Sahrens  */
535990b4856Slling boolean_t
536fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
537fa9e4066Sahrens {
538da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
539da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
540e9dbad6fSeschrock }
541e9dbad6fSeschrock 
542acd76fe5Seschrock #ifndef _KERNEL
543acd76fe5Seschrock 
544fa9e4066Sahrens /*
545fa9e4066Sahrens  * Returns a string describing the set of acceptable values for the given
546b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
547fa9e4066Sahrens  */
548fa9e4066Sahrens const char *
549fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop)
550fa9e4066Sahrens {
551fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
552fa9e4066Sahrens }
553fa9e4066Sahrens 
554fa9e4066Sahrens /*
555fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
556fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
557fa9e4066Sahrens  * are stored numerically on disk.
558fa9e4066Sahrens  */
559fa9e4066Sahrens int
560fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
561fa9e4066Sahrens {
56291ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
56391ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
564fa9e4066Sahrens }
565fa9e4066Sahrens 
566fa9e4066Sahrens /*
567fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
568fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
569fa9e4066Sahrens  */
570fa9e4066Sahrens const char *
571fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
572fa9e4066Sahrens {
573fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
574fa9e4066Sahrens }
575fa9e4066Sahrens 
576fa9e4066Sahrens /*
577e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
578e9dbad6fSeschrock  * 'zfs list'.
579fa9e4066Sahrens  */
580e9dbad6fSeschrock boolean_t
581e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
582fa9e4066Sahrens {
583e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
584fa9e4066Sahrens }
585da6c28aaSamw 
586fa9e4066Sahrens #endif
587