xref: /illumos-gate/usr/src/common/zfs/zfs_prop.c (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
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>
33*da6c28aaSamw #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 
104*da6c28aaSamw 	static zprop_index_t case_table[] = {
105*da6c28aaSamw 		{ "sensitive",		ZFS_CASE_SENSITIVE },
106*da6c28aaSamw 		{ "insensitive",	ZFS_CASE_INSENSITIVE },
107*da6c28aaSamw 		{ "mixed",		ZFS_CASE_MIXED },
108*da6c28aaSamw 		{ NULL }
109*da6c28aaSamw 	};
110*da6c28aaSamw 
111990b4856Slling 	static zprop_index_t copies_table[] = {
11291ebeef5Sahrens 		{ "1",		1 },
11391ebeef5Sahrens 		{ "2",		2 },
11491ebeef5Sahrens 		{ "3",		3 },
11591ebeef5Sahrens 		{ NULL }
11691ebeef5Sahrens 	};
11791ebeef5Sahrens 
118*da6c28aaSamw 	static zprop_index_t normalize_table[] = {
119*da6c28aaSamw 		{ "none",	ZFS_NORMALIZE_NONE },
120*da6c28aaSamw 		{ "formD",	ZFS_NORMALIZE_D },
121*da6c28aaSamw 		{ "formKC",	ZFS_NORMALIZE_KC },
122*da6c28aaSamw 		{ "formC",	ZFS_NORMALIZE_C },
123*da6c28aaSamw 		{ "formKD",	ZFS_NORMALIZE_KD },
124*da6c28aaSamw 		{ NULL }
125*da6c28aaSamw 	};
126*da6c28aaSamw 
127990b4856Slling 	static zprop_index_t version_table[] = {
12891ebeef5Sahrens 		{ "1",		1 },
12991ebeef5Sahrens 		{ "2",		2 },
130*da6c28aaSamw 		{ "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);
184*da6c28aaSamw 	register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
185*da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
186*da6c28aaSamw 	    boolean_table);
187*da6c28aaSamw 	register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
188*da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
189*da6c28aaSamw 	    boolean_table);
190e45ce728Sahrens 
191e45ce728Sahrens 	/* default index properties */
192e45ce728Sahrens 	register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
1937b55fa8eSck 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
194*da6c28aaSamw 	    "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 
204*da6c28aaSamw 	/* set once index properties */
205*da6c28aaSamw 	register_index(ZFS_PROP_NORMALIZE, "normalization", ZFS_NORMALIZE_NONE,
206*da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
207*da6c28aaSamw 	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
208*da6c28aaSamw 	    normalize_table);
209*da6c28aaSamw 	register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE,
210*da6c28aaSamw 	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
211*da6c28aaSamw 	    "sensitive | insensitive | mixed", "CASE", case_table);
212*da6c28aaSamw 
213*da6c28aaSamw 	/* set once index (boolean) properties */
214*da6c28aaSamw 	register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
215*da6c28aaSamw 	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
216*da6c28aaSamw 	    "on | off", "UTF8ONLY", boolean_table);
217*da6c28aaSamw 
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");
229*da6c28aaSamw 	register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT,
230*da6c28aaSamw 	    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,
243*da6c28aaSamw 	    PROP_ONETIME,
244*da6c28aaSamw 	    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");
25391ebeef5Sahrens 
25491ebeef5Sahrens 	/* inherit number properties */
25591ebeef5Sahrens 	register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE,
25691ebeef5Sahrens 	    PROP_INHERIT,
25791ebeef5Sahrens 	    ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
25891ebeef5Sahrens 
25991ebeef5Sahrens 	/* hidden properties */
26091ebeef5Sahrens 	register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
261990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, NULL);
26291ebeef5Sahrens 	register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
26391ebeef5Sahrens 	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL);
26491ebeef5Sahrens 	register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
265990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
26691ebeef5Sahrens 	register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING,
26791ebeef5Sahrens 	    PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
26891ebeef5Sahrens 
26991ebeef5Sahrens 	/* oddball properties */
27091ebeef5Sahrens 	register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL,
271990b4856Slling 	    PROP_READONLY, ZFS_TYPE_DATASET,
27291ebeef5Sahrens 	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
27391ebeef5Sahrens }
27491ebeef5Sahrens 
275b1b8ab34Slling boolean_t
276990b4856Slling zfs_prop_delegatable(zfs_prop_t prop)
277fa9e4066Sahrens {
278990b4856Slling 	zprop_desc_t *pd = &zfs_prop_table[prop];
279990b4856Slling 	return (pd->pd_attr != PROP_READONLY);
280fa9e4066Sahrens }
281fa9e4066Sahrens 
282b1b8ab34Slling /*
283b1b8ab34Slling  * Given a zfs dataset property name, returns the corresponding property ID.
284b1b8ab34Slling  */
285b1b8ab34Slling zfs_prop_t
286b1b8ab34Slling zfs_name_to_prop(const char *propname)
287b1b8ab34Slling {
288990b4856Slling 	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
289b1b8ab34Slling }
290b1b8ab34Slling 
291ecd6cf80Smarks 
292e9dbad6fSeschrock /*
293e9dbad6fSeschrock  * For user property names, we allow all lowercase alphanumeric characters, plus
294e9dbad6fSeschrock  * a few useful punctuation characters.
295e9dbad6fSeschrock  */
296e9dbad6fSeschrock static int
297e9dbad6fSeschrock valid_char(char c)
298e9dbad6fSeschrock {
299e9dbad6fSeschrock 	return ((c >= 'a' && c <= 'z') ||
300e9dbad6fSeschrock 	    (c >= '0' && c <= '9') ||
301e9dbad6fSeschrock 	    c == '-' || c == '_' || c == '.' || c == ':');
302e9dbad6fSeschrock }
303e9dbad6fSeschrock 
304e9dbad6fSeschrock /*
305e9dbad6fSeschrock  * Returns true if this is a valid user-defined property (one with a ':').
306e9dbad6fSeschrock  */
307e9dbad6fSeschrock boolean_t
308e9dbad6fSeschrock zfs_prop_user(const char *name)
309e9dbad6fSeschrock {
310e9dbad6fSeschrock 	int i;
311e9dbad6fSeschrock 	char c;
312e9dbad6fSeschrock 	boolean_t foundsep = B_FALSE;
313e9dbad6fSeschrock 
314e9dbad6fSeschrock 	for (i = 0; i < strlen(name); i++) {
315e9dbad6fSeschrock 		c = name[i];
316e9dbad6fSeschrock 		if (!valid_char(c))
317e9dbad6fSeschrock 			return (B_FALSE);
318e9dbad6fSeschrock 		if (c == ':')
319e9dbad6fSeschrock 			foundsep = B_TRUE;
320e9dbad6fSeschrock 	}
321e9dbad6fSeschrock 
322e9dbad6fSeschrock 	if (!foundsep)
323e9dbad6fSeschrock 		return (B_FALSE);
324e9dbad6fSeschrock 
325e9dbad6fSeschrock 	return (B_TRUE);
326e9dbad6fSeschrock }
327e9dbad6fSeschrock 
328fa9e4066Sahrens /*
329990b4856Slling  * Tables of index types, plus functions to convert between the user view
330990b4856Slling  * (strings) and internal representation (uint64_t).
331fa9e4066Sahrens  */
332990b4856Slling int
333990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
334fa9e4066Sahrens {
335990b4856Slling 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
336fa9e4066Sahrens }
337fa9e4066Sahrens 
338990b4856Slling int
339990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
3403d7072f8Seschrock {
341990b4856Slling 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
3423d7072f8Seschrock }
3433d7072f8Seschrock 
344990b4856Slling /*
345990b4856Slling  * Returns TRUE if the property applies to any of the given dataset types.
346990b4856Slling  */
347990b4856Slling int
348990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types)
349fa9e4066Sahrens {
350990b4856Slling 	return (zprop_valid_for_type(prop, types));
351fa9e4066Sahrens }
352fa9e4066Sahrens 
353990b4856Slling zprop_type_t
354990b4856Slling zfs_prop_get_type(zfs_prop_t prop)
3553d7072f8Seschrock {
356990b4856Slling 	return (zfs_prop_table[prop].pd_proptype);
3573d7072f8Seschrock }
3583d7072f8Seschrock 
359fa9e4066Sahrens /*
360fa9e4066Sahrens  * Returns TRUE if the property is readonly.
361fa9e4066Sahrens  */
362990b4856Slling boolean_t
363fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop)
364fa9e4066Sahrens {
365*da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
366*da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
367*da6c28aaSamw }
368*da6c28aaSamw 
369*da6c28aaSamw /*
370*da6c28aaSamw  * Returns TRUE if the property is only allowed to be set once.
371*da6c28aaSamw  */
372*da6c28aaSamw boolean_t
373*da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop)
374*da6c28aaSamw {
375*da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
376fa9e4066Sahrens }
377fa9e4066Sahrens 
378fa9e4066Sahrens const char *
379990b4856Slling zfs_prop_default_string(zfs_prop_t prop)
380fa9e4066Sahrens {
381990b4856Slling 	return (zfs_prop_table[prop].pd_strdefault);
382990b4856Slling }
383990b4856Slling 
384990b4856Slling uint64_t
385990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop)
386990b4856Slling {
387990b4856Slling 	return (zfs_prop_table[prop].pd_numdefault);
388fa9e4066Sahrens }
389fa9e4066Sahrens 
390b1b8ab34Slling /*
391990b4856Slling  * Given a dataset property ID, returns the corresponding name.
392990b4856Slling  * Assuming the zfs dataset property ID is valid.
393b1b8ab34Slling  */
394b1b8ab34Slling const char *
395990b4856Slling zfs_prop_to_name(zfs_prop_t prop)
396b1b8ab34Slling {
397b1b8ab34Slling 	return (zfs_prop_table[prop].pd_name);
398b1b8ab34Slling }
399b1b8ab34Slling 
400fa9e4066Sahrens /*
401fa9e4066Sahrens  * Returns TRUE if the property is inheritable.
402fa9e4066Sahrens  */
403990b4856Slling boolean_t
404fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop)
405fa9e4066Sahrens {
406*da6c28aaSamw 	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
407*da6c28aaSamw 	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
408e9dbad6fSeschrock }
409e9dbad6fSeschrock 
410acd76fe5Seschrock #ifndef _KERNEL
411acd76fe5Seschrock 
412fa9e4066Sahrens /*
413b1b8ab34Slling  * Returns a string describing the set of acceptable values for the given
414b1b8ab34Slling  * zfs property, or NULL if it cannot be set.
415fa9e4066Sahrens  */
416b1b8ab34Slling const char *
417b1b8ab34Slling zfs_prop_values(zfs_prop_t prop)
418fa9e4066Sahrens {
419fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_values);
420fa9e4066Sahrens }
421fa9e4066Sahrens 
422fa9e4066Sahrens /*
423fa9e4066Sahrens  * Returns TRUE if this property is a string type.  Note that index types
424fa9e4066Sahrens  * (compression, checksum) are treated as strings in userland, even though they
425fa9e4066Sahrens  * are stored numerically on disk.
426fa9e4066Sahrens  */
427fa9e4066Sahrens int
428fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop)
429fa9e4066Sahrens {
43091ebeef5Sahrens 	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
43191ebeef5Sahrens 	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
432fa9e4066Sahrens }
433fa9e4066Sahrens 
434fa9e4066Sahrens /*
435fa9e4066Sahrens  * Returns the column header for the given property.  Used only in
436fa9e4066Sahrens  * 'zfs list -o', but centralized here with the other property information.
437fa9e4066Sahrens  */
438fa9e4066Sahrens const char *
439fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop)
440fa9e4066Sahrens {
441fa9e4066Sahrens 	return (zfs_prop_table[prop].pd_colname);
442fa9e4066Sahrens }
443fa9e4066Sahrens 
444fa9e4066Sahrens /*
445e9dbad6fSeschrock  * Returns whether the given property should be displayed right-justified for
446e9dbad6fSeschrock  * 'zfs list'.
447fa9e4066Sahrens  */
448e9dbad6fSeschrock boolean_t
449e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop)
450fa9e4066Sahrens {
451e9dbad6fSeschrock 	return (zfs_prop_table[prop].pd_rightalign);
452fa9e4066Sahrens }
453*da6c28aaSamw 
454fa9e4066Sahrens #endif
455