xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision ca48f36f20f6098ceb19d5b084b6b3d4b8eca9fa)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5906d120cSlling  * Common Development and Distribution License (the "License").
6906d120cSlling  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
2227dd1e87SMark Shellenbaum  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2377372cb0SMatthew Ahrens  * Copyright (c) 2012 by Delphix. All rights reserved.
24a6f561b4SSašo Kiselkov  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
2755da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */
2855da60b9SMark J Musante 
29fa9e4066Sahrens #include <sys/zio.h>
30fa9e4066Sahrens #include <sys/spa.h>
31de8267e0Stimh #include <sys/u8_textprep.h>
32fa9e4066Sahrens #include <sys/zfs_acl.h>
33fa9e4066Sahrens #include <sys/zfs_ioctl.h>
34e7437265Sahrens #include <sys/zfs_znode.h>
35fa9e4066Sahrens 
36fa9e4066Sahrens #include "zfs_prop.h"
37ecd6cf80Smarks #include "zfs_deleg.h"
38fa9e4066Sahrens 
39fa9e4066Sahrens #if defined(_KERNEL)
40fa9e4066Sahrens #include <sys/systm.h>
41fa9e4066Sahrens #else
42fa9e4066Sahrens #include <stdlib.h>
43fa9e4066Sahrens #include <string.h>
44fa9e4066Sahrens #include <ctype.h>
45fa9e4066Sahrens #endif
46fa9e4066Sahrens 
47990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
4891ebeef5Sahrens 
4914843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
5014843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = {
5114843421SMatthew Ahrens 	"userused@",
5214843421SMatthew Ahrens 	"userquota@",
5314843421SMatthew Ahrens 	"groupused@",
5414843421SMatthew Ahrens 	"groupquota@"
5514843421SMatthew Ahrens };
5614843421SMatthew Ahrens 
57990b4856Slling zprop_desc_t *
58990b4856Slling zfs_prop_get_table(void)
5991ebeef5Sahrens {
60990b4856Slling 	return (zfs_prop_table);
6191ebeef5Sahrens }
6291ebeef5Sahrens 
6391ebeef5Sahrens void
6491ebeef5Sahrens zfs_prop_init(void)
6591ebeef5Sahrens {
66990b4856Slling 	static zprop_index_t checksum_table[] = {
6791ebeef5Sahrens 		{ "on",		ZIO_CHECKSUM_ON },
6891ebeef5Sahrens 		{ "off",	ZIO_CHECKSUM_OFF },
6991ebeef5Sahrens 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
7091ebeef5Sahrens 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
7191ebeef5Sahrens 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
7291ebeef5Sahrens 		{ NULL }
7391ebeef5Sahrens 	};
7491ebeef5Sahrens 
75b24ab676SJeff Bonwick 	static zprop_index_t dedup_table[] = {
76b24ab676SJeff Bonwick 		{ "on",		ZIO_CHECKSUM_ON },
77b24ab676SJeff Bonwick 		{ "off",	ZIO_CHECKSUM_OFF },
78b24ab676SJeff Bonwick 		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
79b24ab676SJeff Bonwick 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
80b24ab676SJeff Bonwick 		{ "sha256,verify",
81b24ab676SJeff Bonwick 				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
82b24ab676SJeff Bonwick 		{ NULL }
83b24ab676SJeff Bonwick 	};
84b24ab676SJeff Bonwick 
85990b4856Slling 	static zprop_index_t compress_table[] = {
8691ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
8791ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
8891ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
8991ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
9091ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
9191ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
9291ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
9391ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
9491ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
9591ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
9691ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
9791ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
9891ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
99b24ab676SJeff Bonwick 		{ "zle",	ZIO_COMPRESS_ZLE },
100a6f561b4SSašo Kiselkov 		{ "lz4",	ZIO_COMPRESS_LZ4 },
10191ebeef5Sahrens 		{ NULL }
10291ebeef5Sahrens 	};
10391ebeef5Sahrens 
104990b4856Slling 	static zprop_index_t snapdir_table[] = {
10591ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
10691ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
10791ebeef5Sahrens 		{ NULL }
10891ebeef5Sahrens 	};
10991ebeef5Sahrens 
110a3c49ce1SAlbert Lee 	static zprop_index_t acl_mode_table[] = {
111a3c49ce1SAlbert Lee 		{ "discard",	ZFS_ACL_DISCARD },
112a3c49ce1SAlbert Lee 		{ "groupmask",	ZFS_ACL_GROUPMASK },
113a3c49ce1SAlbert Lee 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
11471dbfc28SPaul B. Henson 		{ "restricted", ZFS_ACL_RESTRICTED },
115a3c49ce1SAlbert Lee 		{ NULL }
116a3c49ce1SAlbert Lee 	};
117a3c49ce1SAlbert Lee 
118990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
11991ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
12091ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
121b3d141f8Smarks 		{ "restricted",	ZFS_ACL_RESTRICTED },
12291ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
123b3d141f8Smarks 		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
124d0f3f37eSMark Shellenbaum 		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
12591ebeef5Sahrens 		{ NULL }
12691ebeef5Sahrens 	};
12791ebeef5Sahrens 
128da6c28aaSamw 	static zprop_index_t case_table[] = {
129da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
130da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
131da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
132da6c28aaSamw 		{ NULL }
133da6c28aaSamw 	};
134da6c28aaSamw 
135990b4856Slling 	static zprop_index_t copies_table[] = {
13691ebeef5Sahrens 		{ "1",		1 },
13791ebeef5Sahrens 		{ "2",		2 },
13891ebeef5Sahrens 		{ "3",		3 },
13991ebeef5Sahrens 		{ NULL }
14091ebeef5Sahrens 	};
14191ebeef5Sahrens 
142de8267e0Stimh 	/*
143de8267e0Stimh 	 * Use the unique flags we have to send to u8_strcmp() and/or
144de8267e0Stimh 	 * u8_textprep() to represent the various normalization property
145de8267e0Stimh 	 * values.
146de8267e0Stimh 	 */
147da6c28aaSamw 	static zprop_index_t normalize_table[] = {
148de8267e0Stimh 		{ "none",	0 },
149de8267e0Stimh 		{ "formD",	U8_TEXTPREP_NFD },
150de8267e0Stimh 		{ "formKC",	U8_TEXTPREP_NFKC },
151de8267e0Stimh 		{ "formC",	U8_TEXTPREP_NFC },
152de8267e0Stimh 		{ "formKD",	U8_TEXTPREP_NFKD },
153da6c28aaSamw 		{ NULL }
154da6c28aaSamw 	};
155da6c28aaSamw 
156990b4856Slling 	static zprop_index_t version_table[] = {
15791ebeef5Sahrens 		{ "1",		1 },
15891ebeef5Sahrens 		{ "2",		2 },
159da6c28aaSamw 		{ "3",		3 },
16014843421SMatthew Ahrens 		{ "4",		4 },
1610a586ceaSMark Shellenbaum 		{ "5",		5 },
16291ebeef5Sahrens 		{ "current",	ZPL_VERSION },
16391ebeef5Sahrens 		{ NULL }
16491ebeef5Sahrens 	};
16591ebeef5Sahrens 
166990b4856Slling 	static zprop_index_t boolean_table[] = {
167e45ce728Sahrens 		{ "off",	0 },
168e45ce728Sahrens 		{ "on",		1 },
169e45ce728Sahrens 		{ NULL }
170e45ce728Sahrens 	};
171e45ce728Sahrens 
172e09fa4daSNeil Perrin 	static zprop_index_t logbias_table[] = {
173e09fa4daSNeil Perrin 		{ "latency",	ZFS_LOGBIAS_LATENCY },
174e09fa4daSNeil Perrin 		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
175e09fa4daSNeil Perrin 		{ NULL }
176e09fa4daSNeil Perrin 	};
177e09fa4daSNeil Perrin 
178a227b7f4Shs 	static zprop_index_t canmount_table[] = {
179a227b7f4Shs 		{ "off",	ZFS_CANMOUNT_OFF },
180a227b7f4Shs 		{ "on",		ZFS_CANMOUNT_ON },
181a227b7f4Shs 		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
182a227b7f4Shs 		{ NULL }
183a227b7f4Shs 	};
184a227b7f4Shs 
1853baa08fcSek 	static zprop_index_t cache_table[] = {
1863baa08fcSek 		{ "none",	ZFS_CACHE_NONE },
1873baa08fcSek 		{ "metadata",	ZFS_CACHE_METADATA },
1883baa08fcSek 		{ "all",	ZFS_CACHE_ALL },
1893baa08fcSek 		{ NULL }
1903baa08fcSek 	};
1913baa08fcSek 
19255da60b9SMark J Musante 	static zprop_index_t sync_table[] = {
19355da60b9SMark J Musante 		{ "standard",	ZFS_SYNC_STANDARD },
19455da60b9SMark J Musante 		{ "always",	ZFS_SYNC_ALWAYS },
19555da60b9SMark J Musante 		{ "disabled",	ZFS_SYNC_DISABLED },
19655da60b9SMark J Musante 		{ NULL }
19755da60b9SMark J Musante 	};
19855da60b9SMark J Musante 
19991ebeef5Sahrens 	/* inherit index properties */
20055da60b9SMark J Musante 	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
20155da60b9SMark J Musante 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
20255da60b9SMark J Musante 	    "standard | always | disabled", "SYNC",
20355da60b9SMark J Musante 	    sync_table);
20483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
20583d7f9feSTom Erickson 	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
20683d7f9feSTom Erickson 	    ZFS_TYPE_VOLUME,
20791ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
20891ebeef5Sahrens 	    checksum_table);
20983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
210b24ab676SJeff Bonwick 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
211b1033ae2SMatthew Ahrens 	    "on | off | verify | sha256[,verify]", "DEDUP",
212b24ab676SJeff Bonwick 	    dedup_table);
21383d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
214e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
215e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
216a6f561b4SSašo Kiselkov 	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
217a6f561b4SSašo Kiselkov 	    "COMPRESS", compress_table);
21883d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
219e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
220e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
221a3c49ce1SAlbert Lee 	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
222a3c49ce1SAlbert Lee 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
22371dbfc28SPaul B. Henson 	    "discard | groupmask | passthrough | restricted", "ACLMODE",
22471dbfc28SPaul B. Henson 	    acl_mode_table);
22583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
22683d7f9feSTom Erickson 	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
227d0f3f37eSMark Shellenbaum 	    "discard | noallow | restricted | passthrough | passthrough-x",
228b3d141f8Smarks 	    "ACLINHERIT", acl_inherit_table);
22983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
23083d7f9feSTom Erickson 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
23191ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
23283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
2333baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2343baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2353baa08fcSek 	    "all | none | metadata", "PRIMARYCACHE", cache_table);
23683d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
2373baa08fcSek 	    ZFS_CACHE_ALL, PROP_INHERIT,
2383baa08fcSek 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
2393baa08fcSek 	    "all | none | metadata", "SECONDARYCACHE", cache_table);
24083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
241e09fa4daSNeil Perrin 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
242e09fa4daSNeil Perrin 	    "latency | throughput", "LOGBIAS", logbias_table);
243e45ce728Sahrens 
244e45ce728Sahrens 	/* inherit index (boolean) properties */
24583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
246e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
24783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
248e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
249e45ce728Sahrens 	    boolean_table);
25083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
251e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
252e45ce728Sahrens 	    boolean_table);
25383d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
254e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
255e45ce728Sahrens 	    boolean_table);
25683d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
257e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
258e45ce728Sahrens 	    boolean_table);
25983d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
260e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
26183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
262e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
263e45ce728Sahrens 	    boolean_table);
26483d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
265da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
266da6c28aaSamw 	    boolean_table);
26783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
268da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
269da6c28aaSamw 	    boolean_table);
270e45ce728Sahrens 
271e45ce728Sahrens 	/* default index properties */
27283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
2737b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
27419b94df9SMatthew Ahrens 	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
27583d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
276a227b7f4Shs 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
277a227b7f4Shs 	    "CANMOUNT", canmount_table);
278e45ce728Sahrens 
279e45ce728Sahrens 	/* readonly index (boolean) properties */
28083d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
281990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
28283d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
283842727c2SChris Kirby 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
284842727c2SChris Kirby 	    boolean_table);
285e45ce728Sahrens 
286da6c28aaSamw 	/* set once index properties */
28783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
288da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
289da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
290da6c28aaSamw 	    normalize_table);
29183d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
29283d7f9feSTom Erickson 	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
29383d7f9feSTom Erickson 	    ZFS_TYPE_SNAPSHOT,
294da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
295da6c28aaSamw 
296da6c28aaSamw 	/* set once index (boolean) properties */
29783d7f9feSTom Erickson 	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
298da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
299da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
300da6c28aaSamw 
30191ebeef5Sahrens 	/* string properties */
30283d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
30391ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
30419b94df9SMatthew Ahrens 	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
30519b94df9SMatthew Ahrens 	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
30683d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
30783d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
30883d7f9feSTom Erickson 	    "MOUNTPOINT");
30983d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
31083d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
31183d7f9feSTom Erickson 	    "SHARENFS");
31283d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
313990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
31483d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
31583d7f9feSTom Erickson 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
31683d7f9feSTom Erickson 	    "on | off | sharemgr(1M) options", "SHARESMB");
31783d7f9feSTom Erickson 	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
31883d7f9feSTom Erickson 	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
31983d7f9feSTom Erickson 	    "<sensitivity label>", "MLSLABEL");
32091ebeef5Sahrens 
32191ebeef5Sahrens 	/* readonly number properties */
32283d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
323990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
32483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
325990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
32683d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
32783d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
32883d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
329990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
33091ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
331187d6ac0SMatt Ahrens 	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
332187d6ac0SMatt Ahrens 	    PROP_READONLY, ZFS_TYPE_DATASET,
333187d6ac0SMatt Ahrens 	    "<1.00x or higher if compressed>", "REFRATIO");
33483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
335c1449561SEric Taylor 	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
336da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
33783d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
33883d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
33983d7f9feSTom Erickson 	    "USEDSNAP");
34083d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
34183d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
34283d7f9feSTom Erickson 	    "USEDDS");
34383d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
34483d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
34583d7f9feSTom Erickson 	    "USEDCHILD");
34683d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
34774e7dc98SMatthew Ahrens 	    PROP_READONLY,
34874e7dc98SMatthew Ahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
34983d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
350842727c2SChris Kirby 	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
35119b94df9SMatthew Ahrens 	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
35219b94df9SMatthew Ahrens 	    ZFS_TYPE_DATASET, "<size>", "WRITTEN");
35377372cb0SMatthew Ahrens 	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
35477372cb0SMatthew Ahrens 	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED");
35577372cb0SMatthew Ahrens 	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
35677372cb0SMatthew Ahrens 	    0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
35791ebeef5Sahrens 
35891ebeef5Sahrens 	/* default number properties */
35983d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
36091ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
36183d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
36283d7f9feSTom Erickson 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
36383d7f9feSTom Erickson 	    "<size> | none", "RESERV");
36483d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
36591ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
36683d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
367a9799022Sck 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
36883d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
369a9799022Sck 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
370a9799022Sck 	    "<size> | none", "REFRESERV");
37191ebeef5Sahrens 
37291ebeef5Sahrens 	/* inherit number properties */
37383d7f9feSTom Erickson 	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
37483d7f9feSTom Erickson 	    SPA_MAXBLOCKSIZE, PROP_INHERIT,
37591ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
37691ebeef5Sahrens 
37791ebeef5Sahrens 	/* hidden properties */
37883d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
379b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
38083d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
381b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
38283d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
383990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
38483d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
38583d7f9feSTom Erickson 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
38683d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
387478ed9adSEric Taylor 	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
388478ed9adSEric Taylor 	    "STMF_SBD_LU");
38983d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
39083d7f9feSTom Erickson 	    PROP_READONLY, ZFS_TYPE_DATASET, "GUID");
39183d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
392b24ab676SJeff Bonwick 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
393b24ab676SJeff Bonwick 	    "USERACCOUNTING");
39483d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
395b24ab676SJeff Bonwick 	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
39683d7f9feSTom Erickson 	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
3971d713200SEric Schrock 	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
398*ca48f36fSKeith M Wesolowski 	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
399*ca48f36fSKeith M Wesolowski 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
40091ebeef5Sahrens 
40191ebeef5Sahrens 	/* oddball properties */
40283d7f9feSTom Erickson 	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
40383d7f9feSTom Erickson 	    NULL, PROP_READONLY, ZFS_TYPE_DATASET,
40491ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
40591ebeef5Sahrens }
40691ebeef5Sahrens 
407b1b8ab34Slling boolean_t
408990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
409fa9e4066Sahrens {
410990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
4114201a95eSRic Aleshire 
4124201a95eSRic Aleshire 	/* The mlslabel property is never delegatable. */
4134201a95eSRic Aleshire 	if (prop == ZFS_PROP_MLSLABEL)
4144201a95eSRic Aleshire 		return (B_FALSE);
4154201a95eSRic Aleshire 
416990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
417fa9e4066Sahrens }
418fa9e4066Sahrens 
419b1b8ab34Slling /*
420b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
421b1b8ab34Slling  */
422b1b8ab34Slling zfs_prop_t
423b1b8ab34Slling zfs_name_to_prop(const char *propname)
424b1b8ab34Slling {
425990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
426b1b8ab34Slling }
427b1b8ab34Slling 
428e9dbad6fSeschrock /*
429e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
430e9dbad6fSeschrock  * a few useful punctuation characters.
431e9dbad6fSeschrock  */
432e9dbad6fSeschrock static int
433e9dbad6fSeschrock valid_char(char c)
434e9dbad6fSeschrock {
435e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
436e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
437e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
438e9dbad6fSeschrock }
439e9dbad6fSeschrock 
440e9dbad6fSeschrock /*
441e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
442e9dbad6fSeschrock  */
443e9dbad6fSeschrock boolean_t
444e9dbad6fSeschrock zfs_prop_user(const char *name)
445e9dbad6fSeschrock {
446e9dbad6fSeschrock 	int i;
447e9dbad6fSeschrock 	char c;
448e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
449e9dbad6fSeschrock 
450e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
451e9dbad6fSeschrock 		c = name[i];
452e9dbad6fSeschrock 		if (!valid_char(c))
453e9dbad6fSeschrock 			return (B_FALSE);
454e9dbad6fSeschrock 		if (c == ':')
455e9dbad6fSeschrock 			foundsep = B_TRUE;
456e9dbad6fSeschrock 	}
457e9dbad6fSeschrock 
458e9dbad6fSeschrock 	if (!foundsep)
459e9dbad6fSeschrock 		return (B_FALSE);
460e9dbad6fSeschrock 
461e9dbad6fSeschrock 	return (B_TRUE);
462e9dbad6fSeschrock }
463e9dbad6fSeschrock 
46414843421SMatthew Ahrens /*
46514843421SMatthew Ahrens  * Returns true if this is a valid userspace-type property (one with a '@').
46614843421SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for SID
46714843421SMatthew Ahrens  * user@domain).
46814843421SMatthew Ahrens  */
46914843421SMatthew Ahrens boolean_t
47014843421SMatthew Ahrens zfs_prop_userquota(const char *name)
47114843421SMatthew Ahrens {
47214843421SMatthew Ahrens 	zfs_userquota_prop_t prop;
47314843421SMatthew Ahrens 
47414843421SMatthew Ahrens 	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
47514843421SMatthew Ahrens 		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
47614843421SMatthew Ahrens 		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
47714843421SMatthew Ahrens 			return (B_TRUE);
47814843421SMatthew Ahrens 		}
47914843421SMatthew Ahrens 	}
48014843421SMatthew Ahrens 
48114843421SMatthew Ahrens 	return (B_FALSE);
48214843421SMatthew Ahrens }
48314843421SMatthew Ahrens 
48419b94df9SMatthew Ahrens /*
48519b94df9SMatthew Ahrens  * Returns true if this is a valid written@ property.
48619b94df9SMatthew Ahrens  * Note that after the @, any character is valid (eg, another @, for
48719b94df9SMatthew Ahrens  * written@pool/fs@origin).
48819b94df9SMatthew Ahrens  */
48919b94df9SMatthew Ahrens boolean_t
49019b94df9SMatthew Ahrens zfs_prop_written(const char *name)
49119b94df9SMatthew Ahrens {
49219b94df9SMatthew Ahrens 	static const char *prefix = "written@";
49319b94df9SMatthew Ahrens 	return (strncmp(name, prefix, strlen(prefix)) == 0);
49419b94df9SMatthew Ahrens }
49519b94df9SMatthew Ahrens 
496fa9e4066Sahrens /*
497990b4856Slling  * Tables of index types, plus functions to convert between the user view
498990b4856Slling  * (strings) and internal representation (uint64_t).
499fa9e4066Sahrens  */
500990b4856Slling int
501990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
502fa9e4066Sahrens {
503990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
504fa9e4066Sahrens }
505fa9e4066Sahrens 
506990b4856Slling int
507990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
5083d7072f8Seschrock {
509990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
5103d7072f8Seschrock }
5113d7072f8Seschrock 
512b24ab676SJeff Bonwick uint64_t
513b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
514b24ab676SJeff Bonwick {
515b24ab676SJeff Bonwick 	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
516b24ab676SJeff Bonwick }
517b24ab676SJeff Bonwick 
518990b4856Slling /*
519990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
520990b4856Slling  */
5214853e976Sgw boolean_t
522990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
523fa9e4066Sahrens {
524990b4856Slling 	return (zprop_valid_for_type(prop, types));
525fa9e4066Sahrens }
526fa9e4066Sahrens 
527990b4856Slling zprop_type_t
528990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
5293d7072f8Seschrock {
530990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
5313d7072f8Seschrock }
5323d7072f8Seschrock 
533fa9e4066Sahrens /*
534fa9e4066Sahrens  * Returns TRUE if the property is readonly.
535fa9e4066Sahrens  */
536990b4856Slling boolean_t
537fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
538fa9e4066Sahrens {
539da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
540da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
541da6c28aaSamw }
542da6c28aaSamw 
543da6c28aaSamw /*
544da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
545da6c28aaSamw  */
546da6c28aaSamw boolean_t
547da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
548da6c28aaSamw {
549da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
550fa9e4066Sahrens }
551fa9e4066Sahrens 
552fa9e4066Sahrens const char *
553990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
554fa9e4066Sahrens {
555990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
556990b4856Slling }
557990b4856Slling 
558990b4856Slling uint64_t
559990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
560990b4856Slling {
561990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
562fa9e4066Sahrens }
563fa9e4066Sahrens 
564b1b8ab34Slling /*
565990b4856Slling  * Given a dataset property ID, returns the corresponding name.
566990b4856Slling  * Assuming the zfs dataset property ID is valid.
567b1b8ab34Slling  */
568b1b8ab34Slling const char *
569990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
570b1b8ab34Slling {
571b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
572b1b8ab34Slling }
573b1b8ab34Slling 
574fa9e4066Sahrens /*
575fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
576fa9e4066Sahrens  */
577990b4856Slling boolean_t
578fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
579fa9e4066Sahrens {
580da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
581da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
582e9dbad6fSeschrock }
583e9dbad6fSeschrock 
584acd76fe5Seschrock #ifndef _KERNEL
585acd76fe5Seschrock 
586fa9e4066Sahrens /*
587b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
588b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
589fa9e4066Sahrens  */
590b1b8ab34Slling const char *
591b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
592fa9e4066Sahrens {
593fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
594fa9e4066Sahrens }
595fa9e4066Sahrens 
596fa9e4066Sahrens /*
597fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
598fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
599fa9e4066Sahrens  * are stored numerically on disk.
600fa9e4066Sahrens  */
601fa9e4066Sahrens int
602fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
603fa9e4066Sahrens {
60491ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
60591ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
606fa9e4066Sahrens }
607fa9e4066Sahrens 
608fa9e4066Sahrens /*
609fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
610fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
611fa9e4066Sahrens  */
612fa9e4066Sahrens const char *
613fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
614fa9e4066Sahrens {
615fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
616fa9e4066Sahrens }
617fa9e4066Sahrens 
618fa9e4066Sahrens /*
619e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
620e9dbad6fSeschrock  * 'zfs list'.
621fa9e4066Sahrens  */
622e9dbad6fSeschrock boolean_t
623e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
624fa9e4066Sahrens {
625e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
626fa9e4066Sahrens }
627da6c28aaSamw 
628fa9e4066Sahrens #endif
629