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