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, 2016 by Delphix. All rights reserved. 24 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 25 * Copyright (c) 2014 Integros [integros.com] 26 * Copyright 2016, Joyent, Inc. 27 */ 28 29 /* Portions Copyright 2010 Robert Milkowski */ 30 31 #include <sys/zio.h> 32 #include <sys/spa.h> 33 #include <sys/u8_textprep.h> 34 #include <sys/zfs_acl.h> 35 #include <sys/zfs_ioctl.h> 36 #include <sys/zfs_znode.h> 37 #include <sys/dsl_crypt.h> 38 39 #include "zfs_prop.h" 40 #include "zfs_deleg.h" 41 42 #if defined(_KERNEL) 43 #include <sys/systm.h> 44 #else 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 { "edonr", ZIO_CHECKSUM_EDONR }, 87 { NULL } 88 }; 89 90 static zprop_index_t dedup_table[] = { 91 { "on", ZIO_CHECKSUM_ON }, 92 { "off", ZIO_CHECKSUM_OFF }, 93 { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, 94 { "sha256", ZIO_CHECKSUM_SHA256 }, 95 { "sha256,verify", 96 ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, 97 { "sha512", ZIO_CHECKSUM_SHA512 }, 98 { "sha512,verify", 99 ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY }, 100 { "skein", ZIO_CHECKSUM_SKEIN }, 101 { "skein,verify", 102 ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY }, 103 { "edonr,verify", 104 ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY }, 105 { NULL } 106 }; 107 108 static zprop_index_t compress_table[] = { 109 { "on", ZIO_COMPRESS_ON }, 110 { "off", ZIO_COMPRESS_OFF }, 111 { "lzjb", ZIO_COMPRESS_LZJB }, 112 { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 113 { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 114 { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 115 { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 116 { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 117 { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 118 { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 119 { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 120 { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 121 { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 122 { "zle", ZIO_COMPRESS_ZLE }, 123 { "lz4", ZIO_COMPRESS_LZ4 }, 124 { NULL } 125 }; 126 127 static zprop_index_t crypto_table[] = { 128 { "on", ZIO_CRYPT_ON }, 129 { "off", ZIO_CRYPT_OFF }, 130 { "aes-128-ccm", ZIO_CRYPT_AES_128_CCM }, 131 { "aes-192-ccm", ZIO_CRYPT_AES_192_CCM }, 132 { "aes-256-ccm", ZIO_CRYPT_AES_256_CCM }, 133 { "aes-128-gcm", ZIO_CRYPT_AES_128_GCM }, 134 { "aes-192-gcm", ZIO_CRYPT_AES_192_GCM }, 135 { "aes-256-gcm", ZIO_CRYPT_AES_256_GCM }, 136 { NULL } 137 }; 138 139 static zprop_index_t keyformat_table[] = { 140 { "none", ZFS_KEYFORMAT_NONE }, 141 { "raw", ZFS_KEYFORMAT_RAW }, 142 { "hex", ZFS_KEYFORMAT_HEX }, 143 { "passphrase", ZFS_KEYFORMAT_PASSPHRASE }, 144 { NULL } 145 }; 146 147 static zprop_index_t snapdir_table[] = { 148 { "hidden", ZFS_SNAPDIR_HIDDEN }, 149 { "visible", ZFS_SNAPDIR_VISIBLE }, 150 { NULL } 151 }; 152 153 static zprop_index_t acl_mode_table[] = { 154 { "discard", ZFS_ACL_DISCARD }, 155 { "groupmask", ZFS_ACL_GROUPMASK }, 156 { "passthrough", ZFS_ACL_PASSTHROUGH }, 157 { "restricted", ZFS_ACL_RESTRICTED }, 158 { NULL } 159 }; 160 161 static zprop_index_t acl_inherit_table[] = { 162 { "discard", ZFS_ACL_DISCARD }, 163 { "noallow", ZFS_ACL_NOALLOW }, 164 { "restricted", ZFS_ACL_RESTRICTED }, 165 { "passthrough", ZFS_ACL_PASSTHROUGH }, 166 { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 167 { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 168 { NULL } 169 }; 170 171 static zprop_index_t case_table[] = { 172 { "sensitive", ZFS_CASE_SENSITIVE }, 173 { "insensitive", ZFS_CASE_INSENSITIVE }, 174 { "mixed", ZFS_CASE_MIXED }, 175 { NULL } 176 }; 177 178 static zprop_index_t copies_table[] = { 179 { "1", 1 }, 180 { "2", 2 }, 181 { "3", 3 }, 182 { NULL } 183 }; 184 185 /* 186 * Use the unique flags we have to send to u8_strcmp() and/or 187 * u8_textprep() to represent the various normalization property 188 * values. 189 */ 190 static zprop_index_t normalize_table[] = { 191 { "none", 0 }, 192 { "formD", U8_TEXTPREP_NFD }, 193 { "formKC", U8_TEXTPREP_NFKC }, 194 { "formC", U8_TEXTPREP_NFC }, 195 { "formKD", U8_TEXTPREP_NFKD }, 196 { NULL } 197 }; 198 199 static zprop_index_t version_table[] = { 200 { "1", 1 }, 201 { "2", 2 }, 202 { "3", 3 }, 203 { "4", 4 }, 204 { "5", 5 }, 205 { "current", ZPL_VERSION }, 206 { NULL } 207 }; 208 209 static zprop_index_t boolean_table[] = { 210 { "off", 0 }, 211 { "on", 1 }, 212 { NULL } 213 }; 214 215 static zprop_index_t keystatus_table[] = { 216 { "none", ZFS_KEYSTATUS_NONE }, 217 { "unavailable", ZFS_KEYSTATUS_UNAVAILABLE }, 218 { "available", ZFS_KEYSTATUS_AVAILABLE }, 219 { NULL } 220 }; 221 222 static zprop_index_t logbias_table[] = { 223 { "latency", ZFS_LOGBIAS_LATENCY }, 224 { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 225 { NULL } 226 }; 227 228 static zprop_index_t canmount_table[] = { 229 { "off", ZFS_CANMOUNT_OFF }, 230 { "on", ZFS_CANMOUNT_ON }, 231 { "noauto", ZFS_CANMOUNT_NOAUTO }, 232 { NULL } 233 }; 234 235 static zprop_index_t cache_table[] = { 236 { "none", ZFS_CACHE_NONE }, 237 { "metadata", ZFS_CACHE_METADATA }, 238 { "all", ZFS_CACHE_ALL }, 239 { NULL } 240 }; 241 242 static zprop_index_t sync_table[] = { 243 { "standard", ZFS_SYNC_STANDARD }, 244 { "always", ZFS_SYNC_ALWAYS }, 245 { "disabled", ZFS_SYNC_DISABLED }, 246 { NULL } 247 }; 248 249 static zprop_index_t dnsize_table[] = { 250 { "legacy", ZFS_DNSIZE_LEGACY }, 251 { "auto", ZFS_DNSIZE_AUTO }, 252 { "1k", ZFS_DNSIZE_1K }, 253 { "2k", ZFS_DNSIZE_2K }, 254 { "4k", ZFS_DNSIZE_4K }, 255 { "8k", ZFS_DNSIZE_8K }, 256 { "16k", ZFS_DNSIZE_16K }, 257 { NULL } 258 }; 259 260 static zprop_index_t redundant_metadata_table[] = { 261 { "all", ZFS_REDUNDANT_METADATA_ALL }, 262 { "most", ZFS_REDUNDANT_METADATA_MOST }, 263 { NULL } 264 }; 265 266 /* inherit index properties */ 267 zprop_register_index(ZFS_PROP_REDUNDANT_METADATA, "redundant_metadata", 268 ZFS_REDUNDANT_METADATA_ALL, 269 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 270 "all | most", "REDUND_MD", 271 redundant_metadata_table); 272 zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, 273 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 274 "standard | always | disabled", "SYNC", 275 sync_table); 276 zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", 277 ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | 278 ZFS_TYPE_VOLUME, 279 "on | off | fletcher2 | fletcher4 | sha256 | sha512 | " 280 "skein | edonr", "CHECKSUM", checksum_table); 281 zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 282 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 283 "on | off | verify | sha256[,verify], sha512[,verify], " 284 "skein[,verify], edonr,verify", "DEDUP", dedup_table); 285 zprop_register_index(ZFS_PROP_COMPRESSION, "compression", 286 ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 287 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 288 "on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", 289 "COMPRESS", compress_table); 290 zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 291 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 292 "hidden | visible", "SNAPDIR", snapdir_table); 293 zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD, 294 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 295 "discard | groupmask | passthrough | restricted", "ACLMODE", 296 acl_mode_table); 297 zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", 298 ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 299 "discard | noallow | restricted | passthrough | passthrough-x", 300 "ACLINHERIT", acl_inherit_table); 301 zprop_register_index(ZFS_PROP_ACLIMPLICIT, "aclimplicit", 1, 302 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off", "ACLIMPL", 303 boolean_table); 304 zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, 305 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 306 "1 | 2 | 3", "COPIES", copies_table); 307 zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 308 ZFS_CACHE_ALL, PROP_INHERIT, 309 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 310 "all | none | metadata", "PRIMARYCACHE", cache_table); 311 zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 312 ZFS_CACHE_ALL, PROP_INHERIT, 313 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 314 "all | none | metadata", "SECONDARYCACHE", cache_table); 315 zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 316 PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 317 "latency | throughput", "LOGBIAS", logbias_table); 318 319 zprop_register_index(ZFS_PROP_DNODESIZE, "dnodesize", 320 ZFS_DNSIZE_LEGACY, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 321 "legacy | auto | 1k | 2k | 4k | 8k | 16k", "DNSIZE", dnsize_table); 322 323 /* inherit index (boolean) properties */ 324 zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 325 ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 326 zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 327 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 328 boolean_table); 329 zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 330 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 331 boolean_table); 332 zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 333 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 334 boolean_table); 335 zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 336 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 337 boolean_table); 338 zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 339 ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 340 zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 341 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 342 boolean_table); 343 zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 344 ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 345 boolean_table); 346 zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 347 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 348 boolean_table); 349 350 /* default index properties */ 351 zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 352 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 353 "1 | 2 | 3 | 4 | 5 | current", "VERSION", version_table); 354 zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 355 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 356 "CANMOUNT", canmount_table); 357 358 /* readonly index properties */ 359 zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 360 ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 361 zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 362 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 363 boolean_table); 364 zprop_register_index(ZFS_PROP_KEYSTATUS, "keystatus", 365 ZFS_KEYSTATUS_NONE, PROP_READONLY, ZFS_TYPE_DATASET, 366 "none | unavailable | available", 367 "KEYSTATUS", keystatus_table); 368 369 /* set once index properties */ 370 zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 371 PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 372 "none | formC | formD | formKC | formKD", "NORMALIZATION", 373 normalize_table); 374 zprop_register_index(ZFS_PROP_CASE, "casesensitivity", 375 ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | 376 ZFS_TYPE_SNAPSHOT, 377 "sensitive | insensitive | mixed", "CASE", case_table); 378 zprop_register_index(ZFS_PROP_KEYFORMAT, "keyformat", 379 ZFS_KEYFORMAT_NONE, PROP_ONETIME_DEFAULT, 380 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 381 "none | raw | hex | passphrase", "KEYFORMAT", keyformat_table); 382 zprop_register_index(ZFS_PROP_ENCRYPTION, "encryption", 383 ZIO_CRYPT_DEFAULT, PROP_ONETIME, ZFS_TYPE_DATASET, 384 "on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | " 385 "aes-128-gcm | aes-192-gcm | aes-256-gcm", "ENCRYPTION", 386 crypto_table); 387 388 /* set once index (boolean) properties */ 389 zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 390 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 391 "on | off", "UTF8ONLY", boolean_table); 392 393 /* string properties */ 394 zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 395 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 396 zprop_register_string(ZFS_PROP_CLONES, "clones", NULL, PROP_READONLY, 397 ZFS_TYPE_SNAPSHOT, "<dataset>[,...]", "CLONES"); 398 zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", 399 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", 400 "MOUNTPOINT"); 401 zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", 402 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(8) options", 403 "SHARENFS"); 404 zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 405 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 406 "filesystem | volume | snapshot | bookmark", "TYPE"); 407 zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", 408 PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 409 "on | off | sharemgr(8) options", "SHARESMB"); 410 zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", 411 ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, 412 "<sensitivity label>", "MLSLABEL"); 413 zprop_register_string(ZFS_PROP_RECEIVE_RESUME_TOKEN, 414 "receive_resume_token", 415 NULL, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 416 "<string token>", "RESUMETOK"); 417 zprop_register_string(ZFS_PROP_ENCRYPTION_ROOT, "encryptionroot", NULL, 418 PROP_READONLY, ZFS_TYPE_DATASET, "<filesystem | volume>", 419 "ENCROOT"); 420 zprop_register_string(ZFS_PROP_KEYLOCATION, "keylocation", 421 "none", PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 422 "prompt | <file URI>", "KEYLOCATION"); 423 424 /* readonly number properties */ 425 zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 426 ZFS_TYPE_DATASET, "<size>", "USED"); 427 zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 428 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 429 zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, 430 PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); 431 zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 432 PROP_READONLY, ZFS_TYPE_DATASET, 433 "<1.00x or higher if compressed>", "RATIO"); 434 zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, 435 PROP_READONLY, ZFS_TYPE_DATASET, 436 "<1.00x or higher if compressed>", "REFRATIO"); 437 zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 438 ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 439 ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 440 zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, 441 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 442 "USEDSNAP"); 443 zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, 444 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 445 "USEDDS"); 446 zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, 447 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 448 "USEDCHILD"); 449 zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 450 PROP_READONLY, 451 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 452 zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 453 ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 454 zprop_register_number(ZFS_PROP_WRITTEN, "written", 0, PROP_READONLY, 455 ZFS_TYPE_DATASET, "<size>", "WRITTEN"); 456 zprop_register_number(ZFS_PROP_LOGICALUSED, "logicalused", 0, 457 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 458 "LUSED"); 459 zprop_register_number(ZFS_PROP_LOGICALREFERENCED, "logicalreferenced", 460 0, PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "LREFER"); 461 zprop_register_number(ZFS_PROP_FILESYSTEM_COUNT, "filesystem_count", 462 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM, 463 "<count>", "FSCOUNT"); 464 zprop_register_number(ZFS_PROP_SNAPSHOT_COUNT, "snapshot_count", 465 UINT64_MAX, PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 466 "<count>", "SSCOUNT"); 467 zprop_register_number(ZFS_PROP_GUID, "guid", 0, PROP_READONLY, 468 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "GUID"); 469 zprop_register_number(ZFS_PROP_CREATETXG, "createtxg", 0, PROP_READONLY, 470 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "<uint64>", "CREATETXG"); 471 zprop_register_number(ZFS_PROP_PBKDF2_ITERS, "pbkdf2iters", 472 0, PROP_ONETIME_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 473 "<iters>", "PBKDF2ITERS"); 474 475 /* default number properties */ 476 zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 477 ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 478 zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, 479 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 480 "<size> | none", "RESERV"); 481 zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 482 ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 483 zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 484 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 485 zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 486 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 487 "<size> | none", "REFRESERV"); 488 zprop_register_number(ZFS_PROP_FILESYSTEM_LIMIT, "filesystem_limit", 489 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, 490 "<count> | none", "FSLIMIT"); 491 zprop_register_number(ZFS_PROP_SNAPSHOT_LIMIT, "snapshot_limit", 492 UINT64_MAX, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 493 "<count> | none", "SSLIMIT"); 494 495 /* inherit number properties */ 496 zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", 497 SPA_OLD_MAXBLOCKSIZE, PROP_INHERIT, 498 ZFS_TYPE_FILESYSTEM, "512 to 1M, power of 2", "RECSIZE"); 499 zprop_register_number(ZFS_PROP_SPECIAL_SMALL_BLOCKS, 500 "special_small_blocks", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 501 "zero or 512 to 128K, power of 2", "SPECIAL_SMALL_BLOCKS"); 502 503 /* hidden properties */ 504 zprop_register_hidden(ZFS_PROP_REMAPTXG, "remaptxg", PROP_TYPE_NUMBER, 505 PROP_READONLY, ZFS_TYPE_DATASET, "REMAPTXG"); 506 zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 507 PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 508 zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 509 PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "NAME"); 510 zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", 511 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 512 zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 513 PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 514 "STMF_SBD_LU"); 515 zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 516 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 517 "USERACCOUNTING"); 518 zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 519 PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 520 zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 521 PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 522 zprop_register_hidden(ZFS_PROP_INCONSISTENT, "inconsistent", 523 PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, "INCONSISTENT"); 524 zprop_register_hidden(ZFS_PROP_IVSET_GUID, "ivsetguid", 525 PROP_TYPE_NUMBER, PROP_READONLY, 526 ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, "IVSETGUID"); 527 zprop_register_hidden(ZFS_PROP_PREV_SNAP, "prevsnap", PROP_TYPE_STRING, 528 PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PREVSNAP"); 529 zprop_register_hidden(ZFS_PROP_PBKDF2_SALT, "pbkdf2salt", 530 PROP_TYPE_NUMBER, PROP_ONETIME_DEFAULT, 531 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "PBKDF2SALT"); 532 zprop_register_hidden(ZFS_PROP_KEY_GUID, "keyguid", PROP_TYPE_NUMBER, 533 PROP_READONLY, ZFS_TYPE_DATASET, "KEYGUID"); 534 535 /* oddball properties */ 536 zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, 537 NULL, PROP_READONLY, ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK, 538 "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 539 } 540 541 boolean_t 542 zfs_prop_delegatable(zfs_prop_t prop) 543 { 544 zprop_desc_t *pd = &zfs_prop_table[prop]; 545 546 /* The mlslabel property is never delegatable. */ 547 if (prop == ZFS_PROP_MLSLABEL) 548 return (B_FALSE); 549 550 return (pd->pd_attr != PROP_READONLY); 551 } 552 553 /* 554 * Given a zfs dataset property name, returns the corresponding property ID. 555 */ 556 zfs_prop_t 557 zfs_name_to_prop(const char *propname) 558 { 559 return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 560 } 561 562 /* 563 * For user property names, we allow all lowercase alphanumeric characters, plus 564 * a few useful punctuation characters. 565 */ 566 static int 567 valid_char(char c) 568 { 569 return ((c >= 'a' && c <= 'z') || 570 (c >= '0' && c <= '9') || 571 c == '-' || c == '_' || c == '.' || c == ':'); 572 } 573 574 /* 575 * Returns true if this is a valid user-defined property (one with a ':'). 576 */ 577 boolean_t 578 zfs_prop_user(const char *name) 579 { 580 int i; 581 char c; 582 boolean_t foundsep = B_FALSE; 583 584 for (i = 0; i < strlen(name); i++) { 585 c = name[i]; 586 if (!valid_char(c)) 587 return (B_FALSE); 588 if (c == ':') 589 foundsep = B_TRUE; 590 } 591 592 if (!foundsep) 593 return (B_FALSE); 594 595 return (B_TRUE); 596 } 597 598 /* 599 * Returns true if this is a valid userspace-type property (one with a '@'). 600 * Note that after the @, any character is valid (eg, another @, for SID 601 * user@domain). 602 */ 603 boolean_t 604 zfs_prop_userquota(const char *name) 605 { 606 zfs_userquota_prop_t prop; 607 608 for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 609 if (strncmp(name, zfs_userquota_prop_prefixes[prop], 610 strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 611 return (B_TRUE); 612 } 613 } 614 615 return (B_FALSE); 616 } 617 618 /* 619 * Returns true if this is a valid written@ property. 620 * Note that after the @, any character is valid (eg, another @, for 621 * written@pool/fs@origin). 622 */ 623 boolean_t 624 zfs_prop_written(const char *name) 625 { 626 static const char *prefix = "written@"; 627 return (strncmp(name, prefix, strlen(prefix)) == 0); 628 } 629 630 /* 631 * Tables of index types, plus functions to convert between the user view 632 * (strings) and internal representation (uint64_t). 633 */ 634 int 635 zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 636 { 637 return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 638 } 639 640 int 641 zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 642 { 643 return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 644 } 645 646 uint64_t 647 zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 648 { 649 return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 650 } 651 652 /* 653 * Returns TRUE if the property applies to any of the given dataset types. 654 */ 655 boolean_t 656 zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck) 657 { 658 return (zprop_valid_for_type(prop, types, headcheck)); 659 } 660 661 zprop_type_t 662 zfs_prop_get_type(zfs_prop_t prop) 663 { 664 return (zfs_prop_table[prop].pd_proptype); 665 } 666 667 /* 668 * Returns TRUE if the property is readonly. 669 */ 670 boolean_t 671 zfs_prop_readonly(zfs_prop_t prop) 672 { 673 return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 674 zfs_prop_table[prop].pd_attr == PROP_ONETIME || 675 zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT); 676 } 677 678 /* 679 * Returns TRUE if the property is visible (not hidden). 680 */ 681 boolean_t 682 zfs_prop_visible(zfs_prop_t prop) 683 { 684 return (zfs_prop_table[prop].pd_visible); 685 } 686 687 /* 688 * Returns TRUE if the property is only allowed to be set once. 689 */ 690 boolean_t 691 zfs_prop_setonce(zfs_prop_t prop) 692 { 693 return (zfs_prop_table[prop].pd_attr == PROP_ONETIME || 694 zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT); 695 } 696 697 const char * 698 zfs_prop_default_string(zfs_prop_t prop) 699 { 700 return (zfs_prop_table[prop].pd_strdefault); 701 } 702 703 uint64_t 704 zfs_prop_default_numeric(zfs_prop_t prop) 705 { 706 return (zfs_prop_table[prop].pd_numdefault); 707 } 708 709 /* 710 * Given a dataset property ID, returns the corresponding name. 711 * Assuming the zfs dataset property ID is valid. 712 */ 713 const char * 714 zfs_prop_to_name(zfs_prop_t prop) 715 { 716 return (zfs_prop_table[prop].pd_name); 717 } 718 719 /* 720 * Returns TRUE if the property is inheritable. 721 */ 722 boolean_t 723 zfs_prop_inheritable(zfs_prop_t prop) 724 { 725 return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 726 zfs_prop_table[prop].pd_attr == PROP_ONETIME); 727 } 728 729 /* 730 * Returns TRUE if property is one of the encryption properties that requires 731 * a loaded encryption key to modify. 732 */ 733 boolean_t 734 zfs_prop_encryption_key_param(zfs_prop_t prop) 735 { 736 /* 737 * keylocation does not count as an encryption property. It can be 738 * changed at will without needing the master keys. 739 */ 740 return (prop == ZFS_PROP_PBKDF2_SALT || prop == ZFS_PROP_PBKDF2_ITERS || 741 prop == ZFS_PROP_KEYFORMAT); 742 } 743 744 /* 745 * Helper function used by both kernelspace and userspace to check the 746 * keylocation property. If encrypted is set, the keylocation must be valid 747 * for an encrypted dataset. 748 */ 749 boolean_t 750 zfs_prop_valid_keylocation(const char *str, boolean_t encrypted) 751 { 752 if (strcmp("none", str) == 0) 753 return (!encrypted); 754 else if (strcmp("prompt", str) == 0) 755 return (B_TRUE); 756 else if (strlen(str) > 8 && strncmp("file:///", str, 8) == 0) 757 return (B_TRUE); 758 759 return (B_FALSE); 760 } 761 762 763 #ifndef _KERNEL 764 765 /* 766 * Returns a string describing the set of acceptable values for the given 767 * zfs property, or NULL if it cannot be set. 768 */ 769 const char * 770 zfs_prop_values(zfs_prop_t prop) 771 { 772 return (zfs_prop_table[prop].pd_values); 773 } 774 775 /* 776 * Returns TRUE if this property is a string type. Note that index types 777 * (compression, checksum) are treated as strings in userland, even though they 778 * are stored numerically on disk. 779 */ 780 int 781 zfs_prop_is_string(zfs_prop_t prop) 782 { 783 return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 784 zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 785 } 786 787 /* 788 * Returns the column header for the given property. Used only in 789 * 'zfs list -o', but centralized here with the other property information. 790 */ 791 const char * 792 zfs_prop_column_name(zfs_prop_t prop) 793 { 794 return (zfs_prop_table[prop].pd_colname); 795 } 796 797 /* 798 * Returns whether the given property should be displayed right-justified for 799 * 'zfs list'. 800 */ 801 boolean_t 802 zfs_prop_align_right(zfs_prop_t prop) 803 { 804 return (zfs_prop_table[prop].pd_rightalign); 805 } 806 807 #endif 808