1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5906d120cSlling * Common Development and Distribution License (the "License"). 6906d120cSlling * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 2227dd1e87SMark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23*187d6ac0SMatt Ahrens * Copyright (c) 2011 by Delphix. All rights reserved. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 2655da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */ 2755da60b9SMark J Musante 28fa9e4066Sahrens #include <sys/zio.h> 29fa9e4066Sahrens #include <sys/spa.h> 30de8267e0Stimh #include <sys/u8_textprep.h> 31fa9e4066Sahrens #include <sys/zfs_acl.h> 32fa9e4066Sahrens #include <sys/zfs_ioctl.h> 33e7437265Sahrens #include <sys/zfs_znode.h> 34fa9e4066Sahrens 35fa9e4066Sahrens #include "zfs_prop.h" 36ecd6cf80Smarks #include "zfs_deleg.h" 37fa9e4066Sahrens 38fa9e4066Sahrens #if defined(_KERNEL) 39fa9e4066Sahrens #include <sys/systm.h> 40fa9e4066Sahrens #else 41fa9e4066Sahrens #include <stdlib.h> 42fa9e4066Sahrens #include <string.h> 43fa9e4066Sahrens #include <ctype.h> 44fa9e4066Sahrens #endif 45fa9e4066Sahrens 46990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 47fa9e4066Sahrens 4814843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ 4914843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = { 5014843421SMatthew Ahrens "userused@", 5114843421SMatthew Ahrens "userquota@", 5214843421SMatthew Ahrens "groupused@", 5314843421SMatthew Ahrens "groupquota@" 5414843421SMatthew Ahrens }; 5514843421SMatthew Ahrens 56990b4856Slling zprop_desc_t * 57990b4856Slling zfs_prop_get_table(void) 5891ebeef5Sahrens { 59990b4856Slling return (zfs_prop_table); 6091ebeef5Sahrens } 6191ebeef5Sahrens 6291ebeef5Sahrens void 6391ebeef5Sahrens zfs_prop_init(void) 6491ebeef5Sahrens { 65990b4856Slling static zprop_index_t checksum_table[] = { 6691ebeef5Sahrens { "on", ZIO_CHECKSUM_ON }, 6791ebeef5Sahrens { "off", ZIO_CHECKSUM_OFF }, 6891ebeef5Sahrens { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 6991ebeef5Sahrens { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 7091ebeef5Sahrens { "sha256", ZIO_CHECKSUM_SHA256 }, 7191ebeef5Sahrens { NULL } 72fa9e4066Sahrens }; 73fa9e4066Sahrens 74b24ab676SJeff Bonwick static zprop_index_t dedup_table[] = { 75b24ab676SJeff Bonwick { "on", ZIO_CHECKSUM_ON }, 76b24ab676SJeff Bonwick { "off", ZIO_CHECKSUM_OFF }, 77b24ab676SJeff Bonwick { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, 78b24ab676SJeff Bonwick { "sha256", ZIO_CHECKSUM_SHA256 }, 79b24ab676SJeff Bonwick { "sha256,verify", 80b24ab676SJeff Bonwick ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, 81b24ab676SJeff Bonwick { NULL } 82b24ab676SJeff Bonwick }; 83b24ab676SJeff Bonwick 84990b4856Slling static zprop_index_t compress_table[] = { 8591ebeef5Sahrens { "on", ZIO_COMPRESS_ON }, 8691ebeef5Sahrens { "off", ZIO_COMPRESS_OFF }, 8791ebeef5Sahrens { "lzjb", ZIO_COMPRESS_LZJB }, 8891ebeef5Sahrens { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 8991ebeef5Sahrens { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 9091ebeef5Sahrens { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 9191ebeef5Sahrens { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 9291ebeef5Sahrens { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 9391ebeef5Sahrens { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 9491ebeef5Sahrens { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 9591ebeef5Sahrens { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 9691ebeef5Sahrens { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 9791ebeef5Sahrens { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 98b24ab676SJeff Bonwick { "zle", ZIO_COMPRESS_ZLE }, 9991ebeef5Sahrens { NULL } 10091ebeef5Sahrens }; 10191ebeef5Sahrens 102990b4856Slling static zprop_index_t snapdir_table[] = { 10391ebeef5Sahrens { "hidden", ZFS_SNAPDIR_HIDDEN }, 10491ebeef5Sahrens { "visible", ZFS_SNAPDIR_VISIBLE }, 10591ebeef5Sahrens { NULL } 10691ebeef5Sahrens }; 10791ebeef5Sahrens 108a3c49ce1SAlbert Lee static zprop_index_t acl_mode_table[] = { 109a3c49ce1SAlbert Lee { "discard", ZFS_ACL_DISCARD }, 110a3c49ce1SAlbert Lee { "groupmask", ZFS_ACL_GROUPMASK }, 111a3c49ce1SAlbert Lee { "passthrough", ZFS_ACL_PASSTHROUGH }, 112a3c49ce1SAlbert Lee { NULL } 113a3c49ce1SAlbert Lee }; 114a3c49ce1SAlbert Lee 115990b4856Slling static zprop_index_t acl_inherit_table[] = { 11691ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 11791ebeef5Sahrens { "noallow", ZFS_ACL_NOALLOW }, 118b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 11991ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 120b3d141f8Smarks { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 121d0f3f37eSMark Shellenbaum { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 12291ebeef5Sahrens { NULL } 12391ebeef5Sahrens }; 12491ebeef5Sahrens 125da6c28aaSamw static zprop_index_t case_table[] = { 126da6c28aaSamw { "sensitive", ZFS_CASE_SENSITIVE }, 127da6c28aaSamw { "insensitive", ZFS_CASE_INSENSITIVE }, 128da6c28aaSamw { "mixed", ZFS_CASE_MIXED }, 129da6c28aaSamw { NULL } 130da6c28aaSamw }; 131da6c28aaSamw 132990b4856Slling static zprop_index_t copies_table[] = { 13391ebeef5Sahrens { "1", 1 }, 13491ebeef5Sahrens { "2", 2 }, 13591ebeef5Sahrens { "3", 3 }, 13691ebeef5Sahrens { NULL } 13791ebeef5Sahrens }; 13891ebeef5Sahrens 139de8267e0Stimh /* 140de8267e0Stimh * Use the unique flags we have to send to u8_strcmp() and/or 141de8267e0Stimh * u8_textprep() to represent the various normalization property 142de8267e0Stimh * values. 143de8267e0Stimh */ 144da6c28aaSamw static zprop_index_t normalize_table[] = { 145de8267e0Stimh { "none", 0 }, 146de8267e0Stimh { "formD", U8_TEXTPREP_NFD }, 147de8267e0Stimh { "formKC", U8_TEXTPREP_NFKC }, 148de8267e0Stimh { "formC", U8_TEXTPREP_NFC }, 149de8267e0Stimh { "formKD", U8_TEXTPREP_NFKD }, 150da6c28aaSamw { NULL } 151da6c28aaSamw }; 152da6c28aaSamw 153990b4856Slling static zprop_index_t version_table[] = { 15491ebeef5Sahrens { "1", 1 }, 15591ebeef5Sahrens { "2", 2 }, 156da6c28aaSamw { "3", 3 }, 15714843421SMatthew Ahrens { "4", 4 }, 1580a586ceaSMark Shellenbaum { "5", 5 }, 15991ebeef5Sahrens { "current", ZPL_VERSION }, 16091ebeef5Sahrens { NULL } 16191ebeef5Sahrens }; 16291ebeef5Sahrens 163990b4856Slling static zprop_index_t boolean_table[] = { 164e45ce728Sahrens { "off", 0 }, 165e45ce728Sahrens { "on", 1 }, 166e45ce728Sahrens { NULL } 167e45ce728Sahrens }; 168e45ce728Sahrens 169e09fa4daSNeil Perrin static zprop_index_t logbias_table[] = { 170e09fa4daSNeil Perrin { "latency", ZFS_LOGBIAS_LATENCY }, 171e09fa4daSNeil Perrin { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 172e09fa4daSNeil Perrin { NULL } 173e09fa4daSNeil Perrin }; 174e09fa4daSNeil Perrin 175a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 176a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 177a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 178a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 179a227b7f4Shs24103 { NULL } 180a227b7f4Shs24103 }; 181a227b7f4Shs24103 1823baa08fcSek110237 static zprop_index_t cache_table[] = { 1833baa08fcSek110237 { "none", ZFS_CACHE_NONE }, 1843baa08fcSek110237 { "metadata", ZFS_CACHE_METADATA }, 1853baa08fcSek110237 { "all", ZFS_CACHE_ALL }, 1863baa08fcSek110237 { NULL } 1873baa08fcSek110237 }; 1883baa08fcSek110237 18955da60b9SMark J Musante static zprop_index_t sync_table[] = { 19055da60b9SMark J Musante { "standard", ZFS_SYNC_STANDARD }, 19155da60b9SMark J Musante { "always", ZFS_SYNC_ALWAYS }, 19255da60b9SMark J Musante { "disabled", ZFS_SYNC_DISABLED }, 19355da60b9SMark J Musante { NULL } 19455da60b9SMark J Musante }; 19555da60b9SMark J Musante 19691ebeef5Sahrens /* inherit index properties */ 19755da60b9SMark J Musante zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, 19855da60b9SMark J Musante PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 19955da60b9SMark J Musante "standard | always | disabled", "SYNC", 20055da60b9SMark J Musante sync_table); 20183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", 20283d7f9feSTom Erickson ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | 20383d7f9feSTom Erickson ZFS_TYPE_VOLUME, 20491ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 20591ebeef5Sahrens checksum_table); 20683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 207b24ab676SJeff Bonwick PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 208b1033ae2SMatthew Ahrens "on | off | verify | sha256[,verify]", "DEDUP", 209b24ab676SJeff Bonwick dedup_table); 21083d7f9feSTom Erickson zprop_register_index(ZFS_PROP_COMPRESSION, "compression", 211e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 212e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 213b24ab676SJeff Bonwick "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS", 214b24ab676SJeff Bonwick compress_table); 21583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 216e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 217e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 218a3c49ce1SAlbert Lee zprop_register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_DISCARD, 219a3c49ce1SAlbert Lee PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 220a3c49ce1SAlbert Lee "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 22183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", 22283d7f9feSTom Erickson ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 223d0f3f37eSMark Shellenbaum "discard | noallow | restricted | passthrough | passthrough-x", 224b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 22583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, 22683d7f9feSTom Erickson ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 22791ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 22883d7f9feSTom Erickson zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 2293baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2303baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2313baa08fcSek110237 "all | none | metadata", "PRIMARYCACHE", cache_table); 23283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 2333baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2343baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2353baa08fcSek110237 "all | none | metadata", "SECONDARYCACHE", cache_table); 23683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 237e09fa4daSNeil Perrin PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 238e09fa4daSNeil Perrin "latency | throughput", "LOGBIAS", logbias_table); 239e45ce728Sahrens 240e45ce728Sahrens /* inherit index (boolean) properties */ 24183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 242e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 24383d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 244e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 245e45ce728Sahrens boolean_table); 24683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 247e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 248e45ce728Sahrens boolean_table); 24983d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 250e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 251e45ce728Sahrens boolean_table); 25283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 253e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 254e45ce728Sahrens boolean_table); 25583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 256e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 25783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 258e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 259e45ce728Sahrens boolean_table); 26083d7f9feSTom Erickson zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 261da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 262da6c28aaSamw boolean_table); 26383d7f9feSTom Erickson zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 264da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 265da6c28aaSamw boolean_table); 266e45ce728Sahrens 267e45ce728Sahrens /* default index properties */ 26883d7f9feSTom Erickson zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 26991ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 27014843421SMatthew Ahrens "1 | 2 | 3 | 4 | current", "VERSION", version_table); 27183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 272a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 273a227b7f4Shs24103 "CANMOUNT", canmount_table); 274e45ce728Sahrens 275e45ce728Sahrens /* readonly index (boolean) properties */ 27683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 277990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 27883d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 279842727c2SChris Kirby PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 280842727c2SChris Kirby boolean_table); 281e45ce728Sahrens 282da6c28aaSamw /* set once index properties */ 28383d7f9feSTom Erickson zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 284da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 285da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 286da6c28aaSamw normalize_table); 28783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CASE, "casesensitivity", 28883d7f9feSTom Erickson ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | 28983d7f9feSTom Erickson ZFS_TYPE_SNAPSHOT, 290da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 291da6c28aaSamw 292da6c28aaSamw /* set once index (boolean) properties */ 29383d7f9feSTom Erickson zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 294da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 295da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 296da6c28aaSamw 29791ebeef5Sahrens /* string properties */ 29883d7f9feSTom Erickson zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 29991ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 30083d7f9feSTom Erickson zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", 30183d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", 30283d7f9feSTom Erickson "MOUNTPOINT"); 30383d7f9feSTom Erickson zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", 30483d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", 30583d7f9feSTom Erickson "SHARENFS"); 30683d7f9feSTom Erickson zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 307990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 30883d7f9feSTom Erickson zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", 30983d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 31083d7f9feSTom Erickson "on | off | sharemgr(1M) options", "SHARESMB"); 31183d7f9feSTom Erickson zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", 31283d7f9feSTom Erickson ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, 31383d7f9feSTom Erickson "<sensitivity label>", "MLSLABEL"); 31491ebeef5Sahrens 31591ebeef5Sahrens /* readonly number properties */ 31683d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 317990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 31883d7f9feSTom Erickson zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 319990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 32083d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, 32183d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); 32283d7f9feSTom Erickson zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 323990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 32491ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 325*187d6ac0SMatt Ahrens zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0, 326*187d6ac0SMatt Ahrens PROP_READONLY, ZFS_TYPE_DATASET, 327*187d6ac0SMatt Ahrens "<1.00x or higher if compressed>", "REFRATIO"); 32883d7f9feSTom Erickson zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 329c1449561SEric Taylor ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 330da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 33183d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, 33283d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 33383d7f9feSTom Erickson "USEDSNAP"); 33483d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, 33583d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 33683d7f9feSTom Erickson "USEDDS"); 33783d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, 33883d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 33983d7f9feSTom Erickson "USEDCHILD"); 34083d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 34174e7dc98SMatthew Ahrens PROP_READONLY, 34274e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 34383d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 344842727c2SChris Kirby ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 34591ebeef5Sahrens 34691ebeef5Sahrens /* default number properties */ 34783d7f9feSTom Erickson zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 34891ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 34983d7f9feSTom Erickson zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, 35083d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 35183d7f9feSTom Erickson "<size> | none", "RESERV"); 35283d7f9feSTom Erickson zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 35391ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 35483d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 355a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 35683d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 357a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 358a9799022Sck153898 "<size> | none", "REFRESERV"); 35991ebeef5Sahrens 36091ebeef5Sahrens /* inherit number properties */ 36183d7f9feSTom Erickson zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", 36283d7f9feSTom Erickson SPA_MAXBLOCKSIZE, PROP_INHERIT, 36391ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 36491ebeef5Sahrens 36591ebeef5Sahrens /* hidden properties */ 36683d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 367b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 36883d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 369b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 37083d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 371990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 37283d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", 37383d7f9feSTom Erickson PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 37483d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 375478ed9adSEric Taylor PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 376478ed9adSEric Taylor "STMF_SBD_LU"); 37783d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, 37883d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_DATASET, "GUID"); 37983d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 380b24ab676SJeff Bonwick PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 381b24ab676SJeff Bonwick "USERACCOUNTING"); 38283d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 383b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 38483d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 3851d713200SEric Schrock PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 38691ebeef5Sahrens 38791ebeef5Sahrens /* oddball properties */ 38883d7f9feSTom Erickson zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, 38983d7f9feSTom Erickson NULL, PROP_READONLY, ZFS_TYPE_DATASET, 39091ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 39191ebeef5Sahrens } 39291ebeef5Sahrens 393b1b8ab34Slling boolean_t 394990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 395b1b8ab34Slling { 396990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 3974201a95eSRic Aleshire 3984201a95eSRic Aleshire /* The mlslabel property is never delegatable. */ 3994201a95eSRic Aleshire if (prop == ZFS_PROP_MLSLABEL) 4004201a95eSRic Aleshire return (B_FALSE); 4014201a95eSRic Aleshire 402990b4856Slling return (pd->pd_attr != PROP_READONLY); 403b1b8ab34Slling } 404b1b8ab34Slling 405b1b8ab34Slling /* 406b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 407fa9e4066Sahrens */ 408fa9e4066Sahrens zfs_prop_t 409fa9e4066Sahrens zfs_name_to_prop(const char *propname) 410fa9e4066Sahrens { 411990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 412b1b8ab34Slling } 413fa9e4066Sahrens 414fa9e4066Sahrens /* 415e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 416e9dbad6fSeschrock * a few useful punctuation characters. 417e9dbad6fSeschrock */ 418e9dbad6fSeschrock static int 419e9dbad6fSeschrock valid_char(char c) 420e9dbad6fSeschrock { 421e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 422e9dbad6fSeschrock (c >= '0' && c <= '9') || 423e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 424e9dbad6fSeschrock } 425e9dbad6fSeschrock 426e9dbad6fSeschrock /* 427e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 428e9dbad6fSeschrock */ 429e9dbad6fSeschrock boolean_t 430e9dbad6fSeschrock zfs_prop_user(const char *name) 431e9dbad6fSeschrock { 432e9dbad6fSeschrock int i; 433e9dbad6fSeschrock char c; 434e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 435e9dbad6fSeschrock 436e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 437e9dbad6fSeschrock c = name[i]; 438e9dbad6fSeschrock if (!valid_char(c)) 439e9dbad6fSeschrock return (B_FALSE); 440e9dbad6fSeschrock if (c == ':') 441e9dbad6fSeschrock foundsep = B_TRUE; 442e9dbad6fSeschrock } 443e9dbad6fSeschrock 444e9dbad6fSeschrock if (!foundsep) 445e9dbad6fSeschrock return (B_FALSE); 446e9dbad6fSeschrock 447e9dbad6fSeschrock return (B_TRUE); 448e9dbad6fSeschrock } 449e9dbad6fSeschrock 450e9dbad6fSeschrock /* 45114843421SMatthew Ahrens * Returns true if this is a valid userspace-type property (one with a '@'). 45214843421SMatthew Ahrens * Note that after the @, any character is valid (eg, another @, for SID 45314843421SMatthew Ahrens * user@domain). 45414843421SMatthew Ahrens */ 45514843421SMatthew Ahrens boolean_t 45614843421SMatthew Ahrens zfs_prop_userquota(const char *name) 45714843421SMatthew Ahrens { 45814843421SMatthew Ahrens zfs_userquota_prop_t prop; 45914843421SMatthew Ahrens 46014843421SMatthew Ahrens for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 46114843421SMatthew Ahrens if (strncmp(name, zfs_userquota_prop_prefixes[prop], 46214843421SMatthew Ahrens strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 46314843421SMatthew Ahrens return (B_TRUE); 46414843421SMatthew Ahrens } 46514843421SMatthew Ahrens } 46614843421SMatthew Ahrens 46714843421SMatthew Ahrens return (B_FALSE); 46814843421SMatthew Ahrens } 46914843421SMatthew Ahrens 47014843421SMatthew Ahrens /* 471990b4856Slling * Tables of index types, plus functions to convert between the user view 472990b4856Slling * (strings) and internal representation (uint64_t). 473fa9e4066Sahrens */ 474990b4856Slling int 475990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 476fa9e4066Sahrens { 477990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 478990b4856Slling } 479990b4856Slling 480990b4856Slling int 481990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 482990b4856Slling { 483990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 484990b4856Slling } 485990b4856Slling 486b24ab676SJeff Bonwick uint64_t 487b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 488b24ab676SJeff Bonwick { 489b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 490b24ab676SJeff Bonwick } 491b24ab676SJeff Bonwick 492990b4856Slling /* 493990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 494990b4856Slling */ 4954853e976Sgw25295 boolean_t 496990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 497990b4856Slling { 498990b4856Slling return (zprop_valid_for_type(prop, types)); 499990b4856Slling } 500990b4856Slling 501990b4856Slling zprop_type_t 502990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 503990b4856Slling { 504990b4856Slling return (zfs_prop_table[prop].pd_proptype); 505990b4856Slling } 506990b4856Slling 507990b4856Slling /* 508990b4856Slling * Returns TRUE if the property is readonly. 509990b4856Slling */ 510990b4856Slling boolean_t 511990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 512990b4856Slling { 513da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 514da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 515da6c28aaSamw } 516da6c28aaSamw 517da6c28aaSamw /* 518da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 519da6c28aaSamw */ 520da6c28aaSamw boolean_t 521da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 522da6c28aaSamw { 523da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 524fa9e4066Sahrens } 525fa9e4066Sahrens 5263d7072f8Seschrock const char * 527990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 5283d7072f8Seschrock { 5293d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 5303d7072f8Seschrock } 5313d7072f8Seschrock 532fa9e4066Sahrens uint64_t 533fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 534fa9e4066Sahrens { 535fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 536fa9e4066Sahrens } 537fa9e4066Sahrens 538fa9e4066Sahrens /* 539b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 5403d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 541fa9e4066Sahrens */ 542fa9e4066Sahrens const char * 543fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 544fa9e4066Sahrens { 545fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 546fa9e4066Sahrens } 547fa9e4066Sahrens 548fa9e4066Sahrens /* 549fa9e4066Sahrens * Returns TRUE if the property is inheritable. 550fa9e4066Sahrens */ 551990b4856Slling boolean_t 552fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 553fa9e4066Sahrens { 554da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 555da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 556e9dbad6fSeschrock } 557e9dbad6fSeschrock 558acd76fe5Seschrock #ifndef _KERNEL 559acd76fe5Seschrock 560fa9e4066Sahrens /* 561fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 562b1b8ab34Slling * zfs property, or NULL if it cannot be set. 563fa9e4066Sahrens */ 564fa9e4066Sahrens const char * 565fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 566fa9e4066Sahrens { 567fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 568fa9e4066Sahrens } 569fa9e4066Sahrens 570fa9e4066Sahrens /* 571fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 572fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 573fa9e4066Sahrens * are stored numerically on disk. 574fa9e4066Sahrens */ 575fa9e4066Sahrens int 576fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 577fa9e4066Sahrens { 57891ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 57991ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 580fa9e4066Sahrens } 581fa9e4066Sahrens 582fa9e4066Sahrens /* 583fa9e4066Sahrens * Returns the column header for the given property. Used only in 584fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 585fa9e4066Sahrens */ 586fa9e4066Sahrens const char * 587fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 588fa9e4066Sahrens { 589fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 590fa9e4066Sahrens } 591fa9e4066Sahrens 592fa9e4066Sahrens /* 593e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 594e9dbad6fSeschrock * 'zfs list'. 595fa9e4066Sahrens */ 596e9dbad6fSeschrock boolean_t 597e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 598fa9e4066Sahrens { 599e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 600fa9e4066Sahrens } 601da6c28aaSamw 602fa9e4066Sahrens #endif 603