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