]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb, and openmp
[FreeBSD/FreeBSD.git] / sys / cddl / contrib / opensolaris / common / zfs / zfs_prop.c
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
24  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
26  * Copyright (c) 2014 Integros [integros.com]
27  */
28
29 /* Portions Copyright 2010 Robert Milkowski */
30
31 #include <sys/zio.h>
32 #include <sys/spa.h>
33 #include <sys/u8_textprep.h>
34 #include <sys/zfs_acl.h>
35 #include <sys/zfs_ioctl.h>
36 #include <sys/zfs_znode.h>
37
38 #include "zfs_prop.h"
39 #include "zfs_deleg.h"
40
41 #if defined(_KERNEL)
42 #include <sys/systm.h>
43 #else
44 #include <stdlib.h>
45 #include <string.h>
46 #include <ctype.h>
47 #endif
48
49 static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
50
51 /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
52 const char *zfs_userquota_prop_prefixes[] = {
53         "userused@",
54         "userquota@",
55         "groupused@",
56         "groupquota@"
57 };
58
59 zprop_desc_t *
60 zfs_prop_get_table(void)
61 {
62         return (zfs_prop_table);
63 }
64
65 void
66 zfs_prop_init(void)
67 {
68         static zprop_index_t checksum_table[] = {
69                 { "on",         ZIO_CHECKSUM_ON },
70                 { "off",        ZIO_CHECKSUM_OFF },
71                 { "fletcher2",  ZIO_CHECKSUM_FLETCHER_2 },
72                 { "fletcher4",  ZIO_CHECKSUM_FLETCHER_4 },
73                 { "sha256",     ZIO_CHECKSUM_SHA256 },
74                 { "noparity",   ZIO_CHECKSUM_NOPARITY },
75                 { "sha512",     ZIO_CHECKSUM_SHA512 },
76                 { "skein",      ZIO_CHECKSUM_SKEIN },
77 #ifdef illumos
78                 { "edonr",      ZIO_CHECKSUM_EDONR },
79 #endif
80                 { NULL }
81         };
82
83         static zprop_index_t dedup_table[] = {
84                 { "on",         ZIO_CHECKSUM_ON },
85                 { "off",        ZIO_CHECKSUM_OFF },
86                 { "verify",     ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
87                 { "sha256",     ZIO_CHECKSUM_SHA256 },
88                 { "sha256,verify",
89                                 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
90                 { "sha512",     ZIO_CHECKSUM_SHA512 },
91                 { "sha512,verify",
92                                 ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
93                 { "skein",      ZIO_CHECKSUM_SKEIN },
94                 { "skein,verify",
95                                 ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
96 #ifdef illumos
97                 { "edonr,verify",
98                                 ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
99 #endif
100                 { NULL }
101         };
102
103         static zprop_index_t compress_table[] = {
104                 { "on",         ZIO_COMPRESS_ON },
105                 { "off",        ZIO_COMPRESS_OFF },
106                 { "lzjb",       ZIO_COMPRESS_LZJB },
107                 { "gzip",       ZIO_COMPRESS_GZIP_6 },  /* gzip default */
108                 { "gzip-1",     ZIO_COMPRESS_GZIP_1 },
109                 { "gzip-2",     ZIO_COMPRESS_GZIP_2 },
110                 { "gzip-3",     ZIO_COMPRESS_GZIP_3 },
111                 { "gzip-4",     ZIO_COMPRESS_GZIP_4 },
112                 { "gzip-5",     ZIO_COMPRESS_GZIP_5 },
113                 { "gzip-6",     ZIO_COMPRESS_GZIP_6 },
114                 { "gzip-7",     ZIO_COMPRESS_GZIP_7 },
115                 { "gzip-8",     ZIO_COMPRESS_GZIP_8 },
116                 { "gzip-9",     ZIO_COMPRESS_GZIP_9 },
117                 { "zle",        ZIO_COMPRESS_ZLE },
118                 { "lz4",        ZIO_COMPRESS_LZ4 },
119                 { NULL }
120         };
121
122         static zprop_index_t snapdir_table[] = {
123                 { "hidden",     ZFS_SNAPDIR_HIDDEN },
124                 { "visible",    ZFS_SNAPDIR_VISIBLE },
125                 { NULL }
126         };
127
128         static zprop_index_t acl_mode_table[] = {
129                 { "discard",    ZFS_ACL_DISCARD },
130                 { "groupmask",  ZFS_ACL_GROUPMASK },
131                 { "passthrough", ZFS_ACL_PASSTHROUGH },
132                 { "restricted", ZFS_ACL_RESTRICTED },
133                 { NULL }
134         };
135
136         static zprop_index_t acl_inherit_table[] = {
137                 { "discard",    ZFS_ACL_DISCARD },
138                 { "noallow",    ZFS_ACL_NOALLOW },
139                 { "restricted", ZFS_ACL_RESTRICTED },
140                 { "passthrough", ZFS_ACL_PASSTHROUGH },
141                 { "secure",     ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
142                 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
143                 { NULL }
144         };
145
146         static zprop_index_t case_table[] = {
147                 { "sensitive",          ZFS_CASE_SENSITIVE },
148                 { "insensitive",        ZFS_CASE_INSENSITIVE },
149                 { "mixed",              ZFS_CASE_MIXED },
150                 { NULL }
151         };
152
153         static zprop_index_t copies_table[] = {
154                 { "1",          1 },
155                 { "2",          2 },
156                 { "3",          3 },
157                 { NULL }
158         };
159
160         /*
161          * Use the unique flags we have to send to u8_strcmp() and/or
162          * u8_textprep() to represent the various normalization property
163          * values.
164          */
165         static zprop_index_t normalize_table[] = {
166                 { "none",       0 },
167                 { "formD",      U8_TEXTPREP_NFD },
168                 { "formKC",     U8_TEXTPREP_NFKC },
169                 { "formC",      U8_TEXTPREP_NFC },
170                 { "formKD",     U8_TEXTPREP_NFKD },
171                 { NULL }
172         };
173
174         static zprop_index_t version_table[] = {
175                 { "1",          1 },
176                 { "2",          2 },
177                 { "3",          3 },
178                 { "4",          4 },
179                 { "5",          5 },
180                 { "current",    ZPL_VERSION },
181                 { NULL }
182         };
183
184         static zprop_index_t boolean_table[] = {
185                 { "off",        0 },
186                 { "on",         1 },
187                 { NULL }
188         };
189
190         static zprop_index_t logbias_table[] = {
191                 { "latency",    ZFS_LOGBIAS_LATENCY },
192                 { "throughput", ZFS_LOGBIAS_THROUGHPUT },
193                 { NULL }
194         };
195
196         static zprop_index_t canmount_table[] = {
197                 { "off",        ZFS_CANMOUNT_OFF },
198                 { "on",         ZFS_CANMOUNT_ON },
199                 { "noauto",     ZFS_CANMOUNT_NOAUTO },
200                 { NULL }
201         };
202
203         static zprop_index_t cache_table[] = {
204                 { "none",       ZFS_CACHE_NONE },
205                 { "metadata",   ZFS_CACHE_METADATA },
206                 { "all",        ZFS_CACHE_ALL },
207                 { NULL }
208         };
209
210         static zprop_index_t sync_table[] = {
211                 { "standard",   ZFS_SYNC_STANDARD },
212                 { "always",     ZFS_SYNC_ALWAYS },
213                 { "disabled",   ZFS_SYNC_DISABLED },
214                 { NULL }
215         };
216
217         static zprop_index_t volmode_table[] = {
218                 { "default",    ZFS_VOLMODE_DEFAULT },
219                 { "geom",       ZFS_VOLMODE_GEOM },
220                 { "dev",        ZFS_VOLMODE_DEV },
221                 { "none",       ZFS_VOLMODE_NONE },
222                 { NULL }
223         };
224
225         static zprop_index_t dnsize_table[] = {
226                 { "legacy",     ZFS_DNSIZE_LEGACY },
227                 { "auto",       ZFS_DNSIZE_AUTO },
228                 { "1k",         ZFS_DNSIZE_1K },
229                 { "2k",         ZFS_DNSIZE_2K },
230                 { "4k",         ZFS_DNSIZE_4K },
231                 { "8k",         ZFS_DNSIZE_8K },
232                 { "16k",        ZFS_DNSIZE_16K },
233                 { NULL }
234         };
235
236         static zprop_index_t redundant_metadata_table[] = {
237                 { "all",        ZFS_REDUNDANT_METADATA_ALL },
238                 { "most",       ZFS_REDUNDANT_METADATA_MOST },
239                 { NULL }
240         };
241
242         /* inherit index properties */
243         zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
244             ZFS_REDUNDANT_METADATA_ALL,
245             PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
246             "all | most", "REDUND_MD",
247             redundant_metadata_table);
248         zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
249             PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
250             "standard | always | disabled", "SYNC",
251             sync_table);
252         zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
253             ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
254             ZFS_TYPE_VOLUME,
255             "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
256             "skein", "CHECKSUM", checksum_table);
257         zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
258             PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
259             "on | off | verify | sha256[,verify], sha512[,verify], "
260             "skein[,verify]", "DEDUP", dedup_table);
261         zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
262             ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
263             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
264             "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
265             "COMPRESS", compress_table);
266         zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
267             PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
268             "hidden | visible", "SNAPDIR", snapdir_table);
269         zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
270             PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
271             "discard | groupmask | passthrough | restricted", "ACLMODE",
272             acl_mode_table);
273         zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
274             ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
275             "discard | noallow | restricted | passthrough | passthrough-x",
276             "ACLINHERIT", acl_inherit_table);
277         zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
278             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
279             "1 | 2 | 3", "COPIES", copies_table);
280         zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
281             ZFS_CACHE_ALL, PROP_INHERIT,
282             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
283             "all | none | metadata", "PRIMARYCACHE", cache_table);
284         zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
285             ZFS_CACHE_ALL, PROP_INHERIT,
286             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
287             "all | none | metadata", "SECONDARYCACHE", cache_table);
288         zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
289             PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
290             "latency | throughput", "LOGBIAS", logbias_table);
291         zprop_register_index(ZFS_PROP_VOLMODE, "volmode",
292             ZFS_VOLMODE_DEFAULT, PROP_INHERIT,
293             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
294             "default | geom | dev | none", "VOLMODE", volmode_table);
295         zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
296             ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
297             "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
298  
299         /* inherit index (boolean) properties */
300         zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
301             ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
302         zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
303             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
304             boolean_table);
305         zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
306             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
307             boolean_table);
308         zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
309             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
310             boolean_table);
311         zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
312             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
313             boolean_table);
314         zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT,
315             ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table);
316         zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
317             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
318             boolean_table);
319         zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
320             ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
321             boolean_table);
322         zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
323             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
324             boolean_table);
325
326         /* default index properties */
327         zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
328             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
329             "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
330         zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
331             PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
332             "CANMOUNT", canmount_table);
333
334         /* readonly index (boolean) properties */
335         zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
336             ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
337         zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
338             PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
339             boolean_table);
340
341         /* set once index properties */
342         zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
343             PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
344             "none | formC | formD | formKC | formKD", "NORMALIZATION",
345             normalize_table);
346         zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
347             ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
348             ZFS_TYPE_SNAPSHOT,
349             "sensitive | insensitive | mixed", "CASE", case_table);
350
351         /* set once index (boolean) properties */
352         zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
353             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
354             "on | off", "UTF8ONLY", boolean_table);
355
356         /* string properties */
357         zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
358             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
359         zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
360             ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
361         zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
362             PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
363             "MOUNTPOINT");
364         zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
365             PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
366             "SHARENFS");
367         zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
368             ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
369             "filesystem | volume | snapshot | bookmark", "TYPE");
370         zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
371             PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
372             "on | off | sharemgr(1M) options", "SHARESMB");
373         zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
374             ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
375             "<sensitivity label>", "MLSLABEL");
376         zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
377             "receive_resume_token",
378             NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
379             "<string token>", "RESUMETOK");
380
381         /* readonly number properties */
382         zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
383             ZFS_TYPE_DATASET, "<size>", "USED");
384         zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
385             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
386         zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
387             PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
388         zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
389             PROP_READONLY, ZFS_TYPE_DATASET,
390             "<1.00x or higher if compressed>", "RATIO");
391         zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
392             PROP_READONLY, ZFS_TYPE_DATASET,
393             "<1.00x or higher if compressed>", "REFRATIO");
394         zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
395             ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
396             ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
397         zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
398             PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
399             "USEDSNAP");
400         zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
401             PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
402             "USEDDS");
403         zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
404             PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
405             "USEDCHILD");
406         zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
407             PROP_READONLY,
408             ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
409         zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
410             ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
411         zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
412             ZFS_TYPE_DATASET, "<size>", "WRITTEN");
413         zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
414             PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
415             "LUSED");
416         zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
417             0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
418
419         /* default number properties */
420         zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
421             ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
422         zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
423             PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
424             "<size> | none", "RESERV");
425         zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
426             ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
427         zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
428             ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
429         zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
430             PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
431             "<size> | none", "REFRESERV");
432         zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
433             UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
434             "<count> | none", "FSLIMIT");
435         zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
436             UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
437             "<count> | none", "SSLIMIT");
438         zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
439             UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
440             "<count>", "FSCOUNT");
441         zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
442             UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
443             "<count>", "SSCOUNT");
444         zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
445             ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
446         zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
447             ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
448
449         /* inherit number properties */
450         zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
451             SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
452             ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
453
454         /* hidden properties */
455         zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER,
456             PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG");
457         zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
458             PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
459         zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
460             PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
461         zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
462             PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
463         zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
464             PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
465             "STMF_SBD_LU");
466         zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
467             PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
468             "USERACCOUNTING");
469         zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
470             PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
471         zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
472             PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
473         zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
474             PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
475         zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
476             PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
477
478         /* oddball properties */
479         zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
480             NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
481             "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
482 }
483
484 boolean_t
485 zfs_prop_delegatable(zfs_prop_t prop)
486 {
487         zprop_desc_t *pd = &zfs_prop_table[prop];
488
489         /* The mlslabel property is never delegatable. */
490         if (prop == ZFS_PROP_MLSLABEL)
491                 return (B_FALSE);
492
493         return (pd->pd_attr != PROP_READONLY);
494 }
495
496 /*
497  * Given a zfs dataset property name, returns the corresponding property ID.
498  */
499 zfs_prop_t
500 zfs_name_to_prop(const char *propname)
501 {
502         return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
503 }
504
505 /*
506  * For user property names, we allow all lowercase alphanumeric characters, plus
507  * a few useful punctuation characters.
508  */
509 static int
510 valid_char(char c)
511 {
512         return ((c >= 'a' && c <= 'z') ||
513             (c >= '0' && c <= '9') ||
514             c == '-' || c == '_' || c == '.' || c == ':');
515 }
516
517 /*
518  * Returns true if this is a valid user-defined property (one with a ':').
519  */
520 boolean_t
521 zfs_prop_user(const char *name)
522 {
523         int i;
524         char c;
525         boolean_t foundsep = B_FALSE;
526
527         for (i = 0; i < strlen(name); i++) {
528                 c = name[i];
529                 if (!valid_char(c))
530                         return (B_FALSE);
531                 if (c == ':')
532                         foundsep = B_TRUE;
533         }
534
535         if (!foundsep)
536                 return (B_FALSE);
537
538         return (B_TRUE);
539 }
540
541 /*
542  * Returns true if this is a valid userspace-type property (one with a '@').
543  * Note that after the @, any character is valid (eg, another @, for SID
544  * user@domain).
545  */
546 boolean_t
547 zfs_prop_userquota(const char *name)
548 {
549         zfs_userquota_prop_t prop;
550
551         for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
552                 if (strncmp(name, zfs_userquota_prop_prefixes[prop],
553                     strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
554                         return (B_TRUE);
555                 }
556         }
557
558         return (B_FALSE);
559 }
560
561 /*
562  * Returns true if this is a valid written@ property.
563  * Note that after the @, any character is valid (eg, another @, for
564  * written@pool/fs@origin).
565  */
566 boolean_t
567 zfs_prop_written(const char *name)
568 {
569         static const char *prefix = "written@";
570         return (strncmp(name, prefix, strlen(prefix)) == 0);
571 }
572
573 /*
574  * Tables of index types, plus functions to convert between the user view
575  * (strings) and internal representation (uint64_t).
576  */
577 int
578 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
579 {
580         return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
581 }
582
583 int
584 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
585 {
586         return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
587 }
588
589 uint64_t
590 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
591 {
592         return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
593 }
594
595 /*
596  * Returns TRUE if the property applies to any of the given dataset types.
597  */
598 boolean_t
599 zfs_prop_valid_for_type(int prop, zfs_type_t types)
600 {
601         return (zprop_valid_for_type(prop, types));
602 }
603
604 zprop_type_t
605 zfs_prop_get_type(zfs_prop_t prop)
606 {
607         return (zfs_prop_table[prop].pd_proptype);
608 }
609
610 /*
611  * Returns TRUE if the property is readonly.
612  */
613 boolean_t
614 zfs_prop_readonly(zfs_prop_t prop)
615 {
616         return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
617             zfs_prop_table[prop].pd_attr == PROP_ONETIME);
618 }
619
620 /*
621  * Returns TRUE if the property is visible (not hidden).
622  */
623 boolean_t
624 zfs_prop_visible(zfs_prop_t prop)
625 {
626         return (zfs_prop_table[prop].pd_visible);
627 }
628
629 /*
630  * Returns TRUE if the property is only allowed to be set once.
631  */
632 boolean_t
633 zfs_prop_setonce(zfs_prop_t prop)
634 {
635         return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
636 }
637
638 const char *
639 zfs_prop_default_string(zfs_prop_t prop)
640 {
641         return (zfs_prop_table[prop].pd_strdefault);
642 }
643
644 uint64_t
645 zfs_prop_default_numeric(zfs_prop_t prop)
646 {
647         return (zfs_prop_table[prop].pd_numdefault);
648 }
649
650 /*
651  * Given a dataset property ID, returns the corresponding name.
652  * Assuming the zfs dataset property ID is valid.
653  */
654 const char *
655 zfs_prop_to_name(zfs_prop_t prop)
656 {
657         return (zfs_prop_table[prop].pd_name);
658 }
659
660 /*
661  * Returns TRUE if the property is inheritable.
662  */
663 boolean_t
664 zfs_prop_inheritable(zfs_prop_t prop)
665 {
666         return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
667             zfs_prop_table[prop].pd_attr == PROP_ONETIME);
668 }
669
670 #ifndef _KERNEL
671
672 /*
673  * Returns a string describing the set of acceptable values for the given
674  * zfs property, or NULL if it cannot be set.
675  */
676 const char *
677 zfs_prop_values(zfs_prop_t prop)
678 {
679         return (zfs_prop_table[prop].pd_values);
680 }
681
682 /*
683  * Returns TRUE if this property is a string type.  Note that index types
684  * (compression, checksum) are treated as strings in userland, even though they
685  * are stored numerically on disk.
686  */
687 int
688 zfs_prop_is_string(zfs_prop_t prop)
689 {
690         return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
691             zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
692 }
693
694 /*
695  * Returns the column header for the given property.  Used only in
696  * 'zfs list -o', but centralized here with the other property information.
697  */
698 const char *
699 zfs_prop_column_name(zfs_prop_t prop)
700 {
701         return (zfs_prop_table[prop].pd_colname);
702 }
703
704 /*
705  * Returns whether the given property should be displayed right-justified for
706  * 'zfs list'.
707  */
708 boolean_t
709 zfs_prop_align_right(zfs_prop_t prop)
710 {
711         return (zfs_prop_table[prop].pd_rightalign);
712 }
713
714 #endif