zfs_prop.c revision 265744
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) 2013 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 48static 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 */ 51const char *zfs_userquota_prop_prefixes[] = { 52 "userused@", 53 "userquota@", 54 "groupused@", 55 "groupquota@" 56}; 57 58zprop_desc_t * 59zfs_prop_get_table(void) 60{ 61 return (zfs_prop_table); 62} 63 64void 65zfs_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 static zprop_index_t volmode_table[] = { 202 { "default", ZFS_VOLMODE_DEFAULT }, 203 { "geom", ZFS_VOLMODE_GEOM }, 204 { "dev", ZFS_VOLMODE_DEV }, 205 { "none", ZFS_VOLMODE_NONE }, 206 { NULL } 207 }; 208 209 /* inherit index properties */ 210 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, 211 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 212 "standard | always | disabled", "SYNC", 213 sync_table); 214 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", 215 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | 216 ZFS_TYPE_VOLUME, 217 "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 218 checksum_table); 219 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 220 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 221 "on | off | verify | sha256[,verify]", "DEDUP", 222 dedup_table); 223 zprop_register_index(ZFS_PROP_COMPRESSION, "compression", 224 ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 225 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 226 "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", 227 "COMPRESS", compress_table); 228 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 229 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 230 "hidden | visible", "SNAPDIR", snapdir_table); 231 zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD, 232 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 233 "discard | groupmask | passthrough | restricted", "ACLMODE", 234 acl_mode_table); 235 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", 236 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 237 "discard | noallow | restricted | passthrough | passthrough-x", 238 "ACLINHERIT", acl_inherit_table); 239 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, 240 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 241 "1 | 2 | 3", "COPIES", copies_table); 242 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 243 ZFS_CACHE_ALL, PROP_INHERIT, 244 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 245 "all | none | metadata", "PRIMARYCACHE", cache_table); 246 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 247 ZFS_CACHE_ALL, PROP_INHERIT, 248 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 249 "all | none | metadata", "SECONDARYCACHE", cache_table); 250 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 251 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 252 "latency | throughput", "LOGBIAS", logbias_table); 253 zprop_register_index(ZFS_PROP_VOLMODE, "volmode", 254 ZFS_VOLMODE_DEFAULT, PROP_INHERIT, 255 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 256 "default | geom | dev | none", "VOLMODE", volmode_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, "jailed", 0, PROP_INHERIT, 274 ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", 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 | ZFS_TYPE_BOOKMARK, 328 "filesystem | volume | snapshot | bookmark", "TYPE"); 329 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", 330 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 331 "on | off | sharemgr(1M) options", "SHARESMB"); 332 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", 333 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, 334 "<sensitivity label>", "MLSLABEL"); 335 336 /* readonly number properties */ 337 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 338 ZFS_TYPE_DATASET, "<size>", "USED"); 339 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 340 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 341 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, 342 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); 343 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 344 PROP_READONLY, ZFS_TYPE_DATASET, 345 "<1.00x or higher if compressed>", "RATIO"); 346 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, 347 PROP_READONLY, ZFS_TYPE_DATASET, 348 "<1.00x or higher if compressed>", "REFRATIO"); 349 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 350 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 351 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 352 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, 353 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 354 "USEDSNAP"); 355 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, 356 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 357 "USEDDS"); 358 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, 359 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 360 "USEDCHILD"); 361 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 362 PROP_READONLY, 363 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 364 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 365 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 366 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY, 367 ZFS_TYPE_DATASET, "<size>", "WRITTEN"); 368 zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0, 369 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LUSED"); 370 zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced", 371 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER"); 372 373 /* default number properties */ 374 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 375 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 376 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, 377 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 378 "<size> | none", "RESERV"); 379 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 380 ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 381 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 382 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 383 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 384 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 385 "<size> | none", "REFRESERV"); 386 zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit", 387 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, 388 "<count> | none", "FSLIMIT"); 389 zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit", 390 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 391 "<count> | none", "SSLIMIT"); 392 zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count", 393 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, 394 "<count>", "FSCOUNT"); 395 zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count", 396 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 397 "<count>", "SSCOUNT"); 398 399 /* inherit number properties */ 400 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", 401 SPA_MAXBLOCKSIZE, PROP_INHERIT, 402 ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 403 404 /* hidden properties */ 405 zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 406 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "CREATETXG"); 407 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 408 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 409 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 410 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME"); 411 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", 412 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 413 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 414 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 415 "STMF_SBD_LU"); 416 zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, 417 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "GUID"); 418 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 419 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 420 "USERACCOUNTING"); 421 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 422 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 423 zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 424 PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 425 zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent", 426 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT"); 427 428 /* oddball properties */ 429 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, 430 NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 431 "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 432} 433 434boolean_t 435zfs_prop_delegatable(zfs_prop_t prop) 436{ 437 zprop_desc_t *pd = &zfs_prop_table[prop]; 438 439 /* The mlslabel property is never delegatable. */ 440 if (prop == ZFS_PROP_MLSLABEL) 441 return (B_FALSE); 442 443 return (pd->pd_attr != PROP_READONLY); 444} 445 446/* 447 * Given a zfs dataset property name, returns the corresponding property ID. 448 */ 449zfs_prop_t 450zfs_name_to_prop(const char *propname) 451{ 452 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 453} 454 455/* 456 * For user property names, we allow all lowercase alphanumeric characters, plus 457 * a few useful punctuation characters. 458 */ 459static int 460valid_char(char c) 461{ 462 return ((c >= 'a' && c <= 'z') || 463 (c >= '0' && c <= '9') || 464 c == '-' || c == '_' || c == '.' || c == ':'); 465} 466 467/* 468 * Returns true if this is a valid user-defined property (one with a ':'). 469 */ 470boolean_t 471zfs_prop_user(const char *name) 472{ 473 int i; 474 char c; 475 boolean_t foundsep = B_FALSE; 476 477 for (i = 0; i < strlen(name); i++) { 478 c = name[i]; 479 if (!valid_char(c)) 480 return (B_FALSE); 481 if (c == ':') 482 foundsep = B_TRUE; 483 } 484 485 if (!foundsep) 486 return (B_FALSE); 487 488 return (B_TRUE); 489} 490 491/* 492 * Returns true if this is a valid userspace-type property (one with a '@'). 493 * Note that after the @, any character is valid (eg, another @, for SID 494 * user@domain). 495 */ 496boolean_t 497zfs_prop_userquota(const char *name) 498{ 499 zfs_userquota_prop_t prop; 500 501 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 502 if (strncmp(name, zfs_userquota_prop_prefixes[prop], 503 strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 504 return (B_TRUE); 505 } 506 } 507 508 return (B_FALSE); 509} 510 511/* 512 * Returns true if this is a valid written@ property. 513 * Note that after the @, any character is valid (eg, another @, for 514 * written@pool/fs@origin). 515 */ 516boolean_t 517zfs_prop_written(const char *name) 518{ 519 static const char *prefix = "written@"; 520 return (strncmp(name, prefix, strlen(prefix)) == 0); 521} 522 523/* 524 * Tables of index types, plus functions to convert between the user view 525 * (strings) and internal representation (uint64_t). 526 */ 527int 528zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 529{ 530 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 531} 532 533int 534zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 535{ 536 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 537} 538 539uint64_t 540zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 541{ 542 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 543} 544 545/* 546 * Returns TRUE if the property applies to any of the given dataset types. 547 */ 548boolean_t 549zfs_prop_valid_for_type(int prop, zfs_type_t types) 550{ 551 return (zprop_valid_for_type(prop, types)); 552} 553 554zprop_type_t 555zfs_prop_get_type(zfs_prop_t prop) 556{ 557 return (zfs_prop_table[prop].pd_proptype); 558} 559 560/* 561 * Returns TRUE if the property is readonly. 562 */ 563boolean_t 564zfs_prop_readonly(zfs_prop_t prop) 565{ 566 return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 567 zfs_prop_table[prop].pd_attr == PROP_ONETIME); 568} 569 570/* 571 * Returns TRUE if the property is only allowed to be set once. 572 */ 573boolean_t 574zfs_prop_setonce(zfs_prop_t prop) 575{ 576 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 577} 578 579const char * 580zfs_prop_default_string(zfs_prop_t prop) 581{ 582 return (zfs_prop_table[prop].pd_strdefault); 583} 584 585uint64_t 586zfs_prop_default_numeric(zfs_prop_t prop) 587{ 588 return (zfs_prop_table[prop].pd_numdefault); 589} 590 591/* 592 * Given a dataset property ID, returns the corresponding name. 593 * Assuming the zfs dataset property ID is valid. 594 */ 595const char * 596zfs_prop_to_name(zfs_prop_t prop) 597{ 598 return (zfs_prop_table[prop].pd_name); 599} 600 601/* 602 * Returns TRUE if the property is inheritable. 603 */ 604boolean_t 605zfs_prop_inheritable(zfs_prop_t prop) 606{ 607 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 608 zfs_prop_table[prop].pd_attr == PROP_ONETIME); 609} 610 611#ifndef _KERNEL 612 613/* 614 * Returns a string describing the set of acceptable values for the given 615 * zfs property, or NULL if it cannot be set. 616 */ 617const char * 618zfs_prop_values(zfs_prop_t prop) 619{ 620 return (zfs_prop_table[prop].pd_values); 621} 622 623/* 624 * Returns TRUE if this property is a string type. Note that index types 625 * (compression, checksum) are treated as strings in userland, even though they 626 * are stored numerically on disk. 627 */ 628int 629zfs_prop_is_string(zfs_prop_t prop) 630{ 631 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 632 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 633} 634 635/* 636 * Returns the column header for the given property. Used only in 637 * 'zfs list -o', but centralized here with the other property information. 638 */ 639const char * 640zfs_prop_column_name(zfs_prop_t prop) 641{ 642 return (zfs_prop_table[prop].pd_colname); 643} 644 645/* 646 * Returns whether the given property should be displayed right-justified for 647 * 'zfs list'. 648 */ 649boolean_t 650zfs_prop_align_right(zfs_prop_t prop) 651{ 652 return (zfs_prop_table[prop].pd_rightalign); 653} 654 655#endif 656