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