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, 2018 by Delphix. All rights reserved. 24 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 25 * Copyright 2016, Joyent, Inc. 26 * Copyright (c) 2019, Klara Inc. 27 * Copyright (c) 2019, Allan Jude 28 */ 29 30 /* Portions Copyright 2010 Robert Milkowski */ 31 32 #include <sys/zio.h> 33 #include <sys/spa.h> 34 #include <sys/u8_textprep.h> 35 #include <sys/zfs_acl.h> 36 #include <sys/zfs_ioctl.h> 37 #include <sys/zfs_znode.h> 38 #include <sys/dsl_crypt.h> 39 40 #include "zfs_prop.h" 41 #include "zfs_deleg.h" 42 #include "zfs_fletcher.h" 43 44 #if !defined(_KERNEL) 45 #include <stdlib.h> 46 #include <string.h> 47 #include <ctype.h> 48 #endif 49 50 static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 51 52 /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ 53 const char *zfs_userquota_prop_prefixes[] = { 54 "userused@", 55 "userquota@", 56 "groupused@", 57 "groupquota@", 58 "userobjused@", 59 "userobjquota@", 60 "groupobjused@", 61 "groupobjquota@", 62 "projectused@", 63 "projectquota@", 64 "projectobjused@", 65 "projectobjquota@" 66 }; 67 68 zprop_desc_t * 69 zfs_prop_get_table(void) 70 { 71 return (zfs_prop_table); 72 } 73 74 void 75 zfs_prop_init(void) 76 { 77 static zprop_index_t checksum_table[] = { 78 { "on", ZIO_CHECKSUM_ON }, 79 { "off", ZIO_CHECKSUM_OFF }, 80 { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 81 { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 82 { "sha256", ZIO_CHECKSUM_SHA256 }, 83 { "noparity", ZIO_CHECKSUM_NOPARITY }, 84 { "sha512", ZIO_CHECKSUM_SHA512 }, 85 { "skein", ZIO_CHECKSUM_SKEIN }, 86 #if !defined(__FreeBSD__) 87 88 { "edonr", ZIO_CHECKSUM_EDONR }, 89 #endif 90 { NULL } 91 }; 92 93 static zprop_index_t dedup_table[] = { 94 { "on", ZIO_CHECKSUM_ON }, 95 { "off", ZIO_CHECKSUM_OFF }, 96 { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, 97 { "sha256", ZIO_CHECKSUM_SHA256 }, 98 { "sha256,verify", 99 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, 100 { "sha512", ZIO_CHECKSUM_SHA512 }, 101 { "sha512,verify", 102 ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY }, 103 { "skein", ZIO_CHECKSUM_SKEIN }, 104 { "skein,verify", 105 ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY }, 106 #if !defined(__FreeBSD__) 107 108 { "edonr,verify", 109 ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY }, 110 #endif 111 { NULL } 112 }; 113 114 static zprop_index_t compress_table[] = { 115 { "on", ZIO_COMPRESS_ON }, 116 { "off", ZIO_COMPRESS_OFF }, 117 { "lzjb", ZIO_COMPRESS_LZJB }, 118 { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 119 { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 120 { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 121 { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 122 { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 123 { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 124 { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 125 { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 126 { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 127 { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 128 { "zle", ZIO_COMPRESS_ZLE }, 129 { "lz4", ZIO_COMPRESS_LZ4 }, 130 { "zstd", ZIO_COMPRESS_ZSTD }, 131 { "zstd-fast", 132 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_DEFAULT) }, 133 134 /* 135 * ZSTD 1-19 are synthetic. We store the compression level in a 136 * separate hidden property to avoid wasting a large amount of 137 * space in the ZIO_COMPRESS enum. 138 * 139 * The compression level is also stored within the header of the 140 * compressed block since we may need it for later recompression 141 * to avoid checksum errors (L2ARC). 142 * 143 * Note that the level here is defined as bit shifted mask on 144 * top of the method. 145 */ 146 { "zstd-1", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_1) }, 147 { "zstd-2", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_2) }, 148 { "zstd-3", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_3) }, 149 { "zstd-4", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_4) }, 150 { "zstd-5", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_5) }, 151 { "zstd-6", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_6) }, 152 { "zstd-7", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_7) }, 153 { "zstd-8", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_8) }, 154 { "zstd-9", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_9) }, 155 { "zstd-10", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_10) }, 156 { "zstd-11", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_11) }, 157 { "zstd-12", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_12) }, 158 { "zstd-13", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_13) }, 159 { "zstd-14", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_14) }, 160 { "zstd-15", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_15) }, 161 { "zstd-16", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_16) }, 162 { "zstd-17", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_17) }, 163 { "zstd-18", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_18) }, 164 { "zstd-19", ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_19) }, 165 166 /* 167 * The ZSTD-Fast levels are also synthetic. 168 */ 169 { "zstd-fast-1", 170 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_1) }, 171 { "zstd-fast-2", 172 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_2) }, 173 { "zstd-fast-3", 174 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_3) }, 175 { "zstd-fast-4", 176 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_4) }, 177 { "zstd-fast-5", 178 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_5) }, 179 { "zstd-fast-6", 180 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_6) }, 181 { "zstd-fast-7", 182 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_7) }, 183 { "zstd-fast-8", 184 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_8) }, 185 { "zstd-fast-9", 186 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_9) }, 187 { "zstd-fast-10", 188 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_10) }, 189 { "zstd-fast-20", 190 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_20) }, 191 { "zstd-fast-30", 192 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_30) }, 193 { "zstd-fast-40", 194 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_40) }, 195 { "zstd-fast-50", 196 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_50) }, 197 { "zstd-fast-60", 198 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_60) }, 199 { "zstd-fast-70", 200 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_70) }, 201 { "zstd-fast-80", 202 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_80) }, 203 { "zstd-fast-90", 204 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_90) }, 205 { "zstd-fast-100", 206 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_100) }, 207 { "zstd-fast-500", 208 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_500) }, 209 { "zstd-fast-1000", 210 ZIO_COMPLEVEL_ZSTD(ZIO_ZSTD_LEVEL_FAST_1000) }, 211 { NULL } 212 }; 213 214 static zprop_index_t crypto_table[] = { 215 { "on", ZIO_CRYPT_ON }, 216 { "off", ZIO_CRYPT_OFF }, 217 { "aes-128-ccm", ZIO_CRYPT_AES_128_CCM }, 218 { "aes-192-ccm", ZIO_CRYPT_AES_192_CCM }, 219 { "aes-256-ccm", ZIO_CRYPT_AES_256_CCM }, 220 { "aes-128-gcm", ZIO_CRYPT_AES_128_GCM }, 221 { "aes-192-gcm", ZIO_CRYPT_AES_192_GCM }, 222 { "aes-256-gcm", ZIO_CRYPT_AES_256_GCM }, 223 { NULL } 224 }; 225 226 static zprop_index_t keyformat_table[] = { 227 { "none", ZFS_KEYFORMAT_NONE }, 228 { "raw", ZFS_KEYFORMAT_RAW }, 229 { "hex", ZFS_KEYFORMAT_HEX }, 230 { "passphrase", ZFS_KEYFORMAT_PASSPHRASE }, 231 { NULL } 232 }; 233 234 static zprop_index_t snapdir_table[] = { 235 { "hidden", ZFS_SNAPDIR_HIDDEN }, 236 { "visible", ZFS_SNAPDIR_VISIBLE }, 237 { NULL } 238 }; 239 240 static zprop_index_t snapdev_table[] = { 241 { "hidden", ZFS_SNAPDEV_HIDDEN }, 242 { "visible", ZFS_SNAPDEV_VISIBLE }, 243 { NULL } 244 }; 245 246 static zprop_index_t acl_mode_table[] = { 247 { "discard", ZFS_ACL_DISCARD }, 248 { "groupmask", ZFS_ACL_GROUPMASK }, 249 { "passthrough", ZFS_ACL_PASSTHROUGH }, 250 { "restricted", ZFS_ACL_RESTRICTED }, 251 { NULL } 252 }; 253 254 static zprop_index_t acltype_table[] = { 255 { "off", ZFS_ACLTYPE_OFF }, 256 { "posix", ZFS_ACLTYPE_POSIX }, 257 { "disabled", ZFS_ACLTYPE_OFF }, /* bkwrd compatibility */ 258 { "noacl", ZFS_ACLTYPE_OFF }, /* bkwrd compatibility */ 259 { "posixacl", ZFS_ACLTYPE_POSIX }, /* bkwrd compatibility */ 260 { NULL } 261 }; 262 263 static zprop_index_t acl_inherit_table[] = { 264 { "discard", ZFS_ACL_DISCARD }, 265 { "noallow", ZFS_ACL_NOALLOW }, 266 { "restricted", ZFS_ACL_RESTRICTED }, 267 { "passthrough", ZFS_ACL_PASSTHROUGH }, 268 { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatibility */ 269 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 270 { NULL } 271 }; 272 273 static zprop_index_t case_table[] = { 274 { "sensitive", ZFS_CASE_SENSITIVE }, 275 { "insensitive", ZFS_CASE_INSENSITIVE }, 276 { "mixed", ZFS_CASE_MIXED }, 277 { NULL } 278 }; 279 280 static zprop_index_t copies_table[] = { 281 { "1", 1 }, 282 { "2", 2 }, 283 { "3", 3 }, 284 { NULL } 285 }; 286 287 /* 288 * Use the unique flags we have to send to u8_strcmp() and/or 289 * u8_textprep() to represent the various normalization property 290 * values. 291 */ 292 static zprop_index_t normalize_table[] = { 293 { "none", 0 }, 294 { "formD", U8_TEXTPREP_NFD }, 295 { "formKC", U8_TEXTPREP_NFKC }, 296 { "formC", U8_TEXTPREP_NFC }, 297 { "formKD", U8_TEXTPREP_NFKD }, 298 { NULL } 299 }; 300 301 static zprop_index_t version_table[] = { 302 { "1", 1 }, 303 { "2", 2 }, 304 { "3", 3 }, 305 { "4", 4 }, 306 { "5", 5 }, 307 { "current", ZPL_VERSION }, 308 { NULL } 309 }; 310 311 static zprop_index_t boolean_table[] = { 312 { "off", 0 }, 313 { "on", 1 }, 314 { NULL } 315 }; 316 317 static zprop_index_t keystatus_table[] = { 318 { "none", ZFS_KEYSTATUS_NONE}, 319 { "unavailable", ZFS_KEYSTATUS_UNAVAILABLE}, 320 { "available", ZFS_KEYSTATUS_AVAILABLE}, 321 { NULL } 322 }; 323 324 static zprop_index_t logbias_table[] = { 325 { "latency", ZFS_LOGBIAS_LATENCY }, 326 { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 327 { NULL } 328 }; 329 330 static zprop_index_t canmount_table[] = { 331 { "off", ZFS_CANMOUNT_OFF }, 332 { "on", ZFS_CANMOUNT_ON }, 333 { "noauto", ZFS_CANMOUNT_NOAUTO }, 334 { NULL } 335 }; 336 337 static zprop_index_t cache_table[] = { 338 { "none", ZFS_CACHE_NONE }, 339 { "metadata", ZFS_CACHE_METADATA }, 340 { "all", ZFS_CACHE_ALL }, 341 { NULL } 342 }; 343 344 static zprop_index_t sync_table[] = { 345 { "standard", ZFS_SYNC_STANDARD }, 346 { "always", ZFS_SYNC_ALWAYS }, 347 { "disabled", ZFS_SYNC_DISABLED }, 348 { NULL } 349 }; 350 351 static zprop_index_t xattr_table[] = { 352 { "off", ZFS_XATTR_OFF }, 353 { "on", ZFS_XATTR_DIR }, 354 { "sa", ZFS_XATTR_SA }, 355 { "dir", ZFS_XATTR_DIR }, 356 { NULL } 357 }; 358 359 static zprop_index_t dnsize_table[] = { 360 { "legacy", ZFS_DNSIZE_LEGACY }, 361 { "auto", ZFS_DNSIZE_AUTO }, 362 { "1k", ZFS_DNSIZE_1K }, 363 { "2k", ZFS_DNSIZE_2K }, 364 { "4k", ZFS_DNSIZE_4K }, 365 { "8k", ZFS_DNSIZE_8K }, 366 { "16k", ZFS_DNSIZE_16K }, 367 { NULL } 368 }; 369 370 static zprop_index_t redundant_metadata_table[] = { 371 { "all", ZFS_REDUNDANT_METADATA_ALL }, 372 { "most", ZFS_REDUNDANT_METADATA_MOST }, 373 { NULL } 374 }; 375 376 static zprop_index_t volmode_table[] = { 377 { "default", ZFS_VOLMODE_DEFAULT }, 378 { "full", ZFS_VOLMODE_GEOM }, 379 { "geom", ZFS_VOLMODE_GEOM }, 380 { "dev", ZFS_VOLMODE_DEV }, 381 { "none", ZFS_VOLMODE_NONE }, 382 { NULL } 383 }; 384 385 /* inherit index properties */ 386 zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata", 387 ZFS_REDUNDANT_METADATA_ALL, 388 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 389 "all | most", "REDUND_MD", 390 redundant_metadata_table); 391 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, 392 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 393 "standard | always | disabled", "SYNC", 394 sync_table); 395 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", 396 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | 397 ZFS_TYPE_VOLUME, 398 #if !defined(__FreeBSD__) 399 "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein" 400 " | edonr", 401 #else 402 "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein", 403 #endif 404 "CHECKSUM", checksum_table); 405 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 406 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 407 "on | off | verify | sha256[,verify] | sha512[,verify] | " 408 #if !defined(__FreeBSD__) 409 "skein[,verify] | edonr,verify", 410 #else 411 "skein[,verify]", 412 #endif 413 "DEDUP", dedup_table); 414 zprop_register_index(ZFS_PROP_COMPRESSION, "compression", 415 ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 416 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 417 "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4 | " 418 "zstd | zstd-[1-19] | " 419 "zstd-fast-[1-10,20,30,40,50,60,70,80,90,100,500,1000]", 420 "COMPRESS", compress_table); 421 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 422 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 423 "hidden | visible", "SNAPDIR", snapdir_table); 424 zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN, 425 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 426 "hidden | visible", "SNAPDEV", snapdev_table); 427 zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD, 428 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 429 "discard | groupmask | passthrough | restricted", "ACLMODE", 430 acl_mode_table); 431 #ifndef __FreeBSD__ 432 zprop_register_index(ZFS_PROP_ACLTYPE, "acltype", ZFS_ACLTYPE_OFF, 433 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 434 "off | posix", "ACLTYPE", acltype_table); 435 #endif 436 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", 437 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 438 "discard | noallow | restricted | passthrough | passthrough-x", 439 "ACLINHERIT", acl_inherit_table); 440 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, 441 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 442 "1 | 2 | 3", "COPIES", copies_table); 443 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 444 ZFS_CACHE_ALL, PROP_INHERIT, 445 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 446 "all | none | metadata", "PRIMARYCACHE", cache_table); 447 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 448 ZFS_CACHE_ALL, PROP_INHERIT, 449 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 450 "all | none | metadata", "SECONDARYCACHE", cache_table); 451 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 452 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 453 "latency | throughput", "LOGBIAS", logbias_table); 454 zprop_register_index(ZFS_PROP_XATTR, "xattr", ZFS_XATTR_DIR, 455 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 456 "on | off | dir | sa", "XATTR", xattr_table); 457 zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize", 458 ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 459 "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table); 460 zprop_register_index(ZFS_PROP_VOLMODE, "volmode", 461 ZFS_VOLMODE_DEFAULT, PROP_INHERIT, 462 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 463 "default | full | geom | dev | none", "VOLMODE", volmode_table); 464 465 /* inherit index (boolean) properties */ 466 zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 467 ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 468 zprop_register_index(ZFS_PROP_RELATIME, "relatime", 0, PROP_INHERIT, 469 ZFS_TYPE_FILESYSTEM, "on | off", "RELATIME", boolean_table); 470 zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 471 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 472 boolean_table); 473 zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 474 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 475 boolean_table); 476 zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 477 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 478 boolean_table); 479 zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 480 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 481 boolean_table); 482 #ifdef __FreeBSD__ 483 zprop_register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT, 484 ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table); 485 #else 486 zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 487 ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 488 #endif 489 zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 490 ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", boolean_table); 491 zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 492 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 493 boolean_table); 494 zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 1, PROP_INHERIT, 495 ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table); 496 497 /* default index properties */ 498 zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 499 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 500 "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table); 501 zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 502 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 503 "CANMOUNT", canmount_table); 504 505 /* readonly index properties */ 506 zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 507 ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 508 zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 509 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 510 boolean_table); 511 zprop_register_index(ZFS_PROP_KEYSTATUS, "keystatus", 512 ZFS_KEYSTATUS_NONE, PROP_READONLY, ZFS_TYPE_DATASET, 513 "none | unavailable | available", 514 "KEYSTATUS", keystatus_table); 515 516 /* set once index properties */ 517 zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 518 PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 519 "none | formC | formD | formKC | formKD", "NORMALIZATION", 520 normalize_table); 521 zprop_register_index(ZFS_PROP_CASE, "casesensitivity", 522 ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | 523 ZFS_TYPE_SNAPSHOT, 524 "sensitive | insensitive | mixed", "CASE", case_table); 525 zprop_register_index(ZFS_PROP_KEYFORMAT, "keyformat", 526 ZFS_KEYFORMAT_NONE, PROP_ONETIME_DEFAULT, 527 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 528 "none | raw | hex | passphrase", "KEYFORMAT", keyformat_table); 529 zprop_register_index(ZFS_PROP_ENCRYPTION, "encryption", 530 ZIO_CRYPT_DEFAULT, PROP_ONETIME, ZFS_TYPE_DATASET, 531 "on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | " 532 "aes-128-gcm | aes-192-gcm | aes-256-gcm", "ENCRYPTION", 533 crypto_table); 534 535 /* set once index (boolean) properties */ 536 zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 537 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 538 "on | off", "UTF8ONLY", boolean_table); 539 540 /* string properties */ 541 zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 542 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 543 zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY, 544 ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES"); 545 zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", 546 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", 547 "MOUNTPOINT"); 548 zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", 549 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", 550 "SHARENFS"); 551 zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 552 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 553 "filesystem | volume | snapshot | bookmark", "TYPE"); 554 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", 555 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 556 "on | off | sharemgr(1M) options", "SHARESMB"); 557 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", 558 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, 559 "<sensitivity label>", "MLSLABEL"); 560 zprop_register_string(ZFS_PROP_SELINUX_CONTEXT, "context", 561 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux context>", 562 "CONTEXT"); 563 zprop_register_string(ZFS_PROP_SELINUX_FSCONTEXT, "fscontext", 564 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux fscontext>", 565 "FSCONTEXT"); 566 zprop_register_string(ZFS_PROP_SELINUX_DEFCONTEXT, "defcontext", 567 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux defcontext>", 568 "DEFCONTEXT"); 569 zprop_register_string(ZFS_PROP_SELINUX_ROOTCONTEXT, "rootcontext", 570 "none", PROP_DEFAULT, ZFS_TYPE_DATASET, "<selinux rootcontext>", 571 "ROOTCONTEXT"); 572 zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN, 573 "receive_resume_token", 574 NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 575 "<string token>", "RESUMETOK"); 576 zprop_register_string(ZFS_PROP_ENCRYPTION_ROOT, "encryptionroot", NULL, 577 PROP_READONLY, ZFS_TYPE_DATASET, "<filesystem | volume>", 578 "ENCROOT"); 579 zprop_register_string(ZFS_PROP_KEYLOCATION, "keylocation", 580 "none", PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 581 "prompt | <file URI>", "KEYLOCATION"); 582 zprop_register_string(ZFS_PROP_REDACT_SNAPS, 583 "redact_snaps", NULL, PROP_READONLY, 584 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<snapshot>[,...]", 585 "RSNAPS"); 586 587 /* readonly number properties */ 588 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 589 ZFS_TYPE_DATASET, "<size>", "USED"); 590 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 591 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 592 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, 593 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>", 594 "REFER"); 595 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 596 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 597 "<1.00x or higher if compressed>", "RATIO"); 598 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, 599 PROP_READONLY, ZFS_TYPE_DATASET, 600 "<1.00x or higher if compressed>", "REFRATIO"); 601 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 602 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 603 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 604 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, 605 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 606 "USEDSNAP"); 607 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, 608 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 609 "USEDDS"); 610 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, 611 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 612 "USEDCHILD"); 613 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 614 PROP_READONLY, 615 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 616 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 617 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 618 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY, 619 ZFS_TYPE_DATASET, "<size>", "WRITTEN"); 620 zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0, 621 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 622 "LUSED"); 623 zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced", 624 0, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<size>", 625 "LREFER"); 626 zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count", 627 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM, 628 "<count>", "FSCOUNT"); 629 zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count", 630 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 631 "<count>", "SSCOUNT"); 632 zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY, 633 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID"); 634 zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY, 635 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG"); 636 zprop_register_number(ZFS_PROP_PBKDF2_ITERS, "pbkdf2iters", 637 0, PROP_ONETIME_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 638 "<iters>", "PBKDF2ITERS"); 639 zprop_register_number(ZFS_PROP_OBJSETID, "objsetid", 0, 640 PROP_READONLY, ZFS_TYPE_DATASET, "<uint64>", "OBJSETID"); 641 642 /* default number properties */ 643 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 644 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 645 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, 646 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 647 "<size> | none", "RESERV"); 648 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 649 ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 650 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 651 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 652 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 653 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 654 "<size> | none", "REFRESERV"); 655 zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit", 656 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, 657 "<count> | none", "FSLIMIT"); 658 zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit", 659 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 660 "<count> | none", "SSLIMIT"); 661 662 /* inherit number properties */ 663 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", 664 SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT, 665 ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE"); 666 zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS, 667 "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 668 "zero or 512 to 1M, power of 2", "SPECIAL_SMALL_BLOCKS"); 669 670 /* hidden properties */ 671 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 672 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 673 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 674 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME"); 675 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", 676 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 677 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 678 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 679 "STMF_SBD_LU"); 680 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 681 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 682 "USERACCOUNTING"); 683 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 684 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 685 zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent", 686 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT"); 687 zprop_register_hidden(ZFS_PROP_IVSET_GUID, "ivsetguid", 688 PROP_TYPE_NUMBER, PROP_READONLY, 689 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "IVSETGUID"); 690 zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING, 691 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP"); 692 zprop_register_hidden(ZFS_PROP_PBKDF2_SALT, "pbkdf2salt", 693 PROP_TYPE_NUMBER, PROP_ONETIME_DEFAULT, 694 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PBKDF2SALT"); 695 zprop_register_hidden(ZFS_PROP_KEY_GUID, "keyguid", PROP_TYPE_NUMBER, 696 PROP_READONLY, ZFS_TYPE_DATASET, "KEYGUID"); 697 zprop_register_hidden(ZFS_PROP_REDACTED, "redacted", PROP_TYPE_NUMBER, 698 PROP_READONLY, ZFS_TYPE_DATASET, "REDACTED"); 699 700 /* 701 * Properties that are obsolete and not used. These are retained so 702 * that we don't have to change the values of the zfs_prop_t enum, or 703 * have NULL pointers in the zfs_prop_table[]. 704 */ 705 #ifdef __FreeBSD__ 706 zprop_register_impl(ZFS_PROP_ACLTYPE, "acltype", PROP_TYPE_INDEX, 707 ZFS_ACLTYPE_OFF, NULL, PROP_INHERIT, 708 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 709 "off | posix", "ACLTYPE", B_FALSE, B_FALSE, acltype_table); 710 #endif 711 zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER, 712 PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG"); 713 714 /* oddball properties */ 715 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, 716 NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 717 "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 718 } 719 720 boolean_t 721 zfs_prop_delegatable(zfs_prop_t prop) 722 { 723 zprop_desc_t *pd = &zfs_prop_table[prop]; 724 725 /* The mlslabel property is never delegatable. */ 726 if (prop == ZFS_PROP_MLSLABEL) 727 return (B_FALSE); 728 729 return (pd->pd_attr != PROP_READONLY); 730 } 731 732 /* 733 * Given a zfs dataset property name, returns the corresponding property ID. 734 */ 735 zfs_prop_t 736 zfs_name_to_prop(const char *propname) 737 { 738 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 739 } 740 741 /* 742 * For user property names, we allow all lowercase alphanumeric characters, plus 743 * a few useful punctuation characters. 744 */ 745 static int 746 valid_char(char c) 747 { 748 return ((c >= 'a' && c <= 'z') || 749 (c >= '0' && c <= '9') || 750 c == '-' || c == '_' || c == '.' || c == ':'); 751 } 752 753 /* 754 * Returns true if this is a valid user-defined property (one with a ':'). 755 */ 756 boolean_t 757 zfs_prop_user(const char *name) 758 { 759 int i; 760 char c; 761 boolean_t foundsep = B_FALSE; 762 763 for (i = 0; i < strlen(name); i++) { 764 c = name[i]; 765 if (!valid_char(c)) 766 return (B_FALSE); 767 if (c == ':') 768 foundsep = B_TRUE; 769 } 770 771 if (!foundsep) 772 return (B_FALSE); 773 774 return (B_TRUE); 775 } 776 777 /* 778 * Returns true if this is a valid userspace-type property (one with a '@'). 779 * Note that after the @, any character is valid (eg, another @, for SID 780 * user@domain). 781 */ 782 boolean_t 783 zfs_prop_userquota(const char *name) 784 { 785 zfs_userquota_prop_t prop; 786 787 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 788 if (strncmp(name, zfs_userquota_prop_prefixes[prop], 789 strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 790 return (B_TRUE); 791 } 792 } 793 794 return (B_FALSE); 795 } 796 797 /* 798 * Returns true if this is a valid written@ property. 799 * Note that after the @, any character is valid (eg, another @, for 800 * written@pool/fs@origin). 801 */ 802 boolean_t 803 zfs_prop_written(const char *name) 804 { 805 static const char *prop_prefix = "written@"; 806 static const char *book_prefix = "written#"; 807 return (strncmp(name, prop_prefix, strlen(prop_prefix)) == 0 || 808 strncmp(name, book_prefix, strlen(book_prefix)) == 0); 809 } 810 811 /* 812 * Tables of index types, plus functions to convert between the user view 813 * (strings) and internal representation (uint64_t). 814 */ 815 int 816 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 817 { 818 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 819 } 820 821 int 822 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 823 { 824 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 825 } 826 827 uint64_t 828 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 829 { 830 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 831 } 832 833 /* 834 * Returns TRUE if the property applies to any of the given dataset types. 835 */ 836 boolean_t 837 zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck) 838 { 839 return (zprop_valid_for_type(prop, types, headcheck)); 840 } 841 842 zprop_type_t 843 zfs_prop_get_type(zfs_prop_t prop) 844 { 845 return (zfs_prop_table[prop].pd_proptype); 846 } 847 848 /* 849 * Returns TRUE if the property is readonly. 850 */ 851 boolean_t 852 zfs_prop_readonly(zfs_prop_t prop) 853 { 854 return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 855 zfs_prop_table[prop].pd_attr == PROP_ONETIME || 856 zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT); 857 } 858 859 /* 860 * Returns TRUE if the property is visible (not hidden). 861 */ 862 boolean_t 863 zfs_prop_visible(zfs_prop_t prop) 864 { 865 return (zfs_prop_table[prop].pd_visible && 866 zfs_prop_table[prop].pd_zfs_mod_supported); 867 } 868 869 /* 870 * Returns TRUE if the property is only allowed to be set once. 871 */ 872 boolean_t 873 zfs_prop_setonce(zfs_prop_t prop) 874 { 875 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME || 876 zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT); 877 } 878 879 const char * 880 zfs_prop_default_string(zfs_prop_t prop) 881 { 882 return (zfs_prop_table[prop].pd_strdefault); 883 } 884 885 uint64_t 886 zfs_prop_default_numeric(zfs_prop_t prop) 887 { 888 return (zfs_prop_table[prop].pd_numdefault); 889 } 890 891 /* 892 * Given a dataset property ID, returns the corresponding name. 893 * Assuming the zfs dataset property ID is valid. 894 */ 895 const char * 896 zfs_prop_to_name(zfs_prop_t prop) 897 { 898 return (zfs_prop_table[prop].pd_name); 899 } 900 901 /* 902 * Returns TRUE if the property is inheritable. 903 */ 904 boolean_t 905 zfs_prop_inheritable(zfs_prop_t prop) 906 { 907 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 908 zfs_prop_table[prop].pd_attr == PROP_ONETIME); 909 } 910 911 /* 912 * Returns TRUE if property is one of the encryption properties that requires 913 * a loaded encryption key to modify. 914 */ 915 boolean_t 916 zfs_prop_encryption_key_param(zfs_prop_t prop) 917 { 918 /* 919 * keylocation does not count as an encryption property. It can be 920 * changed at will without needing the master keys. 921 */ 922 return (prop == ZFS_PROP_PBKDF2_SALT || prop == ZFS_PROP_PBKDF2_ITERS || 923 prop == ZFS_PROP_KEYFORMAT); 924 } 925 926 /* 927 * Helper function used by both kernelspace and userspace to check the 928 * keylocation property. If encrypted is set, the keylocation must be valid 929 * for an encrypted dataset. 930 */ 931 boolean_t 932 zfs_prop_valid_keylocation(const char *str, boolean_t encrypted) 933 { 934 if (strcmp("none", str) == 0) 935 return (!encrypted); 936 else if (strcmp("prompt", str) == 0) 937 return (B_TRUE); 938 else if (strlen(str) > 8 && strncmp("file:///", str, 8) == 0) 939 return (B_TRUE); 940 941 return (B_FALSE); 942 } 943 944 945 #ifndef _KERNEL 946 #include <libzfs.h> 947 948 /* 949 * Returns a string describing the set of acceptable values for the given 950 * zfs property, or NULL if it cannot be set. 951 */ 952 const char * 953 zfs_prop_values(zfs_prop_t prop) 954 { 955 return (zfs_prop_table[prop].pd_values); 956 } 957 958 /* 959 * Returns TRUE if this property is a string type. Note that index types 960 * (compression, checksum) are treated as strings in userland, even though they 961 * are stored numerically on disk. 962 */ 963 int 964 zfs_prop_is_string(zfs_prop_t prop) 965 { 966 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 967 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 968 } 969 970 /* 971 * Returns the column header for the given property. Used only in 972 * 'zfs list -o', but centralized here with the other property information. 973 */ 974 const char * 975 zfs_prop_column_name(zfs_prop_t prop) 976 { 977 return (zfs_prop_table[prop].pd_colname); 978 } 979 980 /* 981 * Returns whether the given property should be displayed right-justified for 982 * 'zfs list'. 983 */ 984 boolean_t 985 zfs_prop_align_right(zfs_prop_t prop) 986 { 987 return (zfs_prop_table[prop].pd_rightalign); 988 } 989 990 #endif 991 992 #if defined(_KERNEL) 993 994 #include <sys/simd.h> 995 996 #if defined(HAVE_KERNEL_FPU_INTERNAL) 997 union fpregs_state **zfs_kfpu_fpregs; 998 EXPORT_SYMBOL(zfs_kfpu_fpregs); 999 #endif /* HAVE_KERNEL_FPU_INTERNAL */ 1000 1001 static int __init 1002 zcommon_init(void) 1003 { 1004 int error = kfpu_init(); 1005 if (error) 1006 return (error); 1007 1008 fletcher_4_init(); 1009 1010 return (0); 1011 } 1012 1013 static void __exit 1014 zcommon_fini(void) 1015 { 1016 fletcher_4_fini(); 1017 kfpu_fini(); 1018 } 1019 1020 module_init(zcommon_init); 1021 module_exit(zcommon_fini); 1022 1023 #endif 1024 1025 ZFS_MODULE_DESCRIPTION("Generic ZFS support"); 1026 ZFS_MODULE_AUTHOR(ZFS_META_AUTHOR); 1027 ZFS_MODULE_LICENSE(ZFS_META_LICENSE); 1028 ZFS_MODULE_VERSION(ZFS_META_VERSION "-" ZFS_META_RELEASE); 1029 1030 /* zfs dataset property functions */ 1031 EXPORT_SYMBOL(zfs_userquota_prop_prefixes); 1032 EXPORT_SYMBOL(zfs_prop_init); 1033 EXPORT_SYMBOL(zfs_prop_get_type); 1034 EXPORT_SYMBOL(zfs_prop_get_table); 1035 EXPORT_SYMBOL(zfs_prop_delegatable); 1036 EXPORT_SYMBOL(zfs_prop_visible); 1037 1038 /* Dataset property functions shared between libzfs and kernel. */ 1039 EXPORT_SYMBOL(zfs_prop_default_string); 1040 EXPORT_SYMBOL(zfs_prop_default_numeric); 1041 EXPORT_SYMBOL(zfs_prop_readonly); 1042 EXPORT_SYMBOL(zfs_prop_inheritable); 1043 EXPORT_SYMBOL(zfs_prop_encryption_key_param); 1044 EXPORT_SYMBOL(zfs_prop_valid_keylocation); 1045 EXPORT_SYMBOL(zfs_prop_setonce); 1046 EXPORT_SYMBOL(zfs_prop_to_name); 1047 EXPORT_SYMBOL(zfs_name_to_prop); 1048 EXPORT_SYMBOL(zfs_prop_user); 1049 EXPORT_SYMBOL(zfs_prop_userquota); 1050 EXPORT_SYMBOL(zfs_prop_index_to_string); 1051 EXPORT_SYMBOL(zfs_prop_string_to_index); 1052 EXPORT_SYMBOL(zfs_prop_valid_for_type); 1053 EXPORT_SYMBOL(zfs_prop_written); 1054