xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision 4201a95e0468170d576f82c3aa63afecf718497a)
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];
4591ebeef5Sahrens 
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 }
7091ebeef5Sahrens 	};
7191ebeef5Sahrens 
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 		{ "fletcher4,verify",
80b24ab676SJeff Bonwick 				ZIO_CHECKSUM_FLETCHER_4 | ZIO_CHECKSUM_VERIFY },
81b24ab676SJeff Bonwick 		{ NULL }
82b24ab676SJeff Bonwick 	};
83b24ab676SJeff Bonwick 
84990b4856Slling 	static zprop_index_t compress_table[] = {
8591ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
8691ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
8791ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
8891ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
8991ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
9091ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
9191ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
9291ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
9391ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
9491ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
9591ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
9691ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
9791ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
98b24ab676SJeff Bonwick 		{ "zle",	ZIO_COMPRESS_ZLE },
9991ebeef5Sahrens 		{ NULL }
10091ebeef5Sahrens 	};
10191ebeef5Sahrens 
102990b4856Slling 	static zprop_index_t snapdir_table[] = {
10391ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
10491ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
10591ebeef5Sahrens 		{ NULL }
10691ebeef5Sahrens 	};
10791ebeef5Sahrens 
108990b4856Slling 	static zprop_index_t acl_mode_table[] = {
10991ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
11091ebeef5Sahrens 		{ "groupmask",	ZFS_ACL_GROUPMASK },
11191ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
11291ebeef5Sahrens 		{ NULL }
11391ebeef5Sahrens 	};
11491ebeef5Sahrens 
115990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
11691ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
11791ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
118b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
11991ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
120b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
121d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
12291ebeef5Sahrens 		{ NULL }
12391ebeef5Sahrens 	};
12491ebeef5Sahrens 
125da6c28aaSamw 	static zprop_index_t case_table[] = {
126da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
127da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
128da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
129da6c28aaSamw 		{ NULL }
130da6c28aaSamw 	};
131da6c28aaSamw 
132990b4856Slling 	static zprop_index_t copies_table[] = {
13391ebeef5Sahrens 		{ "1",		1 },
13491ebeef5Sahrens 		{ "2",		2 },
13591ebeef5Sahrens 		{ "3",		3 },
13691ebeef5Sahrens 		{ NULL }
13791ebeef5Sahrens 	};
13891ebeef5Sahrens 
139de8267e0Stimh 	/*
140de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
141de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
142de8267e0Stimh 	 * values.
143de8267e0Stimh 	 */
144da6c28aaSamw 	static zprop_index_t normalize_table[] = {
145de8267e0Stimh 		{ "none",	0 },
146de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
147de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
148de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
149de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
150da6c28aaSamw 		{ NULL }
151da6c28aaSamw 	};
152da6c28aaSamw 
153990b4856Slling 	static zprop_index_t version_table[] = {
15491ebeef5Sahrens 		{ "1",		1 },
15591ebeef5Sahrens 		{ "2",		2 },
156da6c28aaSamw 		{ "3",		3 },
15714843421SMatthew Ahrens 		{ "4",		4 },
15891ebeef5Sahrens 		{ "current",	ZPL_VERSION },
15991ebeef5Sahrens 		{ NULL }
16091ebeef5Sahrens 	};
16191ebeef5Sahrens 
162990b4856Slling 	static zprop_index_t boolean_table[] = {
163e45ce728Sahrens 		{ "off",	0 },
164e45ce728Sahrens 		{ "on",		1 },
165e45ce728Sahrens 		{ NULL }
166e45ce728Sahrens 	};
167e45ce728Sahrens 
168e09fa4daSNeil Perrin 	static zprop_index_t logbias_table[] = {
169e09fa4daSNeil Perrin 		{ "latency",	ZFS_LOGBIAS_LATENCY },
170e09fa4daSNeil Perrin 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
171e09fa4daSNeil Perrin 		{ NULL }
172e09fa4daSNeil Perrin 	};
173e09fa4daSNeil Perrin 
174a227b7f4Shs 	static zprop_index_t canmount_table[] = {
175a227b7f4Shs 		{ "off",	ZFS_CANMOUNT_OFF },
176a227b7f4Shs 		{ "on",		ZFS_CANMOUNT_ON },
177a227b7f4Shs 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
178a227b7f4Shs 		{ NULL }
179a227b7f4Shs 	};
180a227b7f4Shs 
1813baa08fcSek 	static zprop_index_t cache_table[] = {
1823baa08fcSek 		{ "none",	ZFS_CACHE_NONE },
1833baa08fcSek 		{ "metadata",	ZFS_CACHE_METADATA },
1843baa08fcSek 		{ "all",	ZFS_CACHE_ALL },
1853baa08fcSek 		{ NULL }
1863baa08fcSek 	};
1873baa08fcSek 
18891ebeef5Sahrens 	/* inherit index properties */
18991ebeef5Sahrens 	register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT,
190e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
19191ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
19291ebeef5Sahrens 	    checksum_table);
193b24ab676SJeff Bonwick 	register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
194b24ab676SJeff Bonwick 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
195b24ab676SJeff Bonwick 	    "on | off | verify | sha256[,verify] | fletcher4,verify", "DEDUP",
196b24ab676SJeff Bonwick 	    dedup_table);
19791ebeef5Sahrens 	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);
20291ebeef5Sahrens 	register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
203e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
204e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
20591ebeef5Sahrens 	register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK,
206e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
207990b4856Slling 	    "discard | groupmask | passthrough", "ACLMODE", acl_mode_table);
208b3d141f8Smarks 	register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED,
209e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
210d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
211b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
21291ebeef5Sahrens 	register_index(ZFS_PROP_COPIES, "copies", 1,
213e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
21491ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
2153baa08fcSek 	register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
2163baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2173baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2183baa08fcSek 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
2193baa08fcSek 	register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
2203baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2213baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2223baa08fcSek 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
223e09fa4daSNeil Perrin 	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 */
228e45ce728Sahrens 	register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
229e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
230e45ce728Sahrens 	register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
231e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
232e45ce728Sahrens 	    boolean_table);
233e45ce728Sahrens 	register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
234e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
235e45ce728Sahrens 	    boolean_table);
236e45ce728Sahrens 	register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
237e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
238e45ce728Sahrens 	    boolean_table);
239e45ce728Sahrens 	register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
240e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
241e45ce728Sahrens 	    boolean_table);
242e45ce728Sahrens 	register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
243e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
244e45ce728Sahrens 	register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
245e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
246e45ce728Sahrens 	    boolean_table);
247da6c28aaSamw 	register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
248da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
249da6c28aaSamw 	    boolean_table);
250da6c28aaSamw 	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 */
255e45ce728Sahrens 	register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
2567b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
25714843421SMatthew Ahrens 	    "1 | 2 | 3 | 4 | current", "VERSION", version_table);
258a227b7f4Shs 	register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
259a227b7f4Shs 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
260a227b7f4Shs 	    "CANMOUNT", canmount_table);
261e45ce728Sahrens 
262e45ce728Sahrens 	/* readonly index (boolean) properties */
263e45ce728Sahrens 	register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
264990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
265842727c2SChris Kirby 	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 */
270de8267e0Stimh 	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);
274da6c28aaSamw 	register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE,
275da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
276da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
277da6c28aaSamw 
278da6c28aaSamw 	/* set once index (boolean) properties */
279da6c28aaSamw 	register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
280da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
281da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
282da6c28aaSamw 
28391ebeef5Sahrens 	/* string properties */
28491ebeef5Sahrens 	register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
28591ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
28691ebeef5Sahrens 	register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT,
28791ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT");
28891ebeef5Sahrens 	register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT,
28991ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS");
29091ebeef5Sahrens 	register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT,
291990b4856Slling 	    ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI");
29291ebeef5Sahrens 	register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
293990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
294da6c28aaSamw 	register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT,
295da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB");
296*4201a95eSRic Aleshire 	register_string(ZFS_PROP_MLSLABEL, "mlslabel", ZFS_MLSLABEL_DEFAULT,
297*4201a95eSRic Aleshire 	    PROP_INHERIT, ZFS_TYPE_DATASET, "<sensitivity label>", "MLSLABEL");
29891ebeef5Sahrens 
29991ebeef5Sahrens 	/* readonly number properties */
30091ebeef5Sahrens 	register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
301990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
30291ebeef5Sahrens 	register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
303990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
30491ebeef5Sahrens 	register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY,
305990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "REFER");
30691ebeef5Sahrens 	register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
307990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
30891ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
30991ebeef5Sahrens 	register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192,
310da6c28aaSamw 	    PROP_ONETIME,
311da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
31274e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY,
31374e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP");
31474e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY,
31574e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS");
31674e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY,
31774e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD");
31874e7dc98SMatthew Ahrens 	register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
31974e7dc98SMatthew Ahrens 	    PROP_READONLY,
32074e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
321842727c2SChris Kirby 	register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
322842727c2SChris Kirby 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
32391ebeef5Sahrens 
32491ebeef5Sahrens 	/* default number properties */
32591ebeef5Sahrens 	register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
32691ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
32791ebeef5Sahrens 	register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT,
32891ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV");
32991ebeef5Sahrens 	register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
33091ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
331a9799022Sck 	register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
332a9799022Sck 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
333a9799022Sck 	register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
334a9799022Sck 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
335a9799022Sck 	    "<size> | none", "REFRESERV");
33691ebeef5Sahrens 
33791ebeef5Sahrens 	/* inherit number properties */
33891ebeef5Sahrens 	register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE,
33991ebeef5Sahrens 	    PROP_INHERIT,
34091ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
34191ebeef5Sahrens 
34291ebeef5Sahrens 	/* hidden properties */
34391ebeef5Sahrens 	register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
344b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
34591ebeef5Sahrens 	register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
346b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
34791ebeef5Sahrens 	register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
348990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
34991ebeef5Sahrens 	register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING,
35091ebeef5Sahrens 	    PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
351478ed9adSEric Taylor 	register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
352478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
353478ed9adSEric Taylor 	    "STMF_SBD_LU");
354c5904d13Seschrock 	register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY,
355c5904d13Seschrock 	    ZFS_TYPE_DATASET, "GUID");
35614843421SMatthew Ahrens 	register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
357b24ab676SJeff Bonwick 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
358b24ab676SJeff Bonwick 	    "USERACCOUNTING");
3591d713200SEric Schrock 	register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
360b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
3611d713200SEric Schrock 	register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
3621d713200SEric Schrock 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
36391ebeef5Sahrens 
36491ebeef5Sahrens 	/* oddball properties */
36591ebeef5Sahrens 	register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL,
366990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
36791ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
36891ebeef5Sahrens }
36991ebeef5Sahrens 
370b1b8ab34Slling boolean_t
371990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
372fa9e4066Sahrens {
373990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
374*4201a95eSRic Aleshire 
375*4201a95eSRic Aleshire 	/* The mlslabel property is never delegatable. */
376*4201a95eSRic Aleshire 	if (prop == ZFS_PROP_MLSLABEL)
377*4201a95eSRic Aleshire 		return (B_FALSE);
378*4201a95eSRic Aleshire 
379990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
380fa9e4066Sahrens }
381fa9e4066Sahrens 
382b1b8ab34Slling /*
383b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
384b1b8ab34Slling  */
385b1b8ab34Slling zfs_prop_t
386b1b8ab34Slling zfs_name_to_prop(const char *propname)
387b1b8ab34Slling {
388990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
389b1b8ab34Slling }
390b1b8ab34Slling 
391e9dbad6fSeschrock /*
392e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
393e9dbad6fSeschrock  * a few useful punctuation characters.
394e9dbad6fSeschrock  */
395e9dbad6fSeschrock static int
396e9dbad6fSeschrock valid_char(char c)
397e9dbad6fSeschrock {
398e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
399e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
400e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
401e9dbad6fSeschrock }
402e9dbad6fSeschrock 
403e9dbad6fSeschrock /*
404e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
405e9dbad6fSeschrock  */
406e9dbad6fSeschrock boolean_t
407e9dbad6fSeschrock zfs_prop_user(const char *name)
408e9dbad6fSeschrock {
409e9dbad6fSeschrock 	int i;
410e9dbad6fSeschrock 	char c;
411e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
412e9dbad6fSeschrock 
413e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
414e9dbad6fSeschrock 		c = name[i];
415e9dbad6fSeschrock 		if (!valid_char(c))
416e9dbad6fSeschrock 			return (B_FALSE);
417e9dbad6fSeschrock 		if (c == ':')
418e9dbad6fSeschrock 			foundsep = B_TRUE;
419e9dbad6fSeschrock 	}
420e9dbad6fSeschrock 
421e9dbad6fSeschrock 	if (!foundsep)
422e9dbad6fSeschrock 		return (B_FALSE);
423e9dbad6fSeschrock 
424e9dbad6fSeschrock 	return (B_TRUE);
425e9dbad6fSeschrock }
426e9dbad6fSeschrock 
42714843421SMatthew Ahrens /*
42814843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
42914843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
43014843421SMatthew Ahrens  * user@domain).
43114843421SMatthew Ahrens  */
43214843421SMatthew Ahrens boolean_t
43314843421SMatthew Ahrens zfs_prop_userquota(const char *name)
43414843421SMatthew Ahrens {
43514843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
43614843421SMatthew Ahrens 
43714843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
43814843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
43914843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
44014843421SMatthew Ahrens 			return (B_TRUE);
44114843421SMatthew Ahrens 		}
44214843421SMatthew Ahrens 	}
44314843421SMatthew Ahrens 
44414843421SMatthew Ahrens 	return (B_FALSE);
44514843421SMatthew Ahrens }
44614843421SMatthew Ahrens 
447fa9e4066Sahrens /*
448990b4856Slling  * Tables of index types, plus functions to convert between the user view
449990b4856Slling  * (strings) and internal representation (uint64_t).
450fa9e4066Sahrens  */
451990b4856Slling int
452990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
453fa9e4066Sahrens {
454990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
455fa9e4066Sahrens }
456fa9e4066Sahrens 
457990b4856Slling int
458990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
4593d7072f8Seschrock {
460990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
4613d7072f8Seschrock }
4623d7072f8Seschrock 
463b24ab676SJeff Bonwick uint64_t
464b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
465b24ab676SJeff Bonwick {
466b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
467b24ab676SJeff Bonwick }
468b24ab676SJeff Bonwick 
469990b4856Slling /*
470990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
471990b4856Slling  */
4724853e976Sgw boolean_t
473990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
474fa9e4066Sahrens {
475990b4856Slling 	return (zprop_valid_for_type(prop, types));
476fa9e4066Sahrens }
477fa9e4066Sahrens 
478990b4856Slling zprop_type_t
479990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
4803d7072f8Seschrock {
481990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
4823d7072f8Seschrock }
4833d7072f8Seschrock 
484fa9e4066Sahrens /*
485fa9e4066Sahrens  * Returns TRUE if the property is readonly.
486fa9e4066Sahrens  */
487990b4856Slling boolean_t
488fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
489fa9e4066Sahrens {
490da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
491da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
492da6c28aaSamw }
493da6c28aaSamw 
494da6c28aaSamw /*
495da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
496da6c28aaSamw  */
497da6c28aaSamw boolean_t
498da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
499da6c28aaSamw {
500da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
501fa9e4066Sahrens }
502fa9e4066Sahrens 
503fa9e4066Sahrens const char *
504990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
505fa9e4066Sahrens {
506990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
507990b4856Slling }
508990b4856Slling 
509990b4856Slling uint64_t
510990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
511990b4856Slling {
512990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
513fa9e4066Sahrens }
514fa9e4066Sahrens 
515b1b8ab34Slling /*
516990b4856Slling  * Given a dataset property ID, returns the corresponding name.
517990b4856Slling  * Assuming the zfs dataset property ID is valid.
518b1b8ab34Slling  */
519b1b8ab34Slling const char *
520990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
521b1b8ab34Slling {
522b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
523b1b8ab34Slling }
524b1b8ab34Slling 
525fa9e4066Sahrens /*
526fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
527fa9e4066Sahrens  */
528990b4856Slling boolean_t
529fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
530fa9e4066Sahrens {
531da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
532da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
533e9dbad6fSeschrock }
534e9dbad6fSeschrock 
535acd76fe5Seschrock #ifndef _KERNEL
536acd76fe5Seschrock 
537fa9e4066Sahrens /*
538b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
539b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
540fa9e4066Sahrens  */
541b1b8ab34Slling const char *
542b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
543fa9e4066Sahrens {
544fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
545fa9e4066Sahrens }
546fa9e4066Sahrens 
547fa9e4066Sahrens /*
548fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
549fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
550fa9e4066Sahrens  * are stored numerically on disk.
551fa9e4066Sahrens  */
552fa9e4066Sahrens int
553fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
554fa9e4066Sahrens {
55591ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
55691ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
557fa9e4066Sahrens }
558fa9e4066Sahrens 
559fa9e4066Sahrens /*
560fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
561fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
562fa9e4066Sahrens  */
563fa9e4066Sahrens const char *
564fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
565fa9e4066Sahrens {
566fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
567fa9e4066Sahrens }
568fa9e4066Sahrens 
569fa9e4066Sahrens /*
570e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
571e9dbad6fSeschrock  * 'zfs list'.
572fa9e4066Sahrens  */
573e9dbad6fSeschrock boolean_t
574e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
575fa9e4066Sahrens {
576e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
577fa9e4066Sahrens }
578da6c28aaSamw 
579fa9e4066Sahrens #endif
580