zfs_prop.c revision 296519
1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23266771Sdelphij * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
24246586Sdelphij * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25255750Sdelphij * Copyright (c) 2013, Joyent, Inc. All rights reserved.
26296519Smav * Copyright (c) 2014 Integros [integros.com]
27168404Spjd */
28168404Spjd
29219089Spjd/* Portions Copyright 2010 Robert Milkowski */
30219089Spjd
31168404Spjd#include <sys/zio.h>
32168404Spjd#include <sys/spa.h>
33185029Spjd#include <sys/u8_textprep.h>
34168404Spjd#include <sys/zfs_acl.h>
35168404Spjd#include <sys/zfs_ioctl.h>
36185029Spjd#include <sys/zfs_znode.h>
37168404Spjd
38168404Spjd#include "zfs_prop.h"
39185029Spjd#include "zfs_deleg.h"
40168404Spjd
41168404Spjd#if defined(_KERNEL)
42168404Spjd#include <sys/systm.h>
43168404Spjd#else
44168404Spjd#include <stdlib.h>
45168404Spjd#include <string.h>
46168404Spjd#include <ctype.h>
47168404Spjd#endif
48168404Spjd
49185029Spjdstatic zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
50168404Spjd
51209962Smm/* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
52209962Smmconst char *zfs_userquota_prop_prefixes[] = {
53209962Smm	"userused@",
54209962Smm	"userquota@",
55209962Smm	"groupused@",
56209962Smm	"groupquota@"
57209962Smm};
58209962Smm
59185029Spjdzprop_desc_t *
60185029Spjdzfs_prop_get_table(void)
61168404Spjd{
62185029Spjd	return (zfs_prop_table);
63168404Spjd}
64168404Spjd
65185029Spjdvoid
66185029Spjdzfs_prop_init(void)
67168404Spjd{
68185029Spjd	static zprop_index_t checksum_table[] = {
69185029Spjd		{ "on",		ZIO_CHECKSUM_ON },
70185029Spjd		{ "off",	ZIO_CHECKSUM_OFF },
71185029Spjd		{ "fletcher2",	ZIO_CHECKSUM_FLETCHER_2 },
72185029Spjd		{ "fletcher4",	ZIO_CHECKSUM_FLETCHER_4 },
73185029Spjd		{ "sha256",	ZIO_CHECKSUM_SHA256 },
74255750Sdelphij		{ "noparity",	ZIO_CHECKSUM_NOPARITY },
75289422Smav#ifdef illumos
76289422Smav		{ "sha512",	ZIO_CHECKSUM_SHA512 },
77289422Smav		{ "skein",	ZIO_CHECKSUM_SKEIN },
78289422Smav		{ "edonr",	ZIO_CHECKSUM_EDONR },
79289422Smav#endif
80185029Spjd		{ NULL }
81185029Spjd	};
82168404Spjd
83219089Spjd	static zprop_index_t dedup_table[] = {
84219089Spjd		{ "on",		ZIO_CHECKSUM_ON },
85219089Spjd		{ "off",	ZIO_CHECKSUM_OFF },
86219089Spjd		{ "verify",	ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
87219089Spjd		{ "sha256",	ZIO_CHECKSUM_SHA256 },
88219089Spjd		{ "sha256,verify",
89219089Spjd				ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
90289422Smav#ifdef illumos
91289422Smav		{ "sha512",	ZIO_CHECKSUM_SHA512 },
92289422Smav		{ "sha512,verify",
93289422Smav				ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
94289422Smav		{ "skein",	ZIO_CHECKSUM_SKEIN },
95289422Smav		{ "skein,verify",
96289422Smav				ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
97289422Smav		{ "edonr,verify",
98289422Smav				ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
99289422Smav#endif
100219089Spjd		{ NULL }
101219089Spjd	};
102219089Spjd
103185029Spjd	static zprop_index_t compress_table[] = {
104185029Spjd		{ "on",		ZIO_COMPRESS_ON },
105185029Spjd		{ "off",	ZIO_COMPRESS_OFF },
106185029Spjd		{ "lzjb",	ZIO_COMPRESS_LZJB },
107185029Spjd		{ "gzip",	ZIO_COMPRESS_GZIP_6 },	/* gzip default */
108185029Spjd		{ "gzip-1",	ZIO_COMPRESS_GZIP_1 },
109185029Spjd		{ "gzip-2",	ZIO_COMPRESS_GZIP_2 },
110185029Spjd		{ "gzip-3",	ZIO_COMPRESS_GZIP_3 },
111185029Spjd		{ "gzip-4",	ZIO_COMPRESS_GZIP_4 },
112185029Spjd		{ "gzip-5",	ZIO_COMPRESS_GZIP_5 },
113185029Spjd		{ "gzip-6",	ZIO_COMPRESS_GZIP_6 },
114185029Spjd		{ "gzip-7",	ZIO_COMPRESS_GZIP_7 },
115185029Spjd		{ "gzip-8",	ZIO_COMPRESS_GZIP_8 },
116185029Spjd		{ "gzip-9",	ZIO_COMPRESS_GZIP_9 },
117219089Spjd		{ "zle",	ZIO_COMPRESS_ZLE },
118246586Sdelphij		{ "lz4",	ZIO_COMPRESS_LZ4 },
119185029Spjd		{ NULL }
120185029Spjd	};
121168404Spjd
122185029Spjd	static zprop_index_t snapdir_table[] = {
123185029Spjd		{ "hidden",	ZFS_SNAPDIR_HIDDEN },
124185029Spjd		{ "visible",	ZFS_SNAPDIR_VISIBLE },
125185029Spjd		{ NULL }
126185029Spjd	};
127168404Spjd
128224174Smm	static zprop_index_t acl_mode_table[] = {
129224174Smm		{ "discard",	ZFS_ACL_DISCARD },
130224174Smm		{ "groupmask",	ZFS_ACL_GROUPMASK },
131224174Smm		{ "passthrough", ZFS_ACL_PASSTHROUGH },
132243560Smm		{ "restricted", ZFS_ACL_RESTRICTED },
133224174Smm		{ NULL }
134224174Smm	};
135224174Smm
136185029Spjd	static zprop_index_t acl_inherit_table[] = {
137185029Spjd		{ "discard",	ZFS_ACL_DISCARD },
138185029Spjd		{ "noallow",	ZFS_ACL_NOALLOW },
139185029Spjd		{ "restricted",	ZFS_ACL_RESTRICTED },
140185029Spjd		{ "passthrough", ZFS_ACL_PASSTHROUGH },
141185029Spjd		{ "secure",	ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
142201143Sdelphij		{ "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
143185029Spjd		{ NULL }
144185029Spjd	};
145168404Spjd
146185029Spjd	static zprop_index_t case_table[] = {
147185029Spjd		{ "sensitive",		ZFS_CASE_SENSITIVE },
148185029Spjd		{ "insensitive",	ZFS_CASE_INSENSITIVE },
149185029Spjd		{ "mixed",		ZFS_CASE_MIXED },
150185029Spjd		{ NULL }
151185029Spjd	};
152168404Spjd
153185029Spjd	static zprop_index_t copies_table[] = {
154185029Spjd		{ "1",		1 },
155185029Spjd		{ "2",		2 },
156185029Spjd		{ "3",		3 },
157185029Spjd		{ NULL }
158185029Spjd	};
159168404Spjd
160185029Spjd	/*
161185029Spjd	 * Use the unique flags we have to send to u8_strcmp() and/or
162185029Spjd	 * u8_textprep() to represent the various normalization property
163185029Spjd	 * values.
164185029Spjd	 */
165185029Spjd	static zprop_index_t normalize_table[] = {
166185029Spjd		{ "none",	0 },
167185029Spjd		{ "formD",	U8_TEXTPREP_NFD },
168185029Spjd		{ "formKC",	U8_TEXTPREP_NFKC },
169185029Spjd		{ "formC",	U8_TEXTPREP_NFC },
170185029Spjd		{ "formKD",	U8_TEXTPREP_NFKD },
171185029Spjd		{ NULL }
172185029Spjd	};
173168404Spjd
174185029Spjd	static zprop_index_t version_table[] = {
175185029Spjd		{ "1",		1 },
176185029Spjd		{ "2",		2 },
177185029Spjd		{ "3",		3 },
178209962Smm		{ "4",		4 },
179219089Spjd		{ "5",		5 },
180185029Spjd		{ "current",	ZPL_VERSION },
181185029Spjd		{ NULL }
182185029Spjd	};
183168404Spjd
184185029Spjd	static zprop_index_t boolean_table[] = {
185185029Spjd		{ "off",	0 },
186185029Spjd		{ "on",		1 },
187185029Spjd		{ NULL }
188185029Spjd	};
189168404Spjd
190219089Spjd	static zprop_index_t logbias_table[] = {
191219089Spjd		{ "latency",	ZFS_LOGBIAS_LATENCY },
192219089Spjd		{ "throughput",	ZFS_LOGBIAS_THROUGHPUT },
193219089Spjd		{ NULL }
194219089Spjd	};
195219089Spjd
196185029Spjd	static zprop_index_t canmount_table[] = {
197185029Spjd		{ "off",	ZFS_CANMOUNT_OFF },
198185029Spjd		{ "on",		ZFS_CANMOUNT_ON },
199185029Spjd		{ "noauto",	ZFS_CANMOUNT_NOAUTO },
200185029Spjd		{ NULL }
201185029Spjd	};
202168404Spjd
203185029Spjd	static zprop_index_t cache_table[] = {
204185029Spjd		{ "none",	ZFS_CACHE_NONE },
205185029Spjd		{ "metadata",	ZFS_CACHE_METADATA },
206185029Spjd		{ "all",	ZFS_CACHE_ALL },
207185029Spjd		{ NULL }
208185029Spjd	};
209168404Spjd
210219089Spjd	static zprop_index_t sync_table[] = {
211219089Spjd		{ "standard",	ZFS_SYNC_STANDARD },
212219089Spjd		{ "always",	ZFS_SYNC_ALWAYS },
213219089Spjd		{ "disabled",	ZFS_SYNC_DISABLED },
214219089Spjd		{ NULL }
215219089Spjd	};
216219089Spjd
217264145Smav	static zprop_index_t volmode_table[] = {
218264145Smav		{ "default",	ZFS_VOLMODE_DEFAULT },
219264145Smav		{ "geom",	ZFS_VOLMODE_GEOM },
220264145Smav		{ "dev",	ZFS_VOLMODE_DEV },
221264145Smav		{ "none",	ZFS_VOLMODE_NONE },
222264145Smav		{ NULL }
223264145Smav	};
224264145Smav
225266771Sdelphij	static zprop_index_t redundant_metadata_table[] = {
226266771Sdelphij		{ "all",	ZFS_REDUNDANT_METADATA_ALL },
227266771Sdelphij		{ "most",	ZFS_REDUNDANT_METADATA_MOST },
228266771Sdelphij		{ NULL }
229266771Sdelphij	};
230266771Sdelphij
231185029Spjd	/* inherit index properties */
232266771Sdelphij	zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
233266771Sdelphij	    ZFS_REDUNDANT_METADATA_ALL,
234266771Sdelphij	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
235266771Sdelphij	    "all | most", "REDUND_MD",
236266771Sdelphij	    redundant_metadata_table);
237219089Spjd	zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
238185029Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
239219089Spjd	    "standard | always | disabled", "SYNC",
240219089Spjd	    sync_table);
241219089Spjd	zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
242219089Spjd	    ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
243219089Spjd	    ZFS_TYPE_VOLUME,
244289422Smav	    "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
245289422Smav	    "skein | edonr", "CHECKSUM", checksum_table);
246219089Spjd	zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
247219089Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
248289422Smav	    "on | off | verify | sha256[,verify], sha512[,verify], "
249289422Smav	    "skein[,verify], edonr,verify", "DEDUP", dedup_table);
250219089Spjd	zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
251185029Spjd	    ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
252185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
253246586Sdelphij	    "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
254246586Sdelphij	    "COMPRESS", compress_table);
255219089Spjd	zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
256185029Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
257185029Spjd	    "hidden | visible", "SNAPDIR", snapdir_table);
258224174Smm	zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
259224174Smm	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
260243560Smm	    "discard | groupmask | passthrough | restricted", "ACLMODE",
261243560Smm	    acl_mode_table);
262219089Spjd	zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
263219089Spjd	    ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
264201143Sdelphij	    "discard | noallow | restricted | passthrough | passthrough-x",
265185029Spjd	    "ACLINHERIT", acl_inherit_table);
266219089Spjd	zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
267219089Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
268185029Spjd	    "1 | 2 | 3", "COPIES", copies_table);
269219089Spjd	zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
270185029Spjd	    ZFS_CACHE_ALL, PROP_INHERIT,
271185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
272185029Spjd	    "all | none | metadata", "PRIMARYCACHE", cache_table);
273219089Spjd	zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
274185029Spjd	    ZFS_CACHE_ALL, PROP_INHERIT,
275185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
276185029Spjd	    "all | none | metadata", "SECONDARYCACHE", cache_table);
277219089Spjd	zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
278219089Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
279219089Spjd	    "latency | throughput", "LOGBIAS", logbias_table);
280264145Smav	zprop_register_index(ZFS_PROP_VOLMODE, "volmode",
281264145Smav	    ZFS_VOLMODE_DEFAULT, PROP_INHERIT,
282264145Smav	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
283264145Smav	    "default | geom | dev | none", "VOLMODE", volmode_table);
284168404Spjd
285185029Spjd	/* inherit index (boolean) properties */
286219089Spjd	zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
287185029Spjd	    ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
288219089Spjd	zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
289185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
290185029Spjd	    boolean_table);
291219089Spjd	zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
292185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
293185029Spjd	    boolean_table);
294219089Spjd	zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
295185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
296185029Spjd	    boolean_table);
297219089Spjd	zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
298185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
299185029Spjd	    boolean_table);
300219089Spjd	zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
301185029Spjd	    ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table);
302219089Spjd	zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
303185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
304185029Spjd	    boolean_table);
305219089Spjd	zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
306185029Spjd	    ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
307185029Spjd	    boolean_table);
308219089Spjd	zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
309185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
310185029Spjd	    boolean_table);
311168404Spjd
312185029Spjd	/* default index properties */
313219089Spjd	zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
314185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
315228103Smm	    "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
316219089Spjd	zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
317185029Spjd	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
318185029Spjd	    "CANMOUNT", canmount_table);
319168404Spjd
320185029Spjd	/* readonly index (boolean) properties */
321219089Spjd	zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
322185029Spjd	    ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
323219089Spjd	zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
324219089Spjd	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
325219089Spjd	    boolean_table);
326185029Spjd
327185029Spjd	/* set once index properties */
328219089Spjd	zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
329185029Spjd	    PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
330185029Spjd	    "none | formC | formD | formKC | formKD", "NORMALIZATION",
331185029Spjd	    normalize_table);
332219089Spjd	zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
333219089Spjd	    ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
334219089Spjd	    ZFS_TYPE_SNAPSHOT,
335185029Spjd	    "sensitive | insensitive | mixed", "CASE", case_table);
336185029Spjd
337185029Spjd	/* set once index (boolean) properties */
338219089Spjd	zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
339185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
340185029Spjd	    "on | off", "UTF8ONLY", boolean_table);
341185029Spjd
342185029Spjd	/* string properties */
343219089Spjd	zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
344185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
345228103Smm	zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
346228103Smm	    ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
347219089Spjd	zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
348219089Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
349219089Spjd	    "MOUNTPOINT");
350219089Spjd	zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
351219089Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
352219089Spjd	    "SHARENFS");
353219089Spjd	zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
354260183Sdelphij	    ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
355260183Sdelphij	    "filesystem | volume | snapshot | bookmark", "TYPE");
356219089Spjd	zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
357219089Spjd	    PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
358219089Spjd	    "on | off | sharemgr(1M) options", "SHARESMB");
359219089Spjd	zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
360219089Spjd	    ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
361219089Spjd	    "<sensitivity label>", "MLSLABEL");
362289362Smav	zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
363289362Smav	    "receive_resume_token",
364289362Smav	    NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
365289362Smav	    "<string token>", "RESUMETOK");
366185029Spjd
367185029Spjd	/* readonly number properties */
368219089Spjd	zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
369185029Spjd	    ZFS_TYPE_DATASET, "<size>", "USED");
370219089Spjd	zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
371185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
372219089Spjd	zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
373219089Spjd	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
374219089Spjd	zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
375185029Spjd	    PROP_READONLY, ZFS_TYPE_DATASET,
376185029Spjd	    "<1.00x or higher if compressed>", "RATIO");
377223623Smm	zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
378223623Smm	    PROP_READONLY, ZFS_TYPE_DATASET,
379223623Smm	    "<1.00x or higher if compressed>", "REFRATIO");
380219089Spjd	zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
381219089Spjd	    ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
382185029Spjd	    ZFS_TYPE_VOLUME, "512 to 128k, power of 2",	"VOLBLOCK");
383219089Spjd	zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
384219089Spjd	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
385219089Spjd	    "USEDSNAP");
386219089Spjd	zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
387219089Spjd	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
388219089Spjd	    "USEDDS");
389219089Spjd	zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
390219089Spjd	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
391219089Spjd	    "USEDCHILD");
392219089Spjd	zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
393185029Spjd	    PROP_READONLY,
394185029Spjd	    ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
395219089Spjd	zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
396219089Spjd	    ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
397228103Smm	zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
398228103Smm	    ZFS_TYPE_DATASET, "<size>", "WRITTEN");
399247585Smm	zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
400247585Smm	    PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED");
401247585Smm	zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
402247585Smm	    0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
403185029Spjd
404185029Spjd	/* default number properties */
405219089Spjd	zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
406185029Spjd	    ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
407219089Spjd	zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
408219089Spjd	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
409219089Spjd	    "<size> | none", "RESERV");
410219089Spjd	zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
411185029Spjd	    ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
412219089Spjd	zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
413185029Spjd	    ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
414219089Spjd	zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
415185029Spjd	    PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
416185029Spjd	    "<size> | none", "REFRESERV");
417264835Sdelphij	zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
418264835Sdelphij	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
419264835Sdelphij	    "<count> | none", "FSLIMIT");
420264835Sdelphij	zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
421264835Sdelphij	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
422264835Sdelphij	    "<count> | none", "SSLIMIT");
423264835Sdelphij	zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
424264835Sdelphij	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
425264835Sdelphij	    "<count>", "FSCOUNT");
426264835Sdelphij	zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
427264835Sdelphij	    UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
428264835Sdelphij	    "<count>", "SSCOUNT");
429185029Spjd
430185029Spjd	/* inherit number properties */
431219089Spjd	zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
432274337Sdelphij	    SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
433274337Sdelphij	    ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
434185029Spjd
435185029Spjd	/* hidden properties */
436219089Spjd	zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
437260183Sdelphij	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "CREATETXG");
438219089Spjd	zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
439219089Spjd	    PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
440219089Spjd	zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
441260183Sdelphij	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
442219089Spjd	zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
443219089Spjd	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
444219089Spjd	zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
445219089Spjd	    PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
446219089Spjd	    "STMF_SBD_LU");
447219089Spjd	zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
448260183Sdelphij	    PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "GUID");
449219089Spjd	zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
450219089Spjd	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
451219089Spjd	    "USERACCOUNTING");
452219089Spjd	zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
453219089Spjd	    PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
454219089Spjd	zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
455219089Spjd	    PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
456253819Sdelphij	zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
457253819Sdelphij	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
458268128Sdelphij	zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
459268128Sdelphij	    PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
460185029Spjd
461185029Spjd	/* oddball properties */
462219089Spjd	zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
463260183Sdelphij	    NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
464185029Spjd	    "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
465168404Spjd}
466168404Spjd
467185029Spjdboolean_t
468185029Spjdzfs_prop_delegatable(zfs_prop_t prop)
469168404Spjd{
470185029Spjd	zprop_desc_t *pd = &zfs_prop_table[prop];
471219089Spjd
472219089Spjd	/* The mlslabel property is never delegatable. */
473219089Spjd	if (prop == ZFS_PROP_MLSLABEL)
474219089Spjd		return (B_FALSE);
475219089Spjd
476185029Spjd	return (pd->pd_attr != PROP_READONLY);
477168404Spjd}
478168404Spjd
479168404Spjd/*
480168404Spjd * Given a zfs dataset property name, returns the corresponding property ID.
481168404Spjd */
482168404Spjdzfs_prop_t
483168404Spjdzfs_name_to_prop(const char *propname)
484168404Spjd{
485185029Spjd	return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
486168404Spjd}
487168404Spjd
488168404Spjd/*
489168404Spjd * For user property names, we allow all lowercase alphanumeric characters, plus
490168404Spjd * a few useful punctuation characters.
491168404Spjd */
492168404Spjdstatic int
493168404Spjdvalid_char(char c)
494168404Spjd{
495168404Spjd	return ((c >= 'a' && c <= 'z') ||
496168404Spjd	    (c >= '0' && c <= '9') ||
497168404Spjd	    c == '-' || c == '_' || c == '.' || c == ':');
498168404Spjd}
499168404Spjd
500168404Spjd/*
501168404Spjd * Returns true if this is a valid user-defined property (one with a ':').
502168404Spjd */
503168404Spjdboolean_t
504168404Spjdzfs_prop_user(const char *name)
505168404Spjd{
506168404Spjd	int i;
507168404Spjd	char c;
508168404Spjd	boolean_t foundsep = B_FALSE;
509168404Spjd
510168404Spjd	for (i = 0; i < strlen(name); i++) {
511168404Spjd		c = name[i];
512168404Spjd		if (!valid_char(c))
513168404Spjd			return (B_FALSE);
514168404Spjd		if (c == ':')
515168404Spjd			foundsep = B_TRUE;
516168404Spjd	}
517168404Spjd
518168404Spjd	if (!foundsep)
519168404Spjd		return (B_FALSE);
520168404Spjd
521168404Spjd	return (B_TRUE);
522168404Spjd}
523168404Spjd
524168404Spjd/*
525209962Smm * Returns true if this is a valid userspace-type property (one with a '@').
526209962Smm * Note that after the @, any character is valid (eg, another @, for SID
527209962Smm * user@domain).
528209962Smm */
529209962Smmboolean_t
530209962Smmzfs_prop_userquota(const char *name)
531209962Smm{
532209962Smm	zfs_userquota_prop_t prop;
533209962Smm
534209962Smm	for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
535209962Smm		if (strncmp(name, zfs_userquota_prop_prefixes[prop],
536209962Smm		    strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
537209962Smm			return (B_TRUE);
538209962Smm		}
539209962Smm	}
540209962Smm
541209962Smm	return (B_FALSE);
542209962Smm}
543209962Smm
544209962Smm/*
545228103Smm * Returns true if this is a valid written@ property.
546228103Smm * Note that after the @, any character is valid (eg, another @, for
547228103Smm * written@pool/fs@origin).
548228103Smm */
549228103Smmboolean_t
550228103Smmzfs_prop_written(const char *name)
551228103Smm{
552228103Smm	static const char *prefix = "written@";
553228103Smm	return (strncmp(name, prefix, strlen(prefix)) == 0);
554228103Smm}
555228103Smm
556228103Smm/*
557185029Spjd * Tables of index types, plus functions to convert between the user view
558185029Spjd * (strings) and internal representation (uint64_t).
559168404Spjd */
560185029Spjdint
561185029Spjdzfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
562168404Spjd{
563185029Spjd	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
564168404Spjd}
565168404Spjd
566185029Spjdint
567185029Spjdzfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
568168404Spjd{
569185029Spjd	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
570168404Spjd}
571168404Spjd
572219089Spjduint64_t
573219089Spjdzfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
574219089Spjd{
575219089Spjd	return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
576219089Spjd}
577219089Spjd
578168404Spjd/*
579185029Spjd * Returns TRUE if the property applies to any of the given dataset types.
580168404Spjd */
581185029Spjdboolean_t
582185029Spjdzfs_prop_valid_for_type(int prop, zfs_type_t types)
583168404Spjd{
584185029Spjd	return (zprop_valid_for_type(prop, types));
585168404Spjd}
586168404Spjd
587185029Spjdzprop_type_t
588185029Spjdzfs_prop_get_type(zfs_prop_t prop)
589168404Spjd{
590185029Spjd	return (zfs_prop_table[prop].pd_proptype);
591168404Spjd}
592168404Spjd
593168404Spjd/*
594185029Spjd * Returns TRUE if the property is readonly.
595168404Spjd */
596185029Spjdboolean_t
597185029Spjdzfs_prop_readonly(zfs_prop_t prop)
598168404Spjd{
599185029Spjd	return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
600185029Spjd	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
601168404Spjd}
602168404Spjd
603168404Spjd/*
604185029Spjd * Returns TRUE if the property is only allowed to be set once.
605168404Spjd */
606185029Spjdboolean_t
607185029Spjdzfs_prop_setonce(zfs_prop_t prop)
608168404Spjd{
609185029Spjd	return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
610168404Spjd}
611168404Spjd
612185029Spjdconst char *
613185029Spjdzfs_prop_default_string(zfs_prop_t prop)
614185029Spjd{
615185029Spjd	return (zfs_prop_table[prop].pd_strdefault);
616185029Spjd}
617168404Spjd
618185029Spjduint64_t
619185029Spjdzfs_prop_default_numeric(zfs_prop_t prop)
620168404Spjd{
621185029Spjd	return (zfs_prop_table[prop].pd_numdefault);
622168404Spjd}
623168404Spjd
624168404Spjd/*
625185029Spjd * Given a dataset property ID, returns the corresponding name.
626185029Spjd * Assuming the zfs dataset property ID is valid.
627168404Spjd */
628185029Spjdconst char *
629185029Spjdzfs_prop_to_name(zfs_prop_t prop)
630168404Spjd{
631185029Spjd	return (zfs_prop_table[prop].pd_name);
632168404Spjd}
633168404Spjd
634185029Spjd/*
635185029Spjd * Returns TRUE if the property is inheritable.
636185029Spjd */
637185029Spjdboolean_t
638185029Spjdzfs_prop_inheritable(zfs_prop_t prop)
639168404Spjd{
640185029Spjd	return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
641185029Spjd	    zfs_prop_table[prop].pd_attr == PROP_ONETIME);
642168404Spjd}
643168404Spjd
644168404Spjd#ifndef _KERNEL
645168404Spjd
646168404Spjd/*
647168404Spjd * Returns a string describing the set of acceptable values for the given
648168404Spjd * zfs property, or NULL if it cannot be set.
649168404Spjd */
650168404Spjdconst char *
651168404Spjdzfs_prop_values(zfs_prop_t prop)
652168404Spjd{
653168404Spjd	return (zfs_prop_table[prop].pd_values);
654168404Spjd}
655168404Spjd
656168404Spjd/*
657168404Spjd * Returns TRUE if this property is a string type.  Note that index types
658168404Spjd * (compression, checksum) are treated as strings in userland, even though they
659168404Spjd * are stored numerically on disk.
660168404Spjd */
661168404Spjdint
662168404Spjdzfs_prop_is_string(zfs_prop_t prop)
663168404Spjd{
664185029Spjd	return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
665185029Spjd	    zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
666168404Spjd}
667168404Spjd
668168404Spjd/*
669168404Spjd * Returns the column header for the given property.  Used only in
670168404Spjd * 'zfs list -o', but centralized here with the other property information.
671168404Spjd */
672168404Spjdconst char *
673168404Spjdzfs_prop_column_name(zfs_prop_t prop)
674168404Spjd{
675168404Spjd	return (zfs_prop_table[prop].pd_colname);
676168404Spjd}
677168404Spjd
678168404Spjd/*
679168404Spjd * Returns whether the given property should be displayed right-justified for
680168404Spjd * 'zfs list'.
681168404Spjd */
682168404Spjdboolean_t
683168404Spjdzfs_prop_align_right(zfs_prop_t prop)
684168404Spjd{
685168404Spjd	return (zfs_prop_table[prop].pd_rightalign);
686168404Spjd}
687168404Spjd
688168404Spjd#endif
689