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