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 /* 22a227b7f4Shs24103 * Copyright 2008 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 46990b4856Slling zprop_desc_t * 47990b4856Slling zfs_prop_get_table(void) 4891ebeef5Sahrens { 49990b4856Slling return (zfs_prop_table); 5091ebeef5Sahrens } 5191ebeef5Sahrens 5291ebeef5Sahrens void 5391ebeef5Sahrens zfs_prop_init(void) 5491ebeef5Sahrens { 55990b4856Slling static zprop_index_t checksum_table[] = { 5691ebeef5Sahrens { "on", ZIO_CHECKSUM_ON }, 5791ebeef5Sahrens { "off", ZIO_CHECKSUM_OFF }, 5891ebeef5Sahrens { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 5991ebeef5Sahrens { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 6091ebeef5Sahrens { "sha256", ZIO_CHECKSUM_SHA256 }, 6191ebeef5Sahrens { NULL } 62fa9e4066Sahrens }; 63fa9e4066Sahrens 64990b4856Slling static zprop_index_t compress_table[] = { 6591ebeef5Sahrens { "on", ZIO_COMPRESS_ON }, 6691ebeef5Sahrens { "off", ZIO_COMPRESS_OFF }, 6791ebeef5Sahrens { "lzjb", ZIO_COMPRESS_LZJB }, 6891ebeef5Sahrens { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 6991ebeef5Sahrens { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 7091ebeef5Sahrens { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 7191ebeef5Sahrens { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 7291ebeef5Sahrens { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 7391ebeef5Sahrens { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 7491ebeef5Sahrens { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 7591ebeef5Sahrens { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 7691ebeef5Sahrens { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 7791ebeef5Sahrens { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 7891ebeef5Sahrens { NULL } 7991ebeef5Sahrens }; 8091ebeef5Sahrens 81990b4856Slling static zprop_index_t snapdir_table[] = { 8291ebeef5Sahrens { "hidden", ZFS_SNAPDIR_HIDDEN }, 8391ebeef5Sahrens { "visible", ZFS_SNAPDIR_VISIBLE }, 8491ebeef5Sahrens { NULL } 8591ebeef5Sahrens }; 8691ebeef5Sahrens 87990b4856Slling static zprop_index_t acl_mode_table[] = { 8891ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 8991ebeef5Sahrens { "groupmask", ZFS_ACL_GROUPMASK }, 9091ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 9191ebeef5Sahrens { NULL } 9291ebeef5Sahrens }; 9391ebeef5Sahrens 94990b4856Slling static zprop_index_t acl_inherit_table[] = { 9591ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 9691ebeef5Sahrens { "noallow", ZFS_ACL_NOALLOW }, 97b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 9891ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 99b3d141f8Smarks { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 100*d0f3f37eSMark Shellenbaum { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 10191ebeef5Sahrens { NULL } 10291ebeef5Sahrens }; 10391ebeef5Sahrens 104da6c28aaSamw static zprop_index_t case_table[] = { 105da6c28aaSamw { "sensitive", ZFS_CASE_SENSITIVE }, 106da6c28aaSamw { "insensitive", ZFS_CASE_INSENSITIVE }, 107da6c28aaSamw { "mixed", ZFS_CASE_MIXED }, 108da6c28aaSamw { NULL } 109da6c28aaSamw }; 110da6c28aaSamw 111990b4856Slling static zprop_index_t copies_table[] = { 11291ebeef5Sahrens { "1", 1 }, 11391ebeef5Sahrens { "2", 2 }, 11491ebeef5Sahrens { "3", 3 }, 11591ebeef5Sahrens { NULL } 11691ebeef5Sahrens }; 11791ebeef5Sahrens 118de8267e0Stimh /* 119de8267e0Stimh * Use the unique flags we have to send to u8_strcmp() and/or 120de8267e0Stimh * u8_textprep() to represent the various normalization property 121de8267e0Stimh * values. 122de8267e0Stimh */ 123da6c28aaSamw static zprop_index_t normalize_table[] = { 124de8267e0Stimh { "none", 0 }, 125de8267e0Stimh { "formD", U8_TEXTPREP_NFD }, 126de8267e0Stimh { "formKC", U8_TEXTPREP_NFKC }, 127de8267e0Stimh { "formC", U8_TEXTPREP_NFC }, 128de8267e0Stimh { "formKD", U8_TEXTPREP_NFKD }, 129da6c28aaSamw { NULL } 130da6c28aaSamw }; 131da6c28aaSamw 132990b4856Slling static zprop_index_t version_table[] = { 13391ebeef5Sahrens { "1", 1 }, 13491ebeef5Sahrens { "2", 2 }, 135da6c28aaSamw { "3", 3 }, 13691ebeef5Sahrens { "current", ZPL_VERSION }, 13791ebeef5Sahrens { NULL } 13891ebeef5Sahrens }; 13991ebeef5Sahrens 140990b4856Slling static zprop_index_t boolean_table[] = { 141e45ce728Sahrens { "off", 0 }, 142e45ce728Sahrens { "on", 1 }, 143e45ce728Sahrens { NULL } 144e45ce728Sahrens }; 145e45ce728Sahrens 146a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 147a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 148a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 149a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 150a227b7f4Shs24103 { NULL } 151a227b7f4Shs24103 }; 152a227b7f4Shs24103 1533baa08fcSek110237 static zprop_index_t cache_table[] = { 1543baa08fcSek110237 { "none", ZFS_CACHE_NONE }, 1553baa08fcSek110237 { "metadata", ZFS_CACHE_METADATA }, 1563baa08fcSek110237 { "all", ZFS_CACHE_ALL }, 1573baa08fcSek110237 { NULL } 1583baa08fcSek110237 }; 1593baa08fcSek110237 16091ebeef5Sahrens /* inherit index properties */ 16191ebeef5Sahrens register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 162e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 16391ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 16491ebeef5Sahrens checksum_table); 16591ebeef5Sahrens register_index(ZFS_PROP_COMPRESSION, "compression", 166e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 167e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 16891ebeef5Sahrens "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table); 16991ebeef5Sahrens register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 170e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 171e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 17291ebeef5Sahrens register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 173e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 174990b4856Slling "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 175b3d141f8Smarks register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 176e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 177*d0f3f37eSMark Shellenbaum "discard | noallow | restricted | passthrough | passthrough-x", 178b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 17991ebeef5Sahrens register_index(ZFS_PROP_COPIES, "copies", 1, 180e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 18191ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 1823baa08fcSek110237 register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 1833baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 1843baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 1853baa08fcSek110237 "all | none | metadata", "PRIMARYCACHE", cache_table); 1863baa08fcSek110237 register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 1873baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 1883baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 1893baa08fcSek110237 "all | none | metadata", "SECONDARYCACHE", cache_table); 190e45ce728Sahrens 191e45ce728Sahrens /* inherit index (boolean) properties */ 192e45ce728Sahrens register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 193e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 194e45ce728Sahrens register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 195e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 196e45ce728Sahrens boolean_table); 197e45ce728Sahrens register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 198e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 199e45ce728Sahrens boolean_table); 200e45ce728Sahrens register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 201e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 202e45ce728Sahrens boolean_table); 203e45ce728Sahrens register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 204e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 205e45ce728Sahrens boolean_table); 206e45ce728Sahrens register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 207e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 208e45ce728Sahrens register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 209e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 210e45ce728Sahrens boolean_table); 211da6c28aaSamw register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 212da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 213da6c28aaSamw boolean_table); 214da6c28aaSamw register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 215da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 216da6c28aaSamw boolean_table); 217e45ce728Sahrens 218e45ce728Sahrens /* default index properties */ 219e45ce728Sahrens register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 22091ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 221da6c28aaSamw "1 | 2 | 3 | current", "VERSION", version_table); 222a227b7f4Shs24103 register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 223a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 224a227b7f4Shs24103 "CANMOUNT", canmount_table); 225e45ce728Sahrens 226e45ce728Sahrens /* readonly index (boolean) properties */ 227e45ce728Sahrens register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 228990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 229e45ce728Sahrens 230da6c28aaSamw /* set once index properties */ 231de8267e0Stimh register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 232da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 233da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 234da6c28aaSamw normalize_table); 235da6c28aaSamw register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 236da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 237da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 238da6c28aaSamw 239da6c28aaSamw /* set once index (boolean) properties */ 240da6c28aaSamw register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 241da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 242da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 243da6c28aaSamw 24491ebeef5Sahrens /* string properties */ 24591ebeef5Sahrens register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 24691ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 24791ebeef5Sahrens register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 24891ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 24991ebeef5Sahrens register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 25091ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 25191ebeef5Sahrens register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT, 252990b4856Slling ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI"); 25391ebeef5Sahrens register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 254990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 255da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 256da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 25791ebeef5Sahrens 25891ebeef5Sahrens /* readonly number properties */ 25991ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 260990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 26191ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 262990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 26391ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 264990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 26591ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 266990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 26791ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 26891ebeef5Sahrens register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192, 269da6c28aaSamw PROP_ONETIME, 270da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 27174e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY, 27274e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP"); 27374e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY, 27474e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS"); 27574e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY, 27674e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD"); 27774e7dc98SMatthew Ahrens register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 27874e7dc98SMatthew Ahrens PROP_READONLY, 27974e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 28091ebeef5Sahrens 28191ebeef5Sahrens /* default number properties */ 28291ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 28391ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 28491ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 28591ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 28691ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 28791ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 288a9799022Sck153898 register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 289a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 290a9799022Sck153898 register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 291a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 292a9799022Sck153898 "<size> | none", "REFRESERV"); 29391ebeef5Sahrens 29491ebeef5Sahrens /* inherit number properties */ 29591ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 29691ebeef5Sahrens PROP_INHERIT, 29791ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 29891ebeef5Sahrens 29991ebeef5Sahrens /* hidden properties */ 30091ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 301990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, NULL); 30291ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 30391ebeef5Sahrens PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL); 30491ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 305990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 30691ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 30791ebeef5Sahrens PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 308c5904d13Seschrock register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 309c5904d13Seschrock ZFS_TYPE_DATASET, "GUID"); 31091ebeef5Sahrens 31191ebeef5Sahrens /* oddball properties */ 31291ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 313990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 31491ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 31591ebeef5Sahrens } 31691ebeef5Sahrens 317b1b8ab34Slling boolean_t 318990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 319b1b8ab34Slling { 320990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 321990b4856Slling return (pd->pd_attr != PROP_READONLY); 322b1b8ab34Slling } 323b1b8ab34Slling 324b1b8ab34Slling /* 325b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 326fa9e4066Sahrens */ 327fa9e4066Sahrens zfs_prop_t 328fa9e4066Sahrens zfs_name_to_prop(const char *propname) 329fa9e4066Sahrens { 330990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 331b1b8ab34Slling } 332fa9e4066Sahrens 333ecd6cf80Smarks 334fa9e4066Sahrens /* 335e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 336e9dbad6fSeschrock * a few useful punctuation characters. 337e9dbad6fSeschrock */ 338e9dbad6fSeschrock static int 339e9dbad6fSeschrock valid_char(char c) 340e9dbad6fSeschrock { 341e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 342e9dbad6fSeschrock (c >= '0' && c <= '9') || 343e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 344e9dbad6fSeschrock } 345e9dbad6fSeschrock 346e9dbad6fSeschrock /* 347e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 348e9dbad6fSeschrock */ 349e9dbad6fSeschrock boolean_t 350e9dbad6fSeschrock zfs_prop_user(const char *name) 351e9dbad6fSeschrock { 352e9dbad6fSeschrock int i; 353e9dbad6fSeschrock char c; 354e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 355e9dbad6fSeschrock 356e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 357e9dbad6fSeschrock c = name[i]; 358e9dbad6fSeschrock if (!valid_char(c)) 359e9dbad6fSeschrock return (B_FALSE); 360e9dbad6fSeschrock if (c == ':') 361e9dbad6fSeschrock foundsep = B_TRUE; 362e9dbad6fSeschrock } 363e9dbad6fSeschrock 364e9dbad6fSeschrock if (!foundsep) 365e9dbad6fSeschrock return (B_FALSE); 366e9dbad6fSeschrock 367e9dbad6fSeschrock return (B_TRUE); 368e9dbad6fSeschrock } 369e9dbad6fSeschrock 370e9dbad6fSeschrock /* 371990b4856Slling * Tables of index types, plus functions to convert between the user view 372990b4856Slling * (strings) and internal representation (uint64_t). 373fa9e4066Sahrens */ 374990b4856Slling int 375990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 376fa9e4066Sahrens { 377990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 378990b4856Slling } 379990b4856Slling 380990b4856Slling int 381990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 382990b4856Slling { 383990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 384990b4856Slling } 385990b4856Slling 386990b4856Slling /* 387990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 388990b4856Slling */ 3894853e976Sgw25295 boolean_t 390990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 391990b4856Slling { 392990b4856Slling return (zprop_valid_for_type(prop, types)); 393990b4856Slling } 394990b4856Slling 395990b4856Slling zprop_type_t 396990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 397990b4856Slling { 398990b4856Slling return (zfs_prop_table[prop].pd_proptype); 399990b4856Slling } 400990b4856Slling 401990b4856Slling /* 402990b4856Slling * Returns TRUE if the property is readonly. 403990b4856Slling */ 404990b4856Slling boolean_t 405990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 406990b4856Slling { 407da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 408da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 409da6c28aaSamw } 410da6c28aaSamw 411da6c28aaSamw /* 412da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 413da6c28aaSamw */ 414da6c28aaSamw boolean_t 415da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 416da6c28aaSamw { 417da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 418fa9e4066Sahrens } 419fa9e4066Sahrens 4203d7072f8Seschrock const char * 421990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 4223d7072f8Seschrock { 4233d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 4243d7072f8Seschrock } 4253d7072f8Seschrock 426fa9e4066Sahrens uint64_t 427fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 428fa9e4066Sahrens { 429fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 430fa9e4066Sahrens } 431fa9e4066Sahrens 432fa9e4066Sahrens /* 433b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 4343d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 435fa9e4066Sahrens */ 436fa9e4066Sahrens const char * 437fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 438fa9e4066Sahrens { 439fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 440fa9e4066Sahrens } 441fa9e4066Sahrens 442fa9e4066Sahrens /* 443fa9e4066Sahrens * Returns TRUE if the property is inheritable. 444fa9e4066Sahrens */ 445990b4856Slling boolean_t 446fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 447fa9e4066Sahrens { 448da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 449da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 450e9dbad6fSeschrock } 451e9dbad6fSeschrock 452acd76fe5Seschrock #ifndef _KERNEL 453acd76fe5Seschrock 454fa9e4066Sahrens /* 455fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 456b1b8ab34Slling * zfs property, or NULL if it cannot be set. 457fa9e4066Sahrens */ 458fa9e4066Sahrens const char * 459fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 460fa9e4066Sahrens { 461fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 462fa9e4066Sahrens } 463fa9e4066Sahrens 464fa9e4066Sahrens /* 465fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 466fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 467fa9e4066Sahrens * are stored numerically on disk. 468fa9e4066Sahrens */ 469fa9e4066Sahrens int 470fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 471fa9e4066Sahrens { 47291ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 47391ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 474fa9e4066Sahrens } 475fa9e4066Sahrens 476fa9e4066Sahrens /* 477fa9e4066Sahrens * Returns the column header for the given property. Used only in 478fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 479fa9e4066Sahrens */ 480fa9e4066Sahrens const char * 481fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 482fa9e4066Sahrens { 483fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 484fa9e4066Sahrens } 485fa9e4066Sahrens 486fa9e4066Sahrens /* 487e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 488e9dbad6fSeschrock * 'zfs list'. 489fa9e4066Sahrens */ 490e9dbad6fSeschrock boolean_t 491e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 492fa9e4066Sahrens { 493e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 494fa9e4066Sahrens } 495da6c28aaSamw 496fa9e4066Sahrens #endif 497