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) 2012 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 */
27
28 /* Portions Copyright 2010 Robert Milkowski */
29
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"
39
40 #if defined(_KERNEL)
41 #include <sys/systm.h>
42 #else
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
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@",
55 "groupquota@"
56 };
57
58 zprop_desc_t *
59 zfs_prop_get_table(void)
60 {
61 return (zfs_prop_table);
62 }
63
64 void
65 zfs_prop_init(void)
66 {
67 static zprop_index_t checksum_table[] = {
68 { "on", ZIO_CHECKSUM_ON },
69 { "off", ZIO_CHECKSUM_OFF },
70 { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 },
71 { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
72 { "sha256", ZIO_CHECKSUM_SHA256 },
73 { "noparity", ZIO_CHECKSUM_NOPARITY },
74 { "sha512", ZIO_CHECKSUM_SHA512 },
75 { "skein", ZIO_CHECKSUM_SKEIN },
76 { "edonr", ZIO_CHECKSUM_EDONR },
77 { NULL }
78 };
79
80 static zprop_index_t dedup_table[] = {
81 { "on", ZIO_CHECKSUM_ON },
82 { "off", ZIO_CHECKSUM_OFF },
83 { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY },
84 { "sha256", ZIO_CHECKSUM_SHA256 },
85 { "sha256,verify",
86 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
87 { "sha512", ZIO_CHECKSUM_SHA512 },
88 { "sha512,verify",
89 ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
90 { "skein", ZIO_CHECKSUM_SKEIN },
91 { "skein,verify",
92 ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
93 { "edonr", ZIO_CHECKSUM_EDONR },
94 { "edonr,verify",
95 ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
96 { NULL }
97 };
98
99 static zprop_index_t compress_table[] = {
100 { "on", ZIO_COMPRESS_ON },
101 { "off", ZIO_COMPRESS_OFF },
102 { "lzjb", ZIO_COMPRESS_LZJB },
103 { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */
104 { "gzip-1", ZIO_COMPRESS_GZIP_1 },
105 { "gzip-2", ZIO_COMPRESS_GZIP_2 },
106 { "gzip-3", ZIO_COMPRESS_GZIP_3 },
107 { "gzip-4", ZIO_COMPRESS_GZIP_4 },
108 { "gzip-5", ZIO_COMPRESS_GZIP_5 },
109 { "gzip-6", ZIO_COMPRESS_GZIP_6 },
110 { "gzip-7", ZIO_COMPRESS_GZIP_7 },
111 { "gzip-8", ZIO_COMPRESS_GZIP_8 },
112 { "gzip-9", ZIO_COMPRESS_GZIP_9 },
113 { "zle", ZIO_COMPRESS_ZLE },
114 { "lz4", ZIO_COMPRESS_LZ4 },
115 { NULL }
116 };
117
118 static zprop_index_t snapdir_table[] = {
119 { "hidden", ZFS_SNAPDIR_HIDDEN },
120 { "visible", ZFS_SNAPDIR_VISIBLE },
121 { NULL }
122 };
123
124 static zprop_index_t acl_mode_table[] = {
125 { "discard", ZFS_ACL_DISCARD },
126 { "groupmask", ZFS_ACL_GROUPMASK },
127 { "passthrough", ZFS_ACL_PASSTHROUGH },
128 { "restricted", ZFS_ACL_RESTRICTED },
129 { NULL }
130 };
131
132 static zprop_index_t acl_inherit_table[] = {
133 { "discard", ZFS_ACL_DISCARD },
134 { "noallow", ZFS_ACL_NOALLOW },
135 { "restricted", ZFS_ACL_RESTRICTED },
136 { "passthrough", ZFS_ACL_PASSTHROUGH },
137 { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */
138 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X },
139 { NULL }
140 };
141
142 static zprop_index_t case_table[] = {
143 { "sensitive", ZFS_CASE_SENSITIVE },
144 { "insensitive", ZFS_CASE_INSENSITIVE },
145 { "mixed", ZFS_CASE_MIXED },
146 { NULL }
147 };
148
149 static zprop_index_t copies_table[] = {
150 { "1", 1 },
151 { "2", 2 },
152 { "3", 3 },
153 { NULL }
154 };
155
156 /*
157 * Use the unique flags we have to send to u8_strcmp() and/or
158 * u8_textprep() to represent the various normalization property
159 * values.
160 */
161 static zprop_index_t normalize_table[] = {
162 { "none", 0 },
163 { "formD", U8_TEXTPREP_NFD },
164 { "formKC", U8_TEXTPREP_NFKC },
165 { "formC", U8_TEXTPREP_NFC },
166 { "formKD", U8_TEXTPREP_NFKD },
167 { NULL }
168 };
169
170 static zprop_index_t version_table[] = {
171 { "1", 1 },
172 { "2", 2 },
173 { "3", 3 },
174 { "4", 4 },
175 { "5", 5 },
176 { "current", ZPL_VERSION },
177 { NULL }
178 };
179
180 static zprop_index_t boolean_table[] = {
181 { "off", 0 },
182 { "on", 1 },
183 { NULL }
184 };
185
186 static zprop_index_t logbias_table[] = {
187 { "latency", ZFS_LOGBIAS_LATENCY },
188 { "throughput", ZFS_LOGBIAS_THROUGHPUT },
189 { NULL }
190 };
191
192 static zprop_index_t canmount_table[] = {
193 { "off", ZFS_CANMOUNT_OFF },
194 { "on", ZFS_CANMOUNT_ON },
195 { "noauto", ZFS_CANMOUNT_NOAUTO },
196 { NULL }
197 };
198
199 static zprop_index_t cache_table[] = {
200 { "none", ZFS_CACHE_NONE },
201 { "metadata", ZFS_CACHE_METADATA },
202 { "all", ZFS_CACHE_ALL },
203 { NULL }
204 };
205
206 static zprop_index_t sync_table[] = {
207 { "standard", ZFS_SYNC_STANDARD },
208 { "always", ZFS_SYNC_ALWAYS },
209 { "disabled", ZFS_SYNC_DISABLED },
210 { NULL }
211 };
212
213 /* inherit index properties */
214 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD,
215 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
216 "standard | always | disabled", "SYNC",
217 sync_table);
218 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum",
219 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM |
220 ZFS_TYPE_VOLUME,
221 "on | off | fletcher2 | fletcher4 | sha256 | sha512 | "
222 "skein | edonr", "CHECKSUM", checksum_table);
223 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF,
224 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
225 "on | off | verify | sha256[,verify], sha512[,verify], "
226 "skein[,verify], edonr[,verify]", "DEDUP", dedup_table);
227 zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
228 ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
229 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
230 "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4",
231 "COMPRESS", compress_table);
232 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
233 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
234 "hidden | visible", "SNAPDIR", snapdir_table);
235 zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD,
236 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
237 "discard | groupmask | passthrough | restricted", "ACLMODE",
238 acl_mode_table);
239 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
240 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
241 "discard | noallow | restricted | passthrough | passthrough-x",
242 "ACLINHERIT", acl_inherit_table);
243 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT,
244 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
245 "1 | 2 | 3", "COPIES", copies_table);
246 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache",
247 ZFS_CACHE_ALL, PROP_INHERIT,
248 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
249 "all | none | metadata", "PRIMARYCACHE", cache_table);
250 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache",
251 ZFS_CACHE_ALL, PROP_INHERIT,
252 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME,
253 "all | none | metadata", "SECONDARYCACHE", cache_table);
254 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY,
255 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
256 "latency | throughput", "LOGBIAS", logbias_table);
257
258 /* inherit index (boolean) properties */
259 zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT,
260 ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table);
261 zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT,
262 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES",
263 boolean_table);
264 zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT,
265 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC",
266 boolean_table);
267 zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT,
268 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID",
269 boolean_table);
270 zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT,
271 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY",
272 boolean_table);
273 zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT,
274 ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table);
275 zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT,
276 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR",
277 boolean_table);
278 zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT,
279 ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN",
280 boolean_table);
281 zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT,
282 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND",
283 boolean_table);
284
285 /* default index properties */
286 zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,
287 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
288 "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table);
289 zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON,
290 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto",
291 "CANMOUNT", canmount_table);
292
293 /* readonly index (boolean) properties */
294 zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY,
295 ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table);
296 zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0,
297 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY",
298 boolean_table);
299
300 /* set once index properties */
301 zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0,
302 PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
303 "none | formC | formD | formKC | formKD", "NORMALIZATION",
304 normalize_table);
305 zprop_register_index(ZFS_PROP_CASE, "casesensitivity",
306 ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM |
307 ZFS_TYPE_SNAPSHOT,
308 "sensitive | insensitive | mixed", "CASE", case_table);
309
310 /* set once index (boolean) properties */
311 zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME,
312 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT,
313 "on | off", "UTF8ONLY", boolean_table);
314
315 /* string properties */
316 zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY,
317 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN");
318 zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY,
319 ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES");
320 zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/",
321 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none",
322 "MOUNTPOINT");
323 zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off",
324 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options",
325 "SHARENFS");
326 zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY,
327 ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE");
328 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off",
329 PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
330 "on | off | sharemgr(1M) options", "SHARESMB");
331 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel",
332 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET,
333 "<sensitivity label>", "MLSLABEL");
334
335 /* readonly number properties */
336 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY,
337 ZFS_TYPE_DATASET, "<size>", "USED");
338 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY,
339 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL");
340 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0,
341 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER");
342 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
343 PROP_READONLY, ZFS_TYPE_DATASET,
344 "<1.00x or higher if compressed>", "RATIO");
345 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
346 PROP_READONLY, ZFS_TYPE_DATASET,
347 "<1.00x or higher if compressed>", "REFRATIO");
348 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
349 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
350 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
351 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0,
352 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
353 "USEDSNAP");
354 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0,
355 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
356 "USEDDS");
357 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0,
358 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>",
359 "USEDCHILD");
360 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0,
361 PROP_READONLY,
362 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV");
363 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY,
364 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS");
365 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY,
366 ZFS_TYPE_DATASET, "<size>", "WRITTEN");
367 zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0,
368 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED");
369 zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced",
370 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER");
371
372 /* default number properties */
373 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT,
374 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA");
375 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0,
376 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
377 "<size> | none", "RESERV");
378 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT,
379 ZFS_TYPE_VOLUME, "<size>", "VOLSIZE");
380 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT,
381 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA");
382 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0,
383 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
384 "<size> | none", "REFRESERV");
385
386 /* inherit number properties */
387 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize",
388 SPA_MAXBLOCKSIZE, PROP_INHERIT,
389 ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE");
390
391 /* hidden properties */
392 zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER,
393 PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG");
394 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER,
395 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES");
396 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING,
397 PROP_READONLY, ZFS_TYPE_DATASET, "NAME");
398 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions",
399 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS");
400 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu",
401 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME,
402 "STMF_SBD_LU");
403 zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER,
404 PROP_READONLY, ZFS_TYPE_DATASET, "GUID");
405 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting",
406 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET,
407 "USERACCOUNTING");
408 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER,
409 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE");
410 zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER,
411 PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID");
412 zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent",
413 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT");
414
415 /* oddball properties */
416 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0,
417 NULL, PROP_READONLY, ZFS_TYPE_DATASET,
418 "<date>", "CREATION", B_FALSE, B_TRUE, NULL);
419 }
420
421 boolean_t
422 zfs_prop_delegatable(zfs_prop_t prop)
423 {
424 zprop_desc_t *pd = &zfs_prop_table[prop];
425
426 /* The mlslabel property is never delegatable. */
427 if (prop == ZFS_PROP_MLSLABEL)
428 return (B_FALSE);
429
430 return (pd->pd_attr != PROP_READONLY);
431 }
432
433 /*
434 * Given a zfs dataset property name, returns the corresponding property ID.
435 */
436 zfs_prop_t
437 zfs_name_to_prop(const char *propname)
438 {
439 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET));
440 }
441
442 /*
443 * For user property names, we allow all lowercase alphanumeric characters, plus
444 * a few useful punctuation characters.
445 */
446 static int
447 valid_char(char c)
448 {
449 return ((c >= 'a' && c <= 'z') ||
450 (c >= '0' && c <= '9') ||
451 c == '-' || c == '_' || c == '.' || c == ':');
452 }
453
454 /*
455 * Returns true if this is a valid user-defined property (one with a ':').
456 */
457 boolean_t
458 zfs_prop_user(const char *name)
459 {
460 int i;
461 char c;
462 boolean_t foundsep = B_FALSE;
463
464 for (i = 0; i < strlen(name); i++) {
465 c = name[i];
466 if (!valid_char(c))
467 return (B_FALSE);
468 if (c == ':')
469 foundsep = B_TRUE;
470 }
471
472 if (!foundsep)
473 return (B_FALSE);
474
475 return (B_TRUE);
476 }
477
478 /*
479 * Returns true if this is a valid userspace-type property (one with a '@').
480 * Note that after the @, any character is valid (eg, another @, for SID
481 * user@domain).
482 */
483 boolean_t
484 zfs_prop_userquota(const char *name)
485 {
486 zfs_userquota_prop_t prop;
487
488 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) {
489 if (strncmp(name, zfs_userquota_prop_prefixes[prop],
490 strlen(zfs_userquota_prop_prefixes[prop])) == 0) {
491 return (B_TRUE);
492 }
493 }
494
495 return (B_FALSE);
496 }
497
498 /*
499 * Returns true if this is a valid written@ property.
500 * Note that after the @, any character is valid (eg, another @, for
501 * written@pool/fs@origin).
502 */
503 boolean_t
504 zfs_prop_written(const char *name)
505 {
506 static const char *prefix = "written@";
507 return (strncmp(name, prefix, strlen(prefix)) == 0);
508 }
509
510 /*
511 * Tables of index types, plus functions to convert between the user view
512 * (strings) and internal representation (uint64_t).
513 */
514 int
515 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index)
516 {
517 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET));
518 }
519
520 int
521 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string)
522 {
523 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET));
524 }
525
526 uint64_t
527 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed)
528 {
529 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET));
530 }
531
532 /*
533 * Returns TRUE if the property applies to any of the given dataset types.
534 */
535 boolean_t
536 zfs_prop_valid_for_type(int prop, zfs_type_t types)
537 {
538 return (zprop_valid_for_type(prop, types));
539 }
540
541 zprop_type_t
542 zfs_prop_get_type(zfs_prop_t prop)
543 {
544 return (zfs_prop_table[prop].pd_proptype);
545 }
546
547 /*
548 * Returns TRUE if the property is readonly.
549 */
550 boolean_t
551 zfs_prop_readonly(zfs_prop_t prop)
552 {
553 return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
554 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
555 }
556
557 /*
558 * Returns TRUE if the property is only allowed to be set once.
559 */
560 boolean_t
561 zfs_prop_setonce(zfs_prop_t prop)
562 {
563 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME);
564 }
565
566 const char *
567 zfs_prop_default_string(zfs_prop_t prop)
568 {
569 return (zfs_prop_table[prop].pd_strdefault);
570 }
571
572 uint64_t
573 zfs_prop_default_numeric(zfs_prop_t prop)
574 {
575 return (zfs_prop_table[prop].pd_numdefault);
576 }
577
578 /*
579 * Given a dataset property ID, returns the corresponding name.
580 * Assuming the zfs dataset property ID is valid.
581 */
582 const char *
583 zfs_prop_to_name(zfs_prop_t prop)
584 {
585 return (zfs_prop_table[prop].pd_name);
586 }
587
588 /*
589 * Returns TRUE if the property is inheritable.
590 */
591 boolean_t
592 zfs_prop_inheritable(zfs_prop_t prop)
593 {
594 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
595 zfs_prop_table[prop].pd_attr == PROP_ONETIME);
596 }
597
598 #ifndef _KERNEL
599
600 /*
601 * Returns a string describing the set of acceptable values for the given
602 * zfs property, or NULL if it cannot be set.
603 */
604 const char *
605 zfs_prop_values(zfs_prop_t prop)
606 {
607 return (zfs_prop_table[prop].pd_values);
608 }
609
610 /*
611 * Returns TRUE if this property is a string type. Note that index types
612 * (compression, checksum) are treated as strings in userland, even though they
613 * are stored numerically on disk.
614 */
615 int
616 zfs_prop_is_string(zfs_prop_t prop)
617 {
618 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
619 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
620 }
621
622 /*
623 * Returns the column header for the given property. Used only in
624 * 'zfs list -o', but centralized here with the other property information.
625 */
626 const char *
627 zfs_prop_column_name(zfs_prop_t prop)
628 {
629 return (zfs_prop_table[prop].pd_colname);
630 }
631
632 /*
633 * Returns whether the given property should be displayed right-justified for
634 * 'zfs list'.
635 */
636 boolean_t
637 zfs_prop_align_right(zfs_prop_t prop)
638 {
639 return (zfs_prop_table[prop].pd_rightalign);
640 }
641
642 #endif