xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision a9799022bd90b13722204e80112efaa5bf573099)
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 /*
2239c23413Seschrock  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
27fa9e4066Sahrens 
28fa9e4066Sahrens #include <sys/zio.h>
29fa9e4066Sahrens #include <sys/spa.h>
30fa9e4066Sahrens #include <sys/zfs_acl.h>
31fa9e4066Sahrens #include <sys/zfs_ioctl.h>
32e7437265Sahrens #include <sys/zfs_znode.h>
33da6c28aaSamw #include <sys/zfs_i18n.h>
34fa9e4066Sahrens 
35fa9e4066Sahrens #include "zfs_prop.h"
36ecd6cf80Smarks #include "zfs_deleg.h"
37fa9e4066Sahrens 
38fa9e4066Sahrens #if defined(_KERNEL)
39fa9e4066Sahrens #include <sys/systm.h>
40fa9e4066Sahrens #else
41fa9e4066Sahrens #include <stdlib.h>
42fa9e4066Sahrens #include <string.h>
43fa9e4066Sahrens #include <ctype.h>
44fa9e4066Sahrens #endif
45fa9e4066Sahrens 
46990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
4791ebeef5Sahrens 
48990b4856Slling zprop_desc_t *
49990b4856Slling zfs_prop_get_table(void)
5091ebeef5Sahrens {
51990b4856Slling 	return (zfs_prop_table);
5291ebeef5Sahrens }
5391ebeef5Sahrens 
5491ebeef5Sahrens void
5591ebeef5Sahrens zfs_prop_init(void)
5691ebeef5Sahrens {
57990b4856Slling 	static zprop_index_t checksum_table[] = {
5891ebeef5Sahrens 		{ "on",		ZIO_CHECKSUM_ON },
5991ebeef5Sahrens 		{ "off",	ZIO_CHECKSUM_OFF },
6091ebeef5Sahrens 		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
6191ebeef5Sahrens 		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
6291ebeef5Sahrens 		{ "sha256",	ZIO_CHECKSUM_SHA256 },
6391ebeef5Sahrens 		{ NULL }
6491ebeef5Sahrens 	};
6591ebeef5Sahrens 
66990b4856Slling 	static zprop_index_t compress_table[] = {
6791ebeef5Sahrens 		{ "on",		ZIO_COMPRESS_ON },
6891ebeef5Sahrens 		{ "off",	ZIO_COMPRESS_OFF },
6991ebeef5Sahrens 		{ "lzjb",	ZIO_COMPRESS_LZJB },
7091ebeef5Sahrens 		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
7191ebeef5Sahrens 		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
7291ebeef5Sahrens 		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
7391ebeef5Sahrens 		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
7491ebeef5Sahrens 		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
7591ebeef5Sahrens 		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
7691ebeef5Sahrens 		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
7791ebeef5Sahrens 		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
7891ebeef5Sahrens 		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
7991ebeef5Sahrens 		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
8091ebeef5Sahrens 		{ NULL }
8191ebeef5Sahrens 	};
8291ebeef5Sahrens 
83990b4856Slling 	static zprop_index_t snapdir_table[] = {
8491ebeef5Sahrens 		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
8591ebeef5Sahrens 		{ "visible",	ZFS_SNAPDIR_VISIBLE },
8691ebeef5Sahrens 		{ NULL }
8791ebeef5Sahrens 	};
8891ebeef5Sahrens 
89990b4856Slling 	static zprop_index_t acl_mode_table[] = {
9091ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
9191ebeef5Sahrens 		{ "groupmask",	ZFS_ACL_GROUPMASK },
9291ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
9391ebeef5Sahrens 		{ NULL }
9491ebeef5Sahrens 	};
9591ebeef5Sahrens 
96990b4856Slling 	static zprop_index_t acl_inherit_table[] = {
9791ebeef5Sahrens 		{ "discard",	ZFS_ACL_DISCARD },
9891ebeef5Sahrens 		{ "noallow",	ZFS_ACL_NOALLOW },
9991ebeef5Sahrens 		{ "secure",	ZFS_ACL_SECURE },
10091ebeef5Sahrens 		{ "passthrough", ZFS_ACL_PASSTHROUGH },
10191ebeef5Sahrens 		{ NULL }
10291ebeef5Sahrens 	};
10391ebeef5Sahrens 
104da6c28aaSamw 	static zprop_index_t case_table[] = {
105da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
106da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
107da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
108da6c28aaSamw 		{ NULL }
109da6c28aaSamw 	};
110da6c28aaSamw 
111990b4856Slling 	static zprop_index_t copies_table[] = {
11291ebeef5Sahrens 		{ "1",		1 },
11391ebeef5Sahrens 		{ "2",		2 },
11491ebeef5Sahrens 		{ "3",		3 },
11591ebeef5Sahrens 		{ NULL }
11691ebeef5Sahrens 	};
11791ebeef5Sahrens 
118da6c28aaSamw 	static zprop_index_t normalize_table[] = {
119da6c28aaSamw 		{ "none",	ZFS_NORMALIZE_NONE },
120da6c28aaSamw 		{ "formD",	ZFS_NORMALIZE_D },
121da6c28aaSamw 		{ "formKC",	ZFS_NORMALIZE_KC },
122da6c28aaSamw 		{ "formC",	ZFS_NORMALIZE_C },
123da6c28aaSamw 		{ "formKD",	ZFS_NORMALIZE_KD },
124da6c28aaSamw 		{ NULL }
125da6c28aaSamw 	};
126da6c28aaSamw 
127990b4856Slling 	static zprop_index_t version_table[] = {
12891ebeef5Sahrens 		{ "1",		1 },
12991ebeef5Sahrens 		{ "2",		2 },
130da6c28aaSamw 		{ "3",		3 },
13191ebeef5Sahrens 		{ "current",	ZPL_VERSION },
13291ebeef5Sahrens 		{ NULL }
13391ebeef5Sahrens 	};
13491ebeef5Sahrens 
135990b4856Slling 	static zprop_index_t boolean_table[] = {
136e45ce728Sahrens 		{ "off",	0 },
137e45ce728Sahrens 		{ "on",		1 },
138e45ce728Sahrens 		{ NULL }
139e45ce728Sahrens 	};
140e45ce728Sahrens 
14191ebeef5Sahrens 	/* inherit index properties */
14291ebeef5Sahrens 	register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT,
143e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
14491ebeef5Sahrens 	    "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM",
14591ebeef5Sahrens 	    checksum_table);
14691ebeef5Sahrens 	register_index(ZFS_PROP_COMPRESSION, "compression",
147e45ce728Sahrens 	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
148e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
14991ebeef5Sahrens 	    "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table);
15091ebeef5Sahrens 	register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
151e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
152e45ce728Sahrens 	    "hidden | visible", "SNAPDIR", snapdir_table);
15391ebeef5Sahrens 	register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK,
154e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
155990b4856Slling 	    "discard | groupmask | passthrough", "ACLMODE", acl_mode_table);
15691ebeef5Sahrens 	register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_SECURE,
157e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
15891ebeef5Sahrens 	    "discard | noallow | secure | passthrough", "ACLINHERIT",
15991ebeef5Sahrens 	    acl_inherit_table);
16091ebeef5Sahrens 	register_index(ZFS_PROP_COPIES, "copies", 1,
161e45ce728Sahrens 	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
16291ebeef5Sahrens 	    "1 | 2 | 3", "COPIES", copies_table);
163e45ce728Sahrens 
164e45ce728Sahrens 	/* inherit index (boolean) properties */
165e45ce728Sahrens 	register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
166e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
167e45ce728Sahrens 	register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
168e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
169e45ce728Sahrens 	    boolean_table);
170e45ce728Sahrens 	register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
171e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
172e45ce728Sahrens 	    boolean_table);
173e45ce728Sahrens 	register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
174e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
175e45ce728Sahrens 	    boolean_table);
176e45ce728Sahrens 	register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
177e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
178e45ce728Sahrens 	    boolean_table);
179e45ce728Sahrens 	register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
180e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
181e45ce728Sahrens 	register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
182e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
183e45ce728Sahrens 	    boolean_table);
184da6c28aaSamw 	register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
185da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
186da6c28aaSamw 	    boolean_table);
187da6c28aaSamw 	register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
188da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
189da6c28aaSamw 	    boolean_table);
190e45ce728Sahrens 
191e45ce728Sahrens 	/* default index properties */
192e45ce728Sahrens 	register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
1937b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
194da6c28aaSamw 	    "1 | 2 | 3 | current", "VERSION", version_table);
19591ebeef5Sahrens 
196e45ce728Sahrens 	/* default index (boolean) properties */
197e45ce728Sahrens 	register_index(ZFS_PROP_CANMOUNT, "canmount", 1, PROP_DEFAULT,
198e45ce728Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off", "CANMOUNT", boolean_table);
199e45ce728Sahrens 
200e45ce728Sahrens 	/* readonly index (boolean) properties */
201e45ce728Sahrens 	register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
202990b4856Slling 	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
203e45ce728Sahrens 
204da6c28aaSamw 	/* set once index properties */
205da6c28aaSamw 	register_index(ZFS_PROP_NORMALIZE, "normalization", ZFS_NORMALIZE_NONE,
206da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
207da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
208da6c28aaSamw 	    normalize_table);
209da6c28aaSamw 	register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE,
210da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
211da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
212da6c28aaSamw 
213da6c28aaSamw 	/* set once index (boolean) properties */
214da6c28aaSamw 	register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
215da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
216da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
217da6c28aaSamw 
21891ebeef5Sahrens 	/* string properties */
21991ebeef5Sahrens 	register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
22091ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
22191ebeef5Sahrens 	register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT,
22291ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT");
22391ebeef5Sahrens 	register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT,
22491ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS");
22591ebeef5Sahrens 	register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT,
226990b4856Slling 	    ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI");
22791ebeef5Sahrens 	register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
228990b4856Slling 	    ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
229da6c28aaSamw 	register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT,
230da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB");
23191ebeef5Sahrens 
23291ebeef5Sahrens 	/* readonly number properties */
23391ebeef5Sahrens 	register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
234990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "USED");
23591ebeef5Sahrens 	register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
236990b4856Slling 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
23791ebeef5Sahrens 	register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY,
238990b4856Slling 	    ZFS_TYPE_DATASET, "<size>", "REFER");
23991ebeef5Sahrens 	register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
240990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
24191ebeef5Sahrens 	    "<1.00x or higher if compressed>", "RATIO");
24291ebeef5Sahrens 	register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192,
243da6c28aaSamw 	    PROP_ONETIME,
244da6c28aaSamw 	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
24591ebeef5Sahrens 
24691ebeef5Sahrens 	/* default number properties */
24791ebeef5Sahrens 	register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
24891ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
24991ebeef5Sahrens 	register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT,
25091ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV");
25191ebeef5Sahrens 	register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
25291ebeef5Sahrens 	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
253*a9799022Sck 	register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
254*a9799022Sck 	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
255*a9799022Sck 	register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
256*a9799022Sck 	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
257*a9799022Sck 	    "<size> | none", "REFRESERV");
25891ebeef5Sahrens 
25991ebeef5Sahrens 	/* inherit number properties */
26091ebeef5Sahrens 	register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE,
26191ebeef5Sahrens 	    PROP_INHERIT,
26291ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
26391ebeef5Sahrens 
26491ebeef5Sahrens 	/* hidden properties */
26591ebeef5Sahrens 	register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
266990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, NULL);
26791ebeef5Sahrens 	register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
26891ebeef5Sahrens 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL);
26991ebeef5Sahrens 	register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
270990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
27191ebeef5Sahrens 	register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING,
27291ebeef5Sahrens 	    PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
27391ebeef5Sahrens 
27491ebeef5Sahrens 	/* oddball properties */
27591ebeef5Sahrens 	register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL,
276990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
27791ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
27891ebeef5Sahrens }
27991ebeef5Sahrens 
280b1b8ab34Slling boolean_t
281990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
282fa9e4066Sahrens {
283990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
284990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
285fa9e4066Sahrens }
286fa9e4066Sahrens 
287b1b8ab34Slling /*
288b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
289b1b8ab34Slling  */
290b1b8ab34Slling zfs_prop_t
291b1b8ab34Slling zfs_name_to_prop(const char *propname)
292b1b8ab34Slling {
293990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
294b1b8ab34Slling }
295b1b8ab34Slling 
296ecd6cf80Smarks 
297e9dbad6fSeschrock /*
298e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
299e9dbad6fSeschrock  * a few useful punctuation characters.
300e9dbad6fSeschrock  */
301e9dbad6fSeschrock static int
302e9dbad6fSeschrock valid_char(char c)
303e9dbad6fSeschrock {
304e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
305e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
306e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
307e9dbad6fSeschrock }
308e9dbad6fSeschrock 
309e9dbad6fSeschrock /*
310e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
311e9dbad6fSeschrock  */
312e9dbad6fSeschrock boolean_t
313e9dbad6fSeschrock zfs_prop_user(const char *name)
314e9dbad6fSeschrock {
315e9dbad6fSeschrock 	int i;
316e9dbad6fSeschrock 	char c;
317e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
318e9dbad6fSeschrock 
319e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
320e9dbad6fSeschrock 		c = name[i];
321e9dbad6fSeschrock 		if (!valid_char(c))
322e9dbad6fSeschrock 			return (B_FALSE);
323e9dbad6fSeschrock 		if (c == ':')
324e9dbad6fSeschrock 			foundsep = B_TRUE;
325e9dbad6fSeschrock 	}
326e9dbad6fSeschrock 
327e9dbad6fSeschrock 	if (!foundsep)
328e9dbad6fSeschrock 		return (B_FALSE);
329e9dbad6fSeschrock 
330e9dbad6fSeschrock 	return (B_TRUE);
331e9dbad6fSeschrock }
332e9dbad6fSeschrock 
333fa9e4066Sahrens /*
334990b4856Slling  * Tables of index types, plus functions to convert between the user view
335990b4856Slling  * (strings) and internal representation (uint64_t).
336fa9e4066Sahrens  */
337990b4856Slling int
338990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
339fa9e4066Sahrens {
340990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
341fa9e4066Sahrens }
342fa9e4066Sahrens 
343990b4856Slling int
344990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
3453d7072f8Seschrock {
346990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
3473d7072f8Seschrock }
3483d7072f8Seschrock 
349990b4856Slling /*
350990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
351990b4856Slling  */
352990b4856Slling int
353990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
354fa9e4066Sahrens {
355990b4856Slling 	return (zprop_valid_for_type(prop, types));
356fa9e4066Sahrens }
357fa9e4066Sahrens 
358990b4856Slling zprop_type_t
359990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
3603d7072f8Seschrock {
361990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
3623d7072f8Seschrock }
3633d7072f8Seschrock 
364fa9e4066Sahrens /*
365fa9e4066Sahrens  * Returns TRUE if the property is readonly.
366fa9e4066Sahrens  */
367990b4856Slling boolean_t
368fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
369fa9e4066Sahrens {
370da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
371da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
372da6c28aaSamw }
373da6c28aaSamw 
374da6c28aaSamw /*
375da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
376da6c28aaSamw  */
377da6c28aaSamw boolean_t
378da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
379da6c28aaSamw {
380da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
381fa9e4066Sahrens }
382fa9e4066Sahrens 
383fa9e4066Sahrens const char *
384990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
385fa9e4066Sahrens {
386990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
387990b4856Slling }
388990b4856Slling 
389990b4856Slling uint64_t
390990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
391990b4856Slling {
392990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
393fa9e4066Sahrens }
394fa9e4066Sahrens 
395b1b8ab34Slling /*
396990b4856Slling  * Given a dataset property ID, returns the corresponding name.
397990b4856Slling  * Assuming the zfs dataset property ID is valid.
398b1b8ab34Slling  */
399b1b8ab34Slling const char *
400990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
401b1b8ab34Slling {
402b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
403b1b8ab34Slling }
404b1b8ab34Slling 
405fa9e4066Sahrens /*
406fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
407fa9e4066Sahrens  */
408990b4856Slling boolean_t
409fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
410fa9e4066Sahrens {
411da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
412da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
413e9dbad6fSeschrock }
414e9dbad6fSeschrock 
415acd76fe5Seschrock #ifndef _KERNEL
416acd76fe5Seschrock 
417fa9e4066Sahrens /*
418b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
419b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
420fa9e4066Sahrens  */
421b1b8ab34Slling const char *
422b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
423fa9e4066Sahrens {
424fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
425fa9e4066Sahrens }
426fa9e4066Sahrens 
427fa9e4066Sahrens /*
428fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
429fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
430fa9e4066Sahrens  * are stored numerically on disk.
431fa9e4066Sahrens  */
432fa9e4066Sahrens int
433fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
434fa9e4066Sahrens {
43591ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
43691ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
437fa9e4066Sahrens }
438fa9e4066Sahrens 
439fa9e4066Sahrens /*
440fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
441fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
442fa9e4066Sahrens  */
443fa9e4066Sahrens const char *
444fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
445fa9e4066Sahrens {
446fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
447fa9e4066Sahrens }
448fa9e4066Sahrens 
449fa9e4066Sahrens /*
450e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
451e9dbad6fSeschrock  * 'zfs list'.
452fa9e4066Sahrens  */
453e9dbad6fSeschrock boolean_t
454e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
455fa9e4066Sahrens {
456e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
457fa9e4066Sahrens }
458da6c28aaSamw 
459fa9e4066Sahrens #endif
460