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