]> git.proxmox.com Git - mirror_zfs.git/blame - module/zcommon/zfs_prop.c
Make createtxg and guid properties public
[mirror_zfs.git] / module / zcommon / zfs_prop.c
CommitLineData
34dc7c2f
BB
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/*
428870ff 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
faf0f58c 23 * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
632a242e 24 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
911c41af 25 * Copyright 2016, Joyent, Inc.
34dc7c2f
BB
26 */
27
428870ff
BB
28/* Portions Copyright 2010 Robert Milkowski */
29
34dc7c2f
BB
30#include <sys/zio.h>
31#include <sys/spa.h>
32#include <sys/u8_textprep.h>
33#include <sys/zfs_acl.h>
34#include <sys/zfs_ioctl.h>
35#include <sys/zfs_znode.h>
36
37#include "zfs_prop.h"
38#include "zfs_deleg.h"
1eeb4562 39#include "zfs_fletcher.h"
34dc7c2f
BB
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
49static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS];
50
9babb374
BB
51/* Note this is indexed by zfs_userquota_prop_t, keep the order the same */
52const char *zfs_userquota_prop_prefixes[] = {
53 "userused@",
54 "userquota@",
55 "groupused@",
1de321e6
JX
56 "groupquota@",
57 "userobjused@",
58 "userobjquota@",
59 "groupobjused@",
60 "groupobjquota@"
9babb374
BB
61};
62
34dc7c2f
BB
63zprop_desc_t *
64zfs_prop_get_table(void)
65{
66 return (zfs_prop_table);
67}
68
69void
70zfs_prop_init(void)
71{
72 static zprop_index_t checksum_table[] = {
73 { "on", ZIO_CHECKSUM_ON },
74 { "off", ZIO_CHECKSUM_OFF },
75 { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 },
76 { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
77 { "sha256", ZIO_CHECKSUM_SHA256 },
3c67d83a
TH
78 { "noparity", ZIO_CHECKSUM_NOPARITY },
79 { "sha512", ZIO_CHECKSUM_SHA512 },
80 { "skein", ZIO_CHECKSUM_SKEIN },
81 { "edonr", ZIO_CHECKSUM_EDONR },
34dc7c2f
BB
82 { NULL }
83 };
84
428870ff
BB
85 static zprop_index_t dedup_table[] = {
86 { "on", ZIO_CHECKSUM_ON },
87 { "off", ZIO_CHECKSUM_OFF },
88 { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
89 { "sha256", ZIO_CHECKSUM_SHA256 },
90 { "sha256,verify",
91 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
3c67d83a
TH
92 { "sha512", ZIO_CHECKSUM_SHA512 },
93 { "sha512,verify",
94 ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
95 { "skein", ZIO_CHECKSUM_SKEIN },
96 { "skein,verify",
97 ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
98 { "edonr,verify",
99 ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
428870ff
BB
100 { NULL }
101 };
102
34dc7c2f
BB
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 },
428870ff 117 { "zle", ZIO_COMPRESS_ZLE },
9759c60f 118 { "lz4", ZIO_COMPRESS_LZ4 },
34dc7c2f
BB
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
0b4d1b58
ED
128 static zprop_index_t snapdev_table[] = {
129 { "hidden", ZFS_SNAPDEV_HIDDEN },
130 { "visible", ZFS_SNAPDEV_VISIBLE },
131 { NULL }
132 };
133
023699cd
MM
134 static zprop_index_t acltype_table[] = {
135 { "off", ZFS_ACLTYPE_OFF },
136 { "disabled", ZFS_ACLTYPE_OFF },
137 { "noacl", ZFS_ACLTYPE_OFF },
138 { "posixacl", ZFS_ACLTYPE_POSIXACL },
139 { NULL }
140 };
141
34dc7c2f
BB
142 static zprop_index_t acl_inherit_table[] = {
143 { "discard", ZFS_ACL_DISCARD },
144 { "noallow", ZFS_ACL_NOALLOW },
145 { "restricted", ZFS_ACL_RESTRICTED },
146 { "passthrough", ZFS_ACL_PASSTHROUGH },
4e33ba4c 147 { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatibility */
b128c09f 148 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
34dc7c2f
BB
149 { NULL }
150 };
151
152 static zprop_index_t case_table[] = {
153 { "sensitive", ZFS_CASE_SENSITIVE },
154 { "insensitive", ZFS_CASE_INSENSITIVE },
155 { "mixed", ZFS_CASE_MIXED },
156 { NULL }
157 };
158
159 static zprop_index_t copies_table[] = {
160 { "1", 1 },
161 { "2", 2 },
162 { "3", 3 },
163 { NULL }
164 };
165
166 /*
167 * Use the unique flags we have to send to u8_strcmp() and/or
168 * u8_textprep() to represent the various normalization property
169 * values.
170 */
171 static zprop_index_t normalize_table[] = {
172 { "none", 0 },
173 { "formD", U8_TEXTPREP_NFD },
174 { "formKC", U8_TEXTPREP_NFKC },
175 { "formC", U8_TEXTPREP_NFC },
176 { "formKD", U8_TEXTPREP_NFKD },
177 { NULL }
178 };
179
180 static zprop_index_t version_table[] = {
181 { "1", 1 },
182 { "2", 2 },
183 { "3", 3 },
9babb374 184 { "4", 4 },
428870ff 185 { "5", 5 },
34dc7c2f
BB
186 { "current", ZPL_VERSION },
187 { NULL }
188 };
189
190 static zprop_index_t boolean_table[] = {
191 { "off", 0 },
192 { "on", 1 },
193 { NULL }
194 };
195
428870ff
BB
196 static zprop_index_t logbias_table[] = {
197 { "latency", ZFS_LOGBIAS_LATENCY },
198 { "throughput", ZFS_LOGBIAS_THROUGHPUT },
199 { NULL }
200 };
201
34dc7c2f
BB
202 static zprop_index_t canmount_table[] = {
203 { "off", ZFS_CANMOUNT_OFF },
204 { "on", ZFS_CANMOUNT_ON },
205 { "noauto", ZFS_CANMOUNT_NOAUTO },
206 { NULL }
207 };
208
b128c09f
BB
209 static zprop_index_t cache_table[] = {
210 { "none", ZFS_CACHE_NONE },
211 { "metadata", ZFS_CACHE_METADATA },
212 { "all", ZFS_CACHE_ALL },
213 { NULL }
214 };
215
428870ff
BB
216 static zprop_index_t sync_table[] = {
217 { "standard", ZFS_SYNC_STANDARD },
218 { "always", ZFS_SYNC_ALWAYS },
219 { "disabled", ZFS_SYNC_DISABLED },
220 { NULL }
221 };
222
82a37189
BB
223 static zprop_index_t xattr_table[] = {
224 { "off", ZFS_XATTR_OFF },
225 { "on", ZFS_XATTR_DIR },
226 { "sa", ZFS_XATTR_SA },
227 { "dir", ZFS_XATTR_DIR },
228 { NULL }
229 };
230
50c957f7
NB
231 static zprop_index_t dnsize_table[] = {
232 { "legacy", ZFS_DNSIZE_LEGACY },
233 { "auto", ZFS_DNSIZE_AUTO },
234 { "1k", ZFS_DNSIZE_1K },
235 { "2k", ZFS_DNSIZE_2K },
236 { "4k", ZFS_DNSIZE_4K },
237 { "8k", ZFS_DNSIZE_8K },
238 { "16k", ZFS_DNSIZE_16K },
239 { NULL }
240 };
241
faf0f58c
MA
242 static zprop_index_t redundant_metadata_table[] = {
243 { "all", ZFS_REDUNDANT_METADATA_ALL },
244 { "most", ZFS_REDUNDANT_METADATA_MOST },
245 { NULL }
246 };
247
34dc7c2f 248 /* inherit index properties */
faf0f58c
MA
249 zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata",
250 ZFS_REDUNDANT_METADATA_ALL,
251 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
252 "all | most", "REDUND_MD",
253 redundant_metadata_table);
428870ff 254 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
34dc7c2f 255 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
428870ff
BB
256 "standard | always | disabled", "SYNC",
257 sync_table);
258 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
259 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
260 ZFS_TYPE_VOLUME,
3c67d83a
TH
261 "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
262 "skein | edonr", "CHECKSUM", checksum_table);
428870ff
BB
263 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
264 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
3c67d83a
TH
265 "on | off | verify | sha256[,verify], sha512[,verify], "
266 "skein[,verify], edonr,verify", "DEDUP", dedup_table);
428870ff 267 zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
34dc7c2f
BB
268 ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
269 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
9759c60f 270 "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS",
428870ff
BB
271 compress_table);
272 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
34dc7c2f
BB
273 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
274 "hidden | visible", "SNAPDIR", snapdir_table);
0b4d1b58
ED
275 zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN,
276 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
277 "hidden | visible", "SNAPDEV", snapdev_table);
023699cd
MM
278 zprop_register_index(ZFS_PROP_ACLTYPE, "acltype", ZFS_ACLTYPE_OFF,
279 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
280 "noacl | posixacl", "ACLTYPE", acltype_table);
428870ff
BB
281 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
282 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
b128c09f 283 "discard | noallow | restricted | passthrough | passthrough-x",
34dc7c2f 284 "ACLINHERIT", acl_inherit_table);
428870ff
BB
285 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
286 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
34dc7c2f 287 "1 | 2 | 3", "COPIES", copies_table);
428870ff 288 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
b128c09f
BB
289 ZFS_CACHE_ALL, PROP_INHERIT,
290 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
291 "all | none | metadata", "PRIMARYCACHE", cache_table);
428870ff 292 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
b128c09f
BB
293 ZFS_CACHE_ALL, PROP_INHERIT,
294 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
295 "all | none | metadata", "SECONDARYCACHE", cache_table);
428870ff
BB
296 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
297 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
298 "latency | throughput", "LOGBIAS", logbias_table);
82a37189
BB
299 zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR,
300 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
301 "on | off | dir | sa", "XATTR", xattr_table);
50c957f7
NB
302 zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize",
303 ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
304 "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table);
34dc7c2f
BB
305
306 /* inherit index (boolean) properties */
428870ff 307 zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
34dc7c2f 308 ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
6d111134
TC
309 zprop_register_index(ZFS_PROP_RELATIME, "relatime", 0, PROP_INHERIT,
310 ZFS_TYPE_FILESYSTEM, "on | off", "RELATIME", boolean_table);
428870ff 311 zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
34dc7c2f
BB
312 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
313 boolean_table);
428870ff 314 zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
34dc7c2f
BB
315 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
316 boolean_table);
428870ff 317 zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
34dc7c2f
BB
318 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
319 boolean_table);
428870ff 320 zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
34dc7c2f
BB
321 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
322 boolean_table);
428870ff 323 zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
34dc7c2f 324 ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
428870ff 325 zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
82a37189 326 ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table);
428870ff 327 zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
34dc7c2f
BB
328 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
329 boolean_table);
f67d7090
TF
330 zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 0, PROP_INHERIT,
331 ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table);
34dc7c2f
BB
332
333 /* default index properties */
428870ff 334 zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
34dc7c2f 335 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
330d06f9 336 "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
428870ff 337 zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
34dc7c2f
BB
338 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
339 "CANMOUNT", canmount_table);
340
341 /* readonly index (boolean) properties */
428870ff 342 zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
34dc7c2f 343 ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
428870ff 344 zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
45d1cae3
BB
345 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
346 boolean_table);
34dc7c2f
BB
347
348 /* set once index properties */
428870ff 349 zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
34dc7c2f
BB
350 PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
351 "none | formC | formD | formKC | formKD", "NORMALIZATION",
352 normalize_table);
428870ff
BB
353 zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
354 ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
355 ZFS_TYPE_SNAPSHOT,
34dc7c2f
BB
356 "sensitive | insensitive | mixed", "CASE", case_table);
357
358 /* set once index (boolean) properties */
428870ff 359 zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
34dc7c2f
BB
360 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
361 "on | off", "UTF8ONLY", boolean_table);
362
363 /* string properties */
428870ff 364 zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
34dc7c2f 365 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
330d06f9
MA
366 zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
367 ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
428870ff
BB
368 zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
369 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
370 "MOUNTPOINT");
371 zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
372 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
373 "SHARENFS");
374 zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
da536844
MA
375 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
376 "filesystem | volume | snapshot | bookmark", "TYPE");
428870ff
BB
377 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
378 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
379 "on | off | sharemgr(1M) options", "SHARESMB");
380 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
381 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
382 "<sensitivity label>", "MLSLABEL");
11b9ec23
MT
383 zprop_register_string(ZFS_PROP_SELINUX_CONTEXT, "context",
384 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux context>",
385 "CONTEXT");
386 zprop_register_string(ZFS_PROP_SELINUX_FSCONTEXT, "fscontext",
387 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux fscontext>",
388 "FSCONTEXT");
389 zprop_register_string(ZFS_PROP_SELINUX_DEFCONTEXT, "defcontext",
390 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux defcontext>",
391 "DEFCONTEXT");
392 zprop_register_string(ZFS_PROP_SELINUX_ROOTCONTEXT, "rootcontext",
393 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux rootcontext>",
394 "ROOTCONTEXT");
47dfff3b
MA
395 zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN,
396 "receive_resume_token",
397 NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
398 "<string token>", "RESUMETOK");
34dc7c2f
BB
399
400 /* readonly number properties */
428870ff 401 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
34dc7c2f 402 ZFS_TYPE_DATASET, "<size>", "USED");
428870ff 403 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
34dc7c2f 404 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
428870ff
BB
405 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
406 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
407 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
34dc7c2f
BB
408 PROP_READONLY, ZFS_TYPE_DATASET,
409 "<1.00x or higher if compressed>", "RATIO");
f5fc4aca
MA
410 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
411 PROP_READONLY, ZFS_TYPE_DATASET,
412 "<1.00x or higher if compressed>", "REFRATIO");
428870ff
BB
413 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
414 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
34dc7c2f 415 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
428870ff
BB
416 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
417 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
418 "USEDSNAP");
419 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
420 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
421 "USEDDS");
422 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
423 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
424 "USEDCHILD");
425 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
b128c09f
BB
426 PROP_READONLY,
427 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
428870ff 428 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
45d1cae3 429 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
330d06f9
MA
430 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
431 ZFS_TYPE_DATASET, "<size>", "WRITTEN");
24a64651
MA
432 zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
433 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED");
434 zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
435 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
911c41af
GM
436 zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count",
437 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
438 "<count>", "FSCOUNT");
439 zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count",
440 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
441 "<count>", "SSCOUNT");
305bc4b3
CS
442 zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY,
443 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID");
444 zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY,
445 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG");
34dc7c2f
BB
446
447 /* default number properties */
428870ff 448 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
34dc7c2f 449 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
428870ff
BB
450 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
451 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
452 "<size> | none", "RESERV");
453 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
962d5242 454 ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
428870ff 455 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
34dc7c2f 456 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
428870ff 457 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
34dc7c2f
BB
458 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
459 "<size> | none", "REFRESERV");
788eb90c
JJ
460 zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit",
461 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM,
462 "<count> | none", "FSLIMIT");
463 zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit",
464 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
465 "<count> | none", "SSLIMIT");
34dc7c2f
BB
466
467 /* inherit number properties */
428870ff 468 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
f1512ee6
MA
469 SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT,
470 ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE");
34dc7c2f
BB
471
472 /* hidden properties */
428870ff
BB
473 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
474 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
475 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
da536844 476 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME");
428870ff
BB
477 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
478 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
479 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
9babb374
BB
480 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
481 "STMF_SBD_LU");
428870ff
BB
482 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
483 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
484 "USERACCOUNTING");
485 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
486 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
487 zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
488 PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
96c2e961
KW
489 zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
490 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
1715493f
MA
491 zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING,
492 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP");
428870ff
BB
493
494 /*
495 * Property to be removed once libbe is integrated
496 */
497 zprop_register_hidden(ZFS_PROP_PRIVATE, "priv_prop",
498 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_FILESYSTEM,
499 "PRIV_PROP");
34dc7c2f
BB
500
501 /* oddball properties */
428870ff 502 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
da536844 503 NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK,
34dc7c2f
BB
504 "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
505}
506
507boolean_t
508zfs_prop_delegatable(zfs_prop_t prop)
509{
510 zprop_desc_t *pd = &zfs_prop_table[prop];
428870ff
BB
511
512 /* The mlslabel property is never delegatable. */
513 if (prop == ZFS_PROP_MLSLABEL)
514 return (B_FALSE);
515
34dc7c2f
BB
516 return (pd->pd_attr != PROP_READONLY);
517}
518
519/*
520 * Given a zfs dataset property name, returns the corresponding property ID.
521 */
522zfs_prop_t
523zfs_name_to_prop(const char *propname)
524{
525 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
526}
527
34dc7c2f
BB
528/*
529 * For user property names, we allow all lowercase alphanumeric characters, plus
530 * a few useful punctuation characters.
531 */
532static int
533valid_char(char c)
534{
535 return ((c >= 'a' && c <= 'z') ||
536 (c >= '0' && c <= '9') ||
537 c == '-' || c == '_' || c == '.' || c == ':');
538}
539
540/*
541 * Returns true if this is a valid user-defined property (one with a ':').
542 */
543boolean_t
544zfs_prop_user(const char *name)
545{
546 int i;
547 char c;
548 boolean_t foundsep = B_FALSE;
549
550 for (i = 0; i < strlen(name); i++) {
551 c = name[i];
552 if (!valid_char(c))
553 return (B_FALSE);
554 if (c == ':')
555 foundsep = B_TRUE;
556 }
557
558 if (!foundsep)
559 return (B_FALSE);
560
561 return (B_TRUE);
562}
563
9babb374
BB
564/*
565 * Returns true if this is a valid userspace-type property (one with a '@').
566 * Note that after the @, any character is valid (eg, another @, for SID
567 * user@domain).
568 */
569boolean_t
570zfs_prop_userquota(const char *name)
571{
572 zfs_userquota_prop_t prop;
573
574 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
575 if (strncmp(name, zfs_userquota_prop_prefixes[prop],
576 strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
577 return (B_TRUE);
578 }
579 }
580
581 return (B_FALSE);
582}
583
330d06f9
MA
584/*
585 * Returns true if this is a valid written@ property.
586 * Note that after the @, any character is valid (eg, another @, for
587 * written@pool/fs@origin).
588 */
589boolean_t
590zfs_prop_written(const char *name)
591{
592 static const char *prefix = "written@";
593 return (strncmp(name, prefix, strlen(prefix)) == 0);
594}
595
34dc7c2f
BB
596/*
597 * Tables of index types, plus functions to convert between the user view
598 * (strings) and internal representation (uint64_t).
599 */
600int
601zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
602{
603 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
604}
605
606int
607zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
608{
609 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
610}
611
428870ff
BB
612uint64_t
613zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
614{
615 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
616}
617
34dc7c2f
BB
618/*
619 * Returns TRUE if the property applies to any of the given dataset types.
620 */
b128c09f 621boolean_t
962d5242 622zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck)
34dc7c2f 623{
962d5242 624 return (zprop_valid_for_type(prop, types, headcheck));
34dc7c2f
BB
625}
626
627zprop_type_t
628zfs_prop_get_type(zfs_prop_t prop)
629{
630 return (zfs_prop_table[prop].pd_proptype);
631}
632
633/*
634 * Returns TRUE if the property is readonly.
635 */
636boolean_t
637zfs_prop_readonly(zfs_prop_t prop)
638{
639 return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
640 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
641}
642
643/*
644 * Returns TRUE if the property is only allowed to be set once.
645 */
646boolean_t
647zfs_prop_setonce(zfs_prop_t prop)
648{
649 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
650}
651
652const char *
653zfs_prop_default_string(zfs_prop_t prop)
654{
655 return (zfs_prop_table[prop].pd_strdefault);
656}
657
658uint64_t
659zfs_prop_default_numeric(zfs_prop_t prop)
660{
661 return (zfs_prop_table[prop].pd_numdefault);
662}
663
664/*
665 * Given a dataset property ID, returns the corresponding name.
666 * Assuming the zfs dataset property ID is valid.
667 */
668const char *
669zfs_prop_to_name(zfs_prop_t prop)
670{
671 return (zfs_prop_table[prop].pd_name);
672}
673
674/*
675 * Returns TRUE if the property is inheritable.
676 */
677boolean_t
678zfs_prop_inheritable(zfs_prop_t prop)
679{
680 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
681 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
682}
683
684#ifndef _KERNEL
685
686/*
687 * Returns a string describing the set of acceptable values for the given
688 * zfs property, or NULL if it cannot be set.
689 */
690const char *
691zfs_prop_values(zfs_prop_t prop)
692{
693 return (zfs_prop_table[prop].pd_values);
694}
695
696/*
697 * Returns TRUE if this property is a string type. Note that index types
698 * (compression, checksum) are treated as strings in userland, even though they
699 * are stored numerically on disk.
700 */
701int
702zfs_prop_is_string(zfs_prop_t prop)
703{
704 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
705 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
706}
707
708/*
709 * Returns the column header for the given property. Used only in
710 * 'zfs list -o', but centralized here with the other property information.
711 */
712const char *
713zfs_prop_column_name(zfs_prop_t prop)
714{
715 return (zfs_prop_table[prop].pd_colname);
716}
717
718/*
719 * Returns whether the given property should be displayed right-justified for
720 * 'zfs list'.
721 */
722boolean_t
723zfs_prop_align_right(zfs_prop_t prop)
724{
725 return (zfs_prop_table[prop].pd_rightalign);
726}
727
728#endif
c28b2279
BB
729
730#if defined(_KERNEL) && defined(HAVE_SPL)
b4f3666a
BB
731static int __init
732zcommon_init(void)
733{
1eeb4562 734 fletcher_4_init();
b4f3666a
BB
735 return (0);
736}
c28b2279 737
b4f3666a
BB
738static void __exit
739zcommon_fini(void)
740{
1eeb4562 741 fletcher_4_fini();
b4f3666a 742}
c28b2279 743
b4f3666a
BB
744module_init(zcommon_init);
745module_exit(zcommon_fini);
c28b2279
BB
746
747MODULE_DESCRIPTION("Generic ZFS support");
748MODULE_AUTHOR(ZFS_META_AUTHOR);
749MODULE_LICENSE(ZFS_META_LICENSE);
99e349db 750MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE);
c28b2279
BB
751
752/* zfs dataset property functions */
753EXPORT_SYMBOL(zfs_userquota_prop_prefixes);
754EXPORT_SYMBOL(zfs_prop_init);
755EXPORT_SYMBOL(zfs_prop_get_type);
756EXPORT_SYMBOL(zfs_prop_get_table);
757EXPORT_SYMBOL(zfs_prop_delegatable);
758
759/* Dataset property functions shared between libzfs and kernel. */
760EXPORT_SYMBOL(zfs_prop_default_string);
761EXPORT_SYMBOL(zfs_prop_default_numeric);
762EXPORT_SYMBOL(zfs_prop_readonly);
763EXPORT_SYMBOL(zfs_prop_inheritable);
764EXPORT_SYMBOL(zfs_prop_setonce);
765EXPORT_SYMBOL(zfs_prop_to_name);
766EXPORT_SYMBOL(zfs_name_to_prop);
767EXPORT_SYMBOL(zfs_prop_user);
768EXPORT_SYMBOL(zfs_prop_userquota);
769EXPORT_SYMBOL(zfs_prop_index_to_string);
770EXPORT_SYMBOL(zfs_prop_string_to_index);
771EXPORT_SYMBOL(zfs_prop_valid_for_type);
772
773#endif