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