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 /* 22c1449561SEric 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_TYPE, "type", NULL, PROP_READONLY, 289990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 290da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 291da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 2924201a95eSRic Aleshire register_string(ZFS_PROP_MLSLABEL, "mlslabel", ZFS_MLSLABEL_DEFAULT, 2934201a95eSRic Aleshire PROP_INHERIT, ZFS_TYPE_DATASET, "<sensitivity label>", "MLSLABEL"); 29491ebeef5Sahrens 29591ebeef5Sahrens /* readonly number properties */ 29691ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 297990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 29891ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 299990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 30091ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 301990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 30291ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 303990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 30491ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 305c1449561SEric Taylor register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 306c1449561SEric Taylor ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 307da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 30874e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY, 30974e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP"); 31074e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY, 31174e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS"); 31274e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY, 31374e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD"); 31474e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 31574e7dc98SMatthew Ahrens PROP_READONLY, 31674e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 317842727c2SChris Kirby register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 318842727c2SChris Kirby ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 31991ebeef5Sahrens 32091ebeef5Sahrens /* default number properties */ 32191ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 32291ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 32391ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 32491ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 32591ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 32691ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 327a9799022Sck153898 register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 328a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 329a9799022Sck153898 register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 330a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 331a9799022Sck153898 "<size> | none", "REFRESERV"); 33291ebeef5Sahrens 33391ebeef5Sahrens /* inherit number properties */ 33491ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 33591ebeef5Sahrens PROP_INHERIT, 33691ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 33791ebeef5Sahrens 33891ebeef5Sahrens /* hidden properties */ 33991ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 340b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 34191ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 342b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 34391ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 344990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 34591ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 346*ab003da8SJim Dunham PROP_READONLY, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 347478ed9adSEric Taylor register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 348478ed9adSEric Taylor PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 349478ed9adSEric Taylor "STMF_SBD_LU"); 350c5904d13Seschrock register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 351c5904d13Seschrock ZFS_TYPE_DATASET, "GUID"); 35214843421SMatthew Ahrens register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 353b24ab676SJeff Bonwick PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 354b24ab676SJeff Bonwick "USERACCOUNTING"); 3551d713200SEric Schrock register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 356b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 3571d713200SEric Schrock register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 3581d713200SEric Schrock PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 35991ebeef5Sahrens 36091ebeef5Sahrens /* oddball properties */ 36191ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 362990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 36391ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 36491ebeef5Sahrens } 36591ebeef5Sahrens 366b1b8ab34Slling boolean_t 367990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 368b1b8ab34Slling { 369990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 3704201a95eSRic Aleshire 3714201a95eSRic Aleshire /* The mlslabel property is never delegatable. */ 3724201a95eSRic Aleshire if (prop == ZFS_PROP_MLSLABEL) 3734201a95eSRic Aleshire return (B_FALSE); 3744201a95eSRic Aleshire 375990b4856Slling return (pd->pd_attr != PROP_READONLY); 376b1b8ab34Slling } 377b1b8ab34Slling 378b1b8ab34Slling /* 379b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 380fa9e4066Sahrens */ 381fa9e4066Sahrens zfs_prop_t 382fa9e4066Sahrens zfs_name_to_prop(const char *propname) 383fa9e4066Sahrens { 384990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 385b1b8ab34Slling } 386fa9e4066Sahrens 387fa9e4066Sahrens /* 388e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 389e9dbad6fSeschrock * a few useful punctuation characters. 390e9dbad6fSeschrock */ 391e9dbad6fSeschrock static int 392e9dbad6fSeschrock valid_char(char c) 393e9dbad6fSeschrock { 394e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 395e9dbad6fSeschrock (c >= '0' && c <= '9') || 396e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 397e9dbad6fSeschrock } 398e9dbad6fSeschrock 399e9dbad6fSeschrock /* 400e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 401e9dbad6fSeschrock */ 402e9dbad6fSeschrock boolean_t 403e9dbad6fSeschrock zfs_prop_user(const char *name) 404e9dbad6fSeschrock { 405e9dbad6fSeschrock int i; 406e9dbad6fSeschrock char c; 407e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 408e9dbad6fSeschrock 409e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 410e9dbad6fSeschrock c = name[i]; 411e9dbad6fSeschrock if (!valid_char(c)) 412e9dbad6fSeschrock return (B_FALSE); 413e9dbad6fSeschrock if (c == ':') 414e9dbad6fSeschrock foundsep = B_TRUE; 415e9dbad6fSeschrock } 416e9dbad6fSeschrock 417e9dbad6fSeschrock if (!foundsep) 418e9dbad6fSeschrock return (B_FALSE); 419e9dbad6fSeschrock 420e9dbad6fSeschrock return (B_TRUE); 421e9dbad6fSeschrock } 422e9dbad6fSeschrock 423e9dbad6fSeschrock /* 42414843421SMatthew Ahrens * Returns true if this is a valid userspace-type property (one with a '@'). 42514843421SMatthew Ahrens * Note that after the @, any character is valid (eg, another @, for SID 42614843421SMatthew Ahrens * user@domain). 42714843421SMatthew Ahrens */ 42814843421SMatthew Ahrens boolean_t 42914843421SMatthew Ahrens zfs_prop_userquota(const char *name) 43014843421SMatthew Ahrens { 43114843421SMatthew Ahrens zfs_userquota_prop_t prop; 43214843421SMatthew Ahrens 43314843421SMatthew Ahrens for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 43414843421SMatthew Ahrens if (strncmp(name, zfs_userquota_prop_prefixes[prop], 43514843421SMatthew Ahrens strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 43614843421SMatthew Ahrens return (B_TRUE); 43714843421SMatthew Ahrens } 43814843421SMatthew Ahrens } 43914843421SMatthew Ahrens 44014843421SMatthew Ahrens return (B_FALSE); 44114843421SMatthew Ahrens } 44214843421SMatthew Ahrens 44314843421SMatthew Ahrens /* 444990b4856Slling * Tables of index types, plus functions to convert between the user view 445990b4856Slling * (strings) and internal representation (uint64_t). 446fa9e4066Sahrens */ 447990b4856Slling int 448990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 449fa9e4066Sahrens { 450990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 451990b4856Slling } 452990b4856Slling 453990b4856Slling int 454990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 455990b4856Slling { 456990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 457990b4856Slling } 458990b4856Slling 459b24ab676SJeff Bonwick uint64_t 460b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 461b24ab676SJeff Bonwick { 462b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 463b24ab676SJeff Bonwick } 464b24ab676SJeff Bonwick 465990b4856Slling /* 466990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 467990b4856Slling */ 4684853e976Sgw25295 boolean_t 469990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 470990b4856Slling { 471990b4856Slling return (zprop_valid_for_type(prop, types)); 472990b4856Slling } 473990b4856Slling 474990b4856Slling zprop_type_t 475990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 476990b4856Slling { 477990b4856Slling return (zfs_prop_table[prop].pd_proptype); 478990b4856Slling } 479990b4856Slling 480990b4856Slling /* 481990b4856Slling * Returns TRUE if the property is readonly. 482990b4856Slling */ 483990b4856Slling boolean_t 484990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 485990b4856Slling { 486da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 487da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 488da6c28aaSamw } 489da6c28aaSamw 490da6c28aaSamw /* 491da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 492da6c28aaSamw */ 493da6c28aaSamw boolean_t 494da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 495da6c28aaSamw { 496da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 497fa9e4066Sahrens } 498fa9e4066Sahrens 4993d7072f8Seschrock const char * 500990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 5013d7072f8Seschrock { 5023d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 5033d7072f8Seschrock } 5043d7072f8Seschrock 505fa9e4066Sahrens uint64_t 506fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 507fa9e4066Sahrens { 508fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 509fa9e4066Sahrens } 510fa9e4066Sahrens 511fa9e4066Sahrens /* 512b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 5133d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 514fa9e4066Sahrens */ 515fa9e4066Sahrens const char * 516fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 517fa9e4066Sahrens { 518fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 519fa9e4066Sahrens } 520fa9e4066Sahrens 521fa9e4066Sahrens /* 522fa9e4066Sahrens * Returns TRUE if the property is inheritable. 523fa9e4066Sahrens */ 524990b4856Slling boolean_t 525fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 526fa9e4066Sahrens { 527da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 528da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 529e9dbad6fSeschrock } 530e9dbad6fSeschrock 531acd76fe5Seschrock #ifndef _KERNEL 532acd76fe5Seschrock 533fa9e4066Sahrens /* 534fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 535b1b8ab34Slling * zfs property, or NULL if it cannot be set. 536fa9e4066Sahrens */ 537fa9e4066Sahrens const char * 538fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 539fa9e4066Sahrens { 540fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 541fa9e4066Sahrens } 542fa9e4066Sahrens 543fa9e4066Sahrens /* 544fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 545fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 546fa9e4066Sahrens * are stored numerically on disk. 547fa9e4066Sahrens */ 548fa9e4066Sahrens int 549fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 550fa9e4066Sahrens { 55191ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 55291ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 553fa9e4066Sahrens } 554fa9e4066Sahrens 555fa9e4066Sahrens /* 556fa9e4066Sahrens * Returns the column header for the given property. Used only in 557fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 558fa9e4066Sahrens */ 559fa9e4066Sahrens const char * 560fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 561fa9e4066Sahrens { 562fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 563fa9e4066Sahrens } 564fa9e4066Sahrens 565fa9e4066Sahrens /* 566e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 567e9dbad6fSeschrock * 'zfs list'. 568fa9e4066Sahrens */ 569e9dbad6fSeschrock boolean_t 570e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 571fa9e4066Sahrens { 572e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 573fa9e4066Sahrens } 574da6c28aaSamw 575fa9e4066Sahrens #endif 576