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