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 /* 22*c1449561SEric Taylor * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #include <sys/zio.h> 27fa9e4066Sahrens #include <sys/spa.h> 28de8267e0Stimh #include <sys/u8_textprep.h> 29fa9e4066Sahrens #include <sys/zfs_acl.h> 30fa9e4066Sahrens #include <sys/zfs_ioctl.h> 31e7437265Sahrens #include <sys/zfs_znode.h> 32fa9e4066Sahrens 33fa9e4066Sahrens #include "zfs_prop.h" 34ecd6cf80Smarks #include "zfs_deleg.h" 35fa9e4066Sahrens 36fa9e4066Sahrens #if defined(_KERNEL) 37fa9e4066Sahrens #include <sys/systm.h> 38fa9e4066Sahrens #else 39fa9e4066Sahrens #include <stdlib.h> 40fa9e4066Sahrens #include <string.h> 41fa9e4066Sahrens #include <ctype.h> 42fa9e4066Sahrens #endif 43fa9e4066Sahrens 44990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 45fa9e4066Sahrens 4614843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ 4714843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = { 4814843421SMatthew Ahrens "userused@", 4914843421SMatthew Ahrens "userquota@", 5014843421SMatthew Ahrens "groupused@", 5114843421SMatthew Ahrens "groupquota@" 5214843421SMatthew Ahrens }; 5314843421SMatthew Ahrens 54990b4856Slling zprop_desc_t * 55990b4856Slling zfs_prop_get_table(void) 5691ebeef5Sahrens { 57990b4856Slling return (zfs_prop_table); 5891ebeef5Sahrens } 5991ebeef5Sahrens 6091ebeef5Sahrens void 6191ebeef5Sahrens zfs_prop_init(void) 6291ebeef5Sahrens { 63990b4856Slling static zprop_index_t checksum_table[] = { 6491ebeef5Sahrens { "on", ZIO_CHECKSUM_ON }, 6591ebeef5Sahrens { "off", ZIO_CHECKSUM_OFF }, 6691ebeef5Sahrens { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 6791ebeef5Sahrens { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 6891ebeef5Sahrens { "sha256", ZIO_CHECKSUM_SHA256 }, 6991ebeef5Sahrens { NULL } 70fa9e4066Sahrens }; 71fa9e4066Sahrens 72b24ab676SJeff Bonwick static zprop_index_t dedup_table[] = { 73b24ab676SJeff Bonwick { "on", ZIO_CHECKSUM_ON }, 74b24ab676SJeff Bonwick { "off", ZIO_CHECKSUM_OFF }, 75b24ab676SJeff Bonwick { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, 76b24ab676SJeff Bonwick { "sha256", ZIO_CHECKSUM_SHA256 }, 77b24ab676SJeff Bonwick { "sha256,verify", 78b24ab676SJeff Bonwick ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, 79b24ab676SJeff Bonwick { NULL } 80b24ab676SJeff Bonwick }; 81b24ab676SJeff Bonwick 82990b4856Slling static zprop_index_t compress_table[] = { 8391ebeef5Sahrens { "on", ZIO_COMPRESS_ON }, 8491ebeef5Sahrens { "off", ZIO_COMPRESS_OFF }, 8591ebeef5Sahrens { "lzjb", ZIO_COMPRESS_LZJB }, 8691ebeef5Sahrens { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 8791ebeef5Sahrens { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 8891ebeef5Sahrens { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 8991ebeef5Sahrens { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 9091ebeef5Sahrens { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 9191ebeef5Sahrens { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 9291ebeef5Sahrens { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 9391ebeef5Sahrens { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 9491ebeef5Sahrens { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 9591ebeef5Sahrens { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 96b24ab676SJeff Bonwick { "zle", ZIO_COMPRESS_ZLE }, 9791ebeef5Sahrens { NULL } 9891ebeef5Sahrens }; 9991ebeef5Sahrens 100990b4856Slling static zprop_index_t snapdir_table[] = { 10191ebeef5Sahrens { "hidden", ZFS_SNAPDIR_HIDDEN }, 10291ebeef5Sahrens { "visible", ZFS_SNAPDIR_VISIBLE }, 10391ebeef5Sahrens { NULL } 10491ebeef5Sahrens }; 10591ebeef5Sahrens 106990b4856Slling static zprop_index_t acl_mode_table[] = { 10791ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 10891ebeef5Sahrens { "groupmask", ZFS_ACL_GROUPMASK }, 10991ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 11091ebeef5Sahrens { NULL } 11191ebeef5Sahrens }; 11291ebeef5Sahrens 113990b4856Slling static zprop_index_t acl_inherit_table[] = { 11491ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 11591ebeef5Sahrens { "noallow", ZFS_ACL_NOALLOW }, 116b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 11791ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 118b3d141f8Smarks { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 119d0f3f37eSMark Shellenbaum { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 12091ebeef5Sahrens { NULL } 12191ebeef5Sahrens }; 12291ebeef5Sahrens 123da6c28aaSamw static zprop_index_t case_table[] = { 124da6c28aaSamw { "sensitive", ZFS_CASE_SENSITIVE }, 125da6c28aaSamw { "insensitive", ZFS_CASE_INSENSITIVE }, 126da6c28aaSamw { "mixed", ZFS_CASE_MIXED }, 127da6c28aaSamw { NULL } 128da6c28aaSamw }; 129da6c28aaSamw 130990b4856Slling static zprop_index_t copies_table[] = { 13191ebeef5Sahrens { "1", 1 }, 13291ebeef5Sahrens { "2", 2 }, 13391ebeef5Sahrens { "3", 3 }, 13491ebeef5Sahrens { NULL } 13591ebeef5Sahrens }; 13691ebeef5Sahrens 137de8267e0Stimh /* 138de8267e0Stimh * Use the unique flags we have to send to u8_strcmp() and/or 139de8267e0Stimh * u8_textprep() to represent the various normalization property 140de8267e0Stimh * values. 141de8267e0Stimh */ 142da6c28aaSamw static zprop_index_t normalize_table[] = { 143de8267e0Stimh { "none", 0 }, 144de8267e0Stimh { "formD", U8_TEXTPREP_NFD }, 145de8267e0Stimh { "formKC", U8_TEXTPREP_NFKC }, 146de8267e0Stimh { "formC", U8_TEXTPREP_NFC }, 147de8267e0Stimh { "formKD", U8_TEXTPREP_NFKD }, 148da6c28aaSamw { NULL } 149da6c28aaSamw }; 150da6c28aaSamw 151990b4856Slling static zprop_index_t version_table[] = { 15291ebeef5Sahrens { "1", 1 }, 15391ebeef5Sahrens { "2", 2 }, 154da6c28aaSamw { "3", 3 }, 15514843421SMatthew Ahrens { "4", 4 }, 15691ebeef5Sahrens { "current", ZPL_VERSION }, 15791ebeef5Sahrens { NULL } 15891ebeef5Sahrens }; 15991ebeef5Sahrens 160990b4856Slling static zprop_index_t boolean_table[] = { 161e45ce728Sahrens { "off", 0 }, 162e45ce728Sahrens { "on", 1 }, 163e45ce728Sahrens { NULL } 164e45ce728Sahrens }; 165e45ce728Sahrens 166e09fa4daSNeil Perrin static zprop_index_t logbias_table[] = { 167e09fa4daSNeil Perrin { "latency", ZFS_LOGBIAS_LATENCY }, 168e09fa4daSNeil Perrin { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 169e09fa4daSNeil Perrin { NULL } 170e09fa4daSNeil Perrin }; 171e09fa4daSNeil Perrin 172a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 173a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 174a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 175a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 176a227b7f4Shs24103 { NULL } 177a227b7f4Shs24103 }; 178a227b7f4Shs24103 1793baa08fcSek110237 static zprop_index_t cache_table[] = { 1803baa08fcSek110237 { "none", ZFS_CACHE_NONE }, 1813baa08fcSek110237 { "metadata", ZFS_CACHE_METADATA }, 1823baa08fcSek110237 { "all", ZFS_CACHE_ALL }, 1833baa08fcSek110237 { NULL } 1843baa08fcSek110237 }; 1853baa08fcSek110237 18691ebeef5Sahrens /* inherit index properties */ 18791ebeef5Sahrens register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 188e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 18991ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 19091ebeef5Sahrens checksum_table); 191b24ab676SJeff Bonwick register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 192b24ab676SJeff Bonwick PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 193b1033ae2SMatthew Ahrens "on | off | verify | sha256[,verify]", "DEDUP", 194b24ab676SJeff Bonwick dedup_table); 19591ebeef5Sahrens register_index(ZFS_PROP_COMPRESSION, "compression", 196e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 197e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 198b24ab676SJeff Bonwick "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS", 199b24ab676SJeff Bonwick compress_table); 20091ebeef5Sahrens register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 201e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 202e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 20391ebeef5Sahrens register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 204e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 205990b4856Slling "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 206b3d141f8Smarks register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 207e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 208d0f3f37eSMark Shellenbaum "discard | noallow | restricted | passthrough | passthrough-x", 209b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 21091ebeef5Sahrens register_index(ZFS_PROP_COPIES, "copies", 1, 211e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 21291ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 2133baa08fcSek110237 register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 2143baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2153baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2163baa08fcSek110237 "all | none | metadata", "PRIMARYCACHE", cache_table); 2173baa08fcSek110237 register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 2183baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2193baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2203baa08fcSek110237 "all | none | metadata", "SECONDARYCACHE", cache_table); 221e09fa4daSNeil Perrin register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 222e09fa4daSNeil Perrin PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 223e09fa4daSNeil Perrin "latency | throughput", "LOGBIAS", logbias_table); 224e45ce728Sahrens 225e45ce728Sahrens /* inherit index (boolean) properties */ 226e45ce728Sahrens register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 227e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 228e45ce728Sahrens register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 229e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 230e45ce728Sahrens boolean_table); 231e45ce728Sahrens register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 232e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 233e45ce728Sahrens boolean_table); 234e45ce728Sahrens register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 235e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 236e45ce728Sahrens boolean_table); 237e45ce728Sahrens register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 238e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 239e45ce728Sahrens boolean_table); 240e45ce728Sahrens register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 241e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 242e45ce728Sahrens register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 243e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 244e45ce728Sahrens boolean_table); 245da6c28aaSamw register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 246da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 247da6c28aaSamw boolean_table); 248da6c28aaSamw register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 249da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 250da6c28aaSamw boolean_table); 251e45ce728Sahrens 252e45ce728Sahrens /* default index properties */ 253e45ce728Sahrens register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 25491ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 25514843421SMatthew Ahrens "1 | 2 | 3 | 4 | current", "VERSION", version_table); 256a227b7f4Shs24103 register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 257a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 258a227b7f4Shs24103 "CANMOUNT", canmount_table); 259e45ce728Sahrens 260e45ce728Sahrens /* readonly index (boolean) properties */ 261e45ce728Sahrens register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 262990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 263842727c2SChris Kirby register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 264842727c2SChris Kirby PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 265842727c2SChris Kirby boolean_table); 266e45ce728Sahrens 267da6c28aaSamw /* set once index properties */ 268de8267e0Stimh register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 269da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 270da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 271da6c28aaSamw normalize_table); 272da6c28aaSamw register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 273da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 274da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 275da6c28aaSamw 276da6c28aaSamw /* set once index (boolean) properties */ 277da6c28aaSamw register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 278da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 279da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 280da6c28aaSamw 28191ebeef5Sahrens /* string properties */ 28291ebeef5Sahrens register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 28391ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 28491ebeef5Sahrens register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 28591ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 28691ebeef5Sahrens register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 28791ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 28891ebeef5Sahrens register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT, 289990b4856Slling ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI"); 29091ebeef5Sahrens register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 291990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 292da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 293da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 2944201a95eSRic Aleshire register_string(ZFS_PROP_MLSLABEL, "mlslabel", ZFS_MLSLABEL_DEFAULT, 2954201a95eSRic Aleshire PROP_INHERIT, ZFS_TYPE_DATASET, "<sensitivity label>", "MLSLABEL"); 29691ebeef5Sahrens 29791ebeef5Sahrens /* readonly number properties */ 29891ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 299990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 30091ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 301990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 30291ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 303990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 30491ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 305990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 30691ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 307*c1449561SEric Taylor register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 308*c1449561SEric Taylor ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 309da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 31074e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY, 31174e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP"); 31274e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY, 31374e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS"); 31474e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY, 31574e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD"); 31674e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 31774e7dc98SMatthew Ahrens PROP_READONLY, 31874e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 319842727c2SChris Kirby register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 320842727c2SChris Kirby ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 32191ebeef5Sahrens 32291ebeef5Sahrens /* default number properties */ 32391ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 32491ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 32591ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 32691ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 32791ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 32891ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 329a9799022Sck153898 register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 330a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 331a9799022Sck153898 register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 332a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 333a9799022Sck153898 "<size> | none", "REFRESERV"); 33491ebeef5Sahrens 33591ebeef5Sahrens /* inherit number properties */ 33691ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 33791ebeef5Sahrens PROP_INHERIT, 33891ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 33991ebeef5Sahrens 34091ebeef5Sahrens /* hidden properties */ 34191ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 342b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 34391ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 344b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 34591ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 346990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 34791ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 34891ebeef5Sahrens PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 349478ed9adSEric Taylor register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 350478ed9adSEric Taylor PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 351478ed9adSEric Taylor "STMF_SBD_LU"); 352c5904d13Seschrock register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 353c5904d13Seschrock ZFS_TYPE_DATASET, "GUID"); 35414843421SMatthew Ahrens register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 355b24ab676SJeff Bonwick PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 356b24ab676SJeff Bonwick "USERACCOUNTING"); 3571d713200SEric Schrock register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 358b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 3591d713200SEric Schrock register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 3601d713200SEric Schrock PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 36191ebeef5Sahrens 36291ebeef5Sahrens /* oddball properties */ 36391ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 364990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 36591ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 36691ebeef5Sahrens } 36791ebeef5Sahrens 368b1b8ab34Slling boolean_t 369990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 370b1b8ab34Slling { 371990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 3724201a95eSRic Aleshire 3734201a95eSRic Aleshire /* The mlslabel property is never delegatable. */ 3744201a95eSRic Aleshire if (prop == ZFS_PROP_MLSLABEL) 3754201a95eSRic Aleshire return (B_FALSE); 3764201a95eSRic Aleshire 377990b4856Slling return (pd->pd_attr != PROP_READONLY); 378b1b8ab34Slling } 379b1b8ab34Slling 380b1b8ab34Slling /* 381b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 382fa9e4066Sahrens */ 383fa9e4066Sahrens zfs_prop_t 384fa9e4066Sahrens zfs_name_to_prop(const char *propname) 385fa9e4066Sahrens { 386990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 387b1b8ab34Slling } 388fa9e4066Sahrens 389fa9e4066Sahrens /* 390e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 391e9dbad6fSeschrock * a few useful punctuation characters. 392e9dbad6fSeschrock */ 393e9dbad6fSeschrock static int 394e9dbad6fSeschrock valid_char(char c) 395e9dbad6fSeschrock { 396e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 397e9dbad6fSeschrock (c >= '0' && c <= '9') || 398e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 399e9dbad6fSeschrock } 400e9dbad6fSeschrock 401e9dbad6fSeschrock /* 402e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 403e9dbad6fSeschrock */ 404e9dbad6fSeschrock boolean_t 405e9dbad6fSeschrock zfs_prop_user(const char *name) 406e9dbad6fSeschrock { 407e9dbad6fSeschrock int i; 408e9dbad6fSeschrock char c; 409e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 410e9dbad6fSeschrock 411e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 412e9dbad6fSeschrock c = name[i]; 413e9dbad6fSeschrock if (!valid_char(c)) 414e9dbad6fSeschrock return (B_FALSE); 415e9dbad6fSeschrock if (c == ':') 416e9dbad6fSeschrock foundsep = B_TRUE; 417e9dbad6fSeschrock } 418e9dbad6fSeschrock 419e9dbad6fSeschrock if (!foundsep) 420e9dbad6fSeschrock return (B_FALSE); 421e9dbad6fSeschrock 422e9dbad6fSeschrock return (B_TRUE); 423e9dbad6fSeschrock } 424e9dbad6fSeschrock 425e9dbad6fSeschrock /* 42614843421SMatthew Ahrens * Returns true if this is a valid userspace-type property (one with a '@'). 42714843421SMatthew Ahrens * Note that after the @, any character is valid (eg, another @, for SID 42814843421SMatthew Ahrens * user@domain). 42914843421SMatthew Ahrens */ 43014843421SMatthew Ahrens boolean_t 43114843421SMatthew Ahrens zfs_prop_userquota(const char *name) 43214843421SMatthew Ahrens { 43314843421SMatthew Ahrens zfs_userquota_prop_t prop; 43414843421SMatthew Ahrens 43514843421SMatthew Ahrens for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 43614843421SMatthew Ahrens if (strncmp(name, zfs_userquota_prop_prefixes[prop], 43714843421SMatthew Ahrens strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 43814843421SMatthew Ahrens return (B_TRUE); 43914843421SMatthew Ahrens } 44014843421SMatthew Ahrens } 44114843421SMatthew Ahrens 44214843421SMatthew Ahrens return (B_FALSE); 44314843421SMatthew Ahrens } 44414843421SMatthew Ahrens 44514843421SMatthew Ahrens /* 446990b4856Slling * Tables of index types, plus functions to convert between the user view 447990b4856Slling * (strings) and internal representation (uint64_t). 448fa9e4066Sahrens */ 449990b4856Slling int 450990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 451fa9e4066Sahrens { 452990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 453990b4856Slling } 454990b4856Slling 455990b4856Slling int 456990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 457990b4856Slling { 458990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 459990b4856Slling } 460990b4856Slling 461b24ab676SJeff Bonwick uint64_t 462b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 463b24ab676SJeff Bonwick { 464b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 465b24ab676SJeff Bonwick } 466b24ab676SJeff Bonwick 467990b4856Slling /* 468990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 469990b4856Slling */ 4704853e976Sgw25295 boolean_t 471990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 472990b4856Slling { 473990b4856Slling return (zprop_valid_for_type(prop, types)); 474990b4856Slling } 475990b4856Slling 476990b4856Slling zprop_type_t 477990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 478990b4856Slling { 479990b4856Slling return (zfs_prop_table[prop].pd_proptype); 480990b4856Slling } 481990b4856Slling 482990b4856Slling /* 483990b4856Slling * Returns TRUE if the property is readonly. 484990b4856Slling */ 485990b4856Slling boolean_t 486990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 487990b4856Slling { 488da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 489da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 490da6c28aaSamw } 491da6c28aaSamw 492da6c28aaSamw /* 493da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 494da6c28aaSamw */ 495da6c28aaSamw boolean_t 496da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 497da6c28aaSamw { 498da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 499fa9e4066Sahrens } 500fa9e4066Sahrens 5013d7072f8Seschrock const char * 502990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 5033d7072f8Seschrock { 5043d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 5053d7072f8Seschrock } 5063d7072f8Seschrock 507fa9e4066Sahrens uint64_t 508fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 509fa9e4066Sahrens { 510fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 511fa9e4066Sahrens } 512fa9e4066Sahrens 513fa9e4066Sahrens /* 514b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 5153d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 516fa9e4066Sahrens */ 517fa9e4066Sahrens const char * 518fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 519fa9e4066Sahrens { 520fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 521fa9e4066Sahrens } 522fa9e4066Sahrens 523fa9e4066Sahrens /* 524fa9e4066Sahrens * Returns TRUE if the property is inheritable. 525fa9e4066Sahrens */ 526990b4856Slling boolean_t 527fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 528fa9e4066Sahrens { 529da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 530da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 531e9dbad6fSeschrock } 532e9dbad6fSeschrock 533acd76fe5Seschrock #ifndef _KERNEL 534acd76fe5Seschrock 535fa9e4066Sahrens /* 536fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 537b1b8ab34Slling * zfs property, or NULL if it cannot be set. 538fa9e4066Sahrens */ 539fa9e4066Sahrens const char * 540fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 541fa9e4066Sahrens { 542fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 543fa9e4066Sahrens } 544fa9e4066Sahrens 545fa9e4066Sahrens /* 546fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 547fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 548fa9e4066Sahrens * are stored numerically on disk. 549fa9e4066Sahrens */ 550fa9e4066Sahrens int 551fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 552fa9e4066Sahrens { 55391ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 55491ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 555fa9e4066Sahrens } 556fa9e4066Sahrens 557fa9e4066Sahrens /* 558fa9e4066Sahrens * Returns the column header for the given property. Used only in 559fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 560fa9e4066Sahrens */ 561fa9e4066Sahrens const char * 562fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 563fa9e4066Sahrens { 564fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 565fa9e4066Sahrens } 566fa9e4066Sahrens 567fa9e4066Sahrens /* 568e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 569e9dbad6fSeschrock * 'zfs list'. 570fa9e4066Sahrens */ 571e9dbad6fSeschrock boolean_t 572e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 573fa9e4066Sahrens { 574e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 575fa9e4066Sahrens } 576da6c28aaSamw 577fa9e4066Sahrens #endif 578