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 }, 156*0a586ceaSMark Shellenbaum { "5", 5 }, 15791ebeef5Sahrens { "current", ZPL_VERSION }, 15891ebeef5Sahrens { NULL } 15991ebeef5Sahrens }; 16091ebeef5Sahrens 161990b4856Slling static zprop_index_t boolean_table[] = { 162e45ce728Sahrens { "off", 0 }, 163e45ce728Sahrens { "on", 1 }, 164e45ce728Sahrens { NULL } 165e45ce728Sahrens }; 166e45ce728Sahrens 167e09fa4daSNeil Perrin static zprop_index_t logbias_table[] = { 168e09fa4daSNeil Perrin { "latency", ZFS_LOGBIAS_LATENCY }, 169e09fa4daSNeil Perrin { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 170e09fa4daSNeil Perrin { NULL } 171e09fa4daSNeil Perrin }; 172e09fa4daSNeil Perrin 173a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 174a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 175a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 176a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 177a227b7f4Shs24103 { NULL } 178a227b7f4Shs24103 }; 179a227b7f4Shs24103 1803baa08fcSek110237 static zprop_index_t cache_table[] = { 1813baa08fcSek110237 { "none", ZFS_CACHE_NONE }, 1823baa08fcSek110237 { "metadata", ZFS_CACHE_METADATA }, 1833baa08fcSek110237 { "all", ZFS_CACHE_ALL }, 1843baa08fcSek110237 { NULL } 1853baa08fcSek110237 }; 1863baa08fcSek110237 18791ebeef5Sahrens /* inherit index properties */ 18891ebeef5Sahrens register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 189e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 19091ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 19191ebeef5Sahrens checksum_table); 192b24ab676SJeff Bonwick register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 193b24ab676SJeff Bonwick PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 194b1033ae2SMatthew Ahrens "on | off | verify | sha256[,verify]", "DEDUP", 195b24ab676SJeff Bonwick dedup_table); 19691ebeef5Sahrens register_index(ZFS_PROP_COMPRESSION, "compression", 197e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 198e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 199b24ab676SJeff Bonwick "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS", 200b24ab676SJeff Bonwick compress_table); 20191ebeef5Sahrens register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 202e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 203e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 20491ebeef5Sahrens register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 205e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 206990b4856Slling "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 207b3d141f8Smarks register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 208e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 209d0f3f37eSMark Shellenbaum "discard | noallow | restricted | passthrough | passthrough-x", 210b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 21191ebeef5Sahrens register_index(ZFS_PROP_COPIES, "copies", 1, 212e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 21391ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 2143baa08fcSek110237 register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 2153baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2163baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2173baa08fcSek110237 "all | none | metadata", "PRIMARYCACHE", cache_table); 2183baa08fcSek110237 register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 2193baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2203baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2213baa08fcSek110237 "all | none | metadata", "SECONDARYCACHE", cache_table); 222e09fa4daSNeil Perrin register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 223e09fa4daSNeil Perrin PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 224e09fa4daSNeil Perrin "latency | throughput", "LOGBIAS", logbias_table); 225e45ce728Sahrens 226e45ce728Sahrens /* inherit index (boolean) properties */ 227e45ce728Sahrens register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 228e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 229e45ce728Sahrens register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 230e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 231e45ce728Sahrens boolean_table); 232e45ce728Sahrens register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 233e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 234e45ce728Sahrens boolean_table); 235e45ce728Sahrens register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 236e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 237e45ce728Sahrens boolean_table); 238e45ce728Sahrens register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 239e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 240e45ce728Sahrens boolean_table); 241e45ce728Sahrens register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 242e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 243e45ce728Sahrens register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 244e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 245e45ce728Sahrens boolean_table); 246da6c28aaSamw register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 247da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 248da6c28aaSamw boolean_table); 249da6c28aaSamw register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 250da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 251da6c28aaSamw boolean_table); 252e45ce728Sahrens 253e45ce728Sahrens /* default index properties */ 254e45ce728Sahrens register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 25591ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 25614843421SMatthew Ahrens "1 | 2 | 3 | 4 | current", "VERSION", version_table); 257a227b7f4Shs24103 register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 258a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 259a227b7f4Shs24103 "CANMOUNT", canmount_table); 260e45ce728Sahrens 261e45ce728Sahrens /* readonly index (boolean) properties */ 262e45ce728Sahrens register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 263990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 264842727c2SChris Kirby register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 265842727c2SChris Kirby PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 266842727c2SChris Kirby boolean_table); 267e45ce728Sahrens 268da6c28aaSamw /* set once index properties */ 269de8267e0Stimh register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 270da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 271da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 272da6c28aaSamw normalize_table); 273da6c28aaSamw register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 274da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 275da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 276da6c28aaSamw 277da6c28aaSamw /* set once index (boolean) properties */ 278da6c28aaSamw register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 279da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 280da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 281da6c28aaSamw 28291ebeef5Sahrens /* string properties */ 28391ebeef5Sahrens register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 28491ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 28591ebeef5Sahrens register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 28691ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 28791ebeef5Sahrens register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 28891ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 28991ebeef5Sahrens register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 290990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 291da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 292da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 2934201a95eSRic Aleshire register_string(ZFS_PROP_MLSLABEL, "mlslabel", ZFS_MLSLABEL_DEFAULT, 2944201a95eSRic Aleshire PROP_INHERIT, ZFS_TYPE_DATASET, "<sensitivity label>", "MLSLABEL"); 29591ebeef5Sahrens 29691ebeef5Sahrens /* readonly number properties */ 29791ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 298990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 29991ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 300990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 30191ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 302990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 30391ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 304990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 30591ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 306c1449561SEric Taylor register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 307c1449561SEric Taylor ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 308da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 30974e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY, 31074e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP"); 31174e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY, 31274e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS"); 31374e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY, 31474e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD"); 31574e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 31674e7dc98SMatthew Ahrens PROP_READONLY, 31774e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 318842727c2SChris Kirby register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 319842727c2SChris Kirby ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 32091ebeef5Sahrens 32191ebeef5Sahrens /* default number properties */ 32291ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 32391ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 32491ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 32591ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 32691ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 32791ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 328a9799022Sck153898 register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 329a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 330a9799022Sck153898 register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 331a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 332a9799022Sck153898 "<size> | none", "REFRESERV"); 33391ebeef5Sahrens 33491ebeef5Sahrens /* inherit number properties */ 33591ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 33691ebeef5Sahrens PROP_INHERIT, 33791ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 33891ebeef5Sahrens 33991ebeef5Sahrens /* hidden properties */ 34091ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 341b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 34291ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 343b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 34491ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 345990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 34691ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 347ab003da8SJim Dunham PROP_READONLY, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 348478ed9adSEric Taylor register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 349478ed9adSEric Taylor PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 350478ed9adSEric Taylor "STMF_SBD_LU"); 351c5904d13Seschrock register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 352c5904d13Seschrock ZFS_TYPE_DATASET, "GUID"); 35314843421SMatthew Ahrens register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 354b24ab676SJeff Bonwick PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 355b24ab676SJeff Bonwick "USERACCOUNTING"); 3561d713200SEric Schrock register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 357b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 3581d713200SEric Schrock register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 3591d713200SEric Schrock PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 36091ebeef5Sahrens 36191ebeef5Sahrens /* oddball properties */ 36291ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 363990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 36491ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 36591ebeef5Sahrens } 36691ebeef5Sahrens 367b1b8ab34Slling boolean_t 368990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 369b1b8ab34Slling { 370990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 3714201a95eSRic Aleshire 3724201a95eSRic Aleshire /* The mlslabel property is never delegatable. */ 3734201a95eSRic Aleshire if (prop == ZFS_PROP_MLSLABEL) 3744201a95eSRic Aleshire return (B_FALSE); 3754201a95eSRic Aleshire 376990b4856Slling return (pd->pd_attr != PROP_READONLY); 377b1b8ab34Slling } 378b1b8ab34Slling 379b1b8ab34Slling /* 380b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 381fa9e4066Sahrens */ 382fa9e4066Sahrens zfs_prop_t 383fa9e4066Sahrens zfs_name_to_prop(const char *propname) 384fa9e4066Sahrens { 385990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 386b1b8ab34Slling } 387fa9e4066Sahrens 388fa9e4066Sahrens /* 389e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 390e9dbad6fSeschrock * a few useful punctuation characters. 391e9dbad6fSeschrock */ 392e9dbad6fSeschrock static int 393e9dbad6fSeschrock valid_char(char c) 394e9dbad6fSeschrock { 395e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 396e9dbad6fSeschrock (c >= '0' && c <= '9') || 397e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 398e9dbad6fSeschrock } 399e9dbad6fSeschrock 400e9dbad6fSeschrock /* 401e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 402e9dbad6fSeschrock */ 403e9dbad6fSeschrock boolean_t 404e9dbad6fSeschrock zfs_prop_user(const char *name) 405e9dbad6fSeschrock { 406e9dbad6fSeschrock int i; 407e9dbad6fSeschrock char c; 408e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 409e9dbad6fSeschrock 410e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 411e9dbad6fSeschrock c = name[i]; 412e9dbad6fSeschrock if (!valid_char(c)) 413e9dbad6fSeschrock return (B_FALSE); 414e9dbad6fSeschrock if (c == ':') 415e9dbad6fSeschrock foundsep = B_TRUE; 416e9dbad6fSeschrock } 417e9dbad6fSeschrock 418e9dbad6fSeschrock if (!foundsep) 419e9dbad6fSeschrock return (B_FALSE); 420e9dbad6fSeschrock 421e9dbad6fSeschrock return (B_TRUE); 422e9dbad6fSeschrock } 423e9dbad6fSeschrock 424e9dbad6fSeschrock /* 42514843421SMatthew Ahrens * Returns true if this is a valid userspace-type property (one with a '@'). 42614843421SMatthew Ahrens * Note that after the @, any character is valid (eg, another @, for SID 42714843421SMatthew Ahrens * user@domain). 42814843421SMatthew Ahrens */ 42914843421SMatthew Ahrens boolean_t 43014843421SMatthew Ahrens zfs_prop_userquota(const char *name) 43114843421SMatthew Ahrens { 43214843421SMatthew Ahrens zfs_userquota_prop_t prop; 43314843421SMatthew Ahrens 43414843421SMatthew Ahrens for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 43514843421SMatthew Ahrens if (strncmp(name, zfs_userquota_prop_prefixes[prop], 43614843421SMatthew Ahrens strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 43714843421SMatthew Ahrens return (B_TRUE); 43814843421SMatthew Ahrens } 43914843421SMatthew Ahrens } 44014843421SMatthew Ahrens 44114843421SMatthew Ahrens return (B_FALSE); 44214843421SMatthew Ahrens } 44314843421SMatthew Ahrens 44414843421SMatthew Ahrens /* 445990b4856Slling * Tables of index types, plus functions to convert between the user view 446990b4856Slling * (strings) and internal representation (uint64_t). 447fa9e4066Sahrens */ 448990b4856Slling int 449990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 450fa9e4066Sahrens { 451990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 452990b4856Slling } 453990b4856Slling 454990b4856Slling int 455990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 456990b4856Slling { 457990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 458990b4856Slling } 459990b4856Slling 460b24ab676SJeff Bonwick uint64_t 461b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 462b24ab676SJeff Bonwick { 463b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 464b24ab676SJeff Bonwick } 465b24ab676SJeff Bonwick 466990b4856Slling /* 467990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 468990b4856Slling */ 4694853e976Sgw25295 boolean_t 470990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 471990b4856Slling { 472990b4856Slling return (zprop_valid_for_type(prop, types)); 473990b4856Slling } 474990b4856Slling 475990b4856Slling zprop_type_t 476990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 477990b4856Slling { 478990b4856Slling return (zfs_prop_table[prop].pd_proptype); 479990b4856Slling } 480990b4856Slling 481990b4856Slling /* 482990b4856Slling * Returns TRUE if the property is readonly. 483990b4856Slling */ 484990b4856Slling boolean_t 485990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 486990b4856Slling { 487da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 488da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 489da6c28aaSamw } 490da6c28aaSamw 491da6c28aaSamw /* 492da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 493da6c28aaSamw */ 494da6c28aaSamw boolean_t 495da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 496da6c28aaSamw { 497da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 498fa9e4066Sahrens } 499fa9e4066Sahrens 5003d7072f8Seschrock const char * 501990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 5023d7072f8Seschrock { 5033d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 5043d7072f8Seschrock } 5053d7072f8Seschrock 506fa9e4066Sahrens uint64_t 507fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 508fa9e4066Sahrens { 509fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 510fa9e4066Sahrens } 511fa9e4066Sahrens 512fa9e4066Sahrens /* 513b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 5143d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 515fa9e4066Sahrens */ 516fa9e4066Sahrens const char * 517fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 518fa9e4066Sahrens { 519fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 520fa9e4066Sahrens } 521fa9e4066Sahrens 522fa9e4066Sahrens /* 523fa9e4066Sahrens * Returns TRUE if the property is inheritable. 524fa9e4066Sahrens */ 525990b4856Slling boolean_t 526fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 527fa9e4066Sahrens { 528da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 529da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 530e9dbad6fSeschrock } 531e9dbad6fSeschrock 532acd76fe5Seschrock #ifndef _KERNEL 533acd76fe5Seschrock 534fa9e4066Sahrens /* 535fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 536b1b8ab34Slling * zfs property, or NULL if it cannot be set. 537fa9e4066Sahrens */ 538fa9e4066Sahrens const char * 539fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 540fa9e4066Sahrens { 541fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 542fa9e4066Sahrens } 543fa9e4066Sahrens 544fa9e4066Sahrens /* 545fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 546fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 547fa9e4066Sahrens * are stored numerically on disk. 548fa9e4066Sahrens */ 549fa9e4066Sahrens int 550fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 551fa9e4066Sahrens { 55291ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 55391ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 554fa9e4066Sahrens } 555fa9e4066Sahrens 556fa9e4066Sahrens /* 557fa9e4066Sahrens * Returns the column header for the given property. Used only in 558fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 559fa9e4066Sahrens */ 560fa9e4066Sahrens const char * 561fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 562fa9e4066Sahrens { 563fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 564fa9e4066Sahrens } 565fa9e4066Sahrens 566fa9e4066Sahrens /* 567e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 568e9dbad6fSeschrock * 'zfs list'. 569fa9e4066Sahrens */ 570e9dbad6fSeschrock boolean_t 571e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 572fa9e4066Sahrens { 573e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 574fa9e4066Sahrens } 575da6c28aaSamw 576fa9e4066Sahrens #endif 577