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 /* 22a227b7f4Shs * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #pragma ident "%Z%%M% %I% %E% SMI" 27fa9e4066Sahrens 28fa9e4066Sahrens #include <sys/zio.h> 29fa9e4066Sahrens #include <sys/spa.h> 30de8267e0Stimh #include <sys/u8_textprep.h> 31fa9e4066Sahrens #include <sys/zfs_acl.h> 32fa9e4066Sahrens #include <sys/zfs_ioctl.h> 33e7437265Sahrens #include <sys/zfs_znode.h> 34fa9e4066Sahrens 35fa9e4066Sahrens #include "zfs_prop.h" 36ecd6cf80Smarks #include "zfs_deleg.h" 37fa9e4066Sahrens 38fa9e4066Sahrens #if defined(_KERNEL) 39fa9e4066Sahrens #include <sys/systm.h> 40fa9e4066Sahrens #else 41fa9e4066Sahrens #include <stdlib.h> 42fa9e4066Sahrens #include <string.h> 43fa9e4066Sahrens #include <ctype.h> 44fa9e4066Sahrens #endif 45fa9e4066Sahrens 46990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 4791ebeef5Sahrens 48990b4856Slling zprop_desc_t * 49990b4856Slling zfs_prop_get_table(void) 5091ebeef5Sahrens { 51990b4856Slling return (zfs_prop_table); 5291ebeef5Sahrens } 5391ebeef5Sahrens 5491ebeef5Sahrens void 5591ebeef5Sahrens zfs_prop_init(void) 5691ebeef5Sahrens { 57990b4856Slling static zprop_index_t checksum_table[] = { 5891ebeef5Sahrens { "on", ZIO_CHECKSUM_ON }, 5991ebeef5Sahrens { "off", ZIO_CHECKSUM_OFF }, 6091ebeef5Sahrens { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 6191ebeef5Sahrens { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 6291ebeef5Sahrens { "sha256", ZIO_CHECKSUM_SHA256 }, 6391ebeef5Sahrens { NULL } 6491ebeef5Sahrens }; 6591ebeef5Sahrens 66990b4856Slling static zprop_index_t compress_table[] = { 6791ebeef5Sahrens { "on", ZIO_COMPRESS_ON }, 6891ebeef5Sahrens { "off", ZIO_COMPRESS_OFF }, 6991ebeef5Sahrens { "lzjb", ZIO_COMPRESS_LZJB }, 7091ebeef5Sahrens { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 7191ebeef5Sahrens { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 7291ebeef5Sahrens { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 7391ebeef5Sahrens { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 7491ebeef5Sahrens { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 7591ebeef5Sahrens { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 7691ebeef5Sahrens { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 7791ebeef5Sahrens { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 7891ebeef5Sahrens { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 7991ebeef5Sahrens { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 8091ebeef5Sahrens { NULL } 8191ebeef5Sahrens }; 8291ebeef5Sahrens 83990b4856Slling static zprop_index_t snapdir_table[] = { 8491ebeef5Sahrens { "hidden", ZFS_SNAPDIR_HIDDEN }, 8591ebeef5Sahrens { "visible", ZFS_SNAPDIR_VISIBLE }, 8691ebeef5Sahrens { NULL } 8791ebeef5Sahrens }; 8891ebeef5Sahrens 89990b4856Slling static zprop_index_t acl_mode_table[] = { 9091ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 9191ebeef5Sahrens { "groupmask", ZFS_ACL_GROUPMASK }, 9291ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 9391ebeef5Sahrens { NULL } 9491ebeef5Sahrens }; 9591ebeef5Sahrens 96990b4856Slling static zprop_index_t acl_inherit_table[] = { 9791ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 9891ebeef5Sahrens { "noallow", ZFS_ACL_NOALLOW }, 99b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 10091ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 101b3d141f8Smarks { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 10291ebeef5Sahrens { NULL } 10391ebeef5Sahrens }; 10491ebeef5Sahrens 105da6c28aaSamw static zprop_index_t case_table[] = { 106da6c28aaSamw { "sensitive", ZFS_CASE_SENSITIVE }, 107da6c28aaSamw { "insensitive", ZFS_CASE_INSENSITIVE }, 108da6c28aaSamw { "mixed", ZFS_CASE_MIXED }, 109da6c28aaSamw { NULL } 110da6c28aaSamw }; 111da6c28aaSamw 112990b4856Slling static zprop_index_t copies_table[] = { 11391ebeef5Sahrens { "1", 1 }, 11491ebeef5Sahrens { "2", 2 }, 11591ebeef5Sahrens { "3", 3 }, 11691ebeef5Sahrens { NULL } 11791ebeef5Sahrens }; 11891ebeef5Sahrens 119de8267e0Stimh /* 120de8267e0Stimh * Use the unique flags we have to send to u8_strcmp() and/or 121de8267e0Stimh * u8_textprep() to represent the various normalization property 122de8267e0Stimh * values. 123de8267e0Stimh */ 124da6c28aaSamw static zprop_index_t normalize_table[] = { 125de8267e0Stimh { "none", 0 }, 126de8267e0Stimh { "formD", U8_TEXTPREP_NFD }, 127de8267e0Stimh { "formKC", U8_TEXTPREP_NFKC }, 128de8267e0Stimh { "formC", U8_TEXTPREP_NFC }, 129de8267e0Stimh { "formKD", U8_TEXTPREP_NFKD }, 130da6c28aaSamw { NULL } 131da6c28aaSamw }; 132da6c28aaSamw 133990b4856Slling static zprop_index_t version_table[] = { 13491ebeef5Sahrens { "1", 1 }, 13591ebeef5Sahrens { "2", 2 }, 136da6c28aaSamw { "3", 3 }, 13791ebeef5Sahrens { "current", ZPL_VERSION }, 13891ebeef5Sahrens { NULL } 13991ebeef5Sahrens }; 14091ebeef5Sahrens 141990b4856Slling static zprop_index_t boolean_table[] = { 142e45ce728Sahrens { "off", 0 }, 143e45ce728Sahrens { "on", 1 }, 144e45ce728Sahrens { NULL } 145e45ce728Sahrens }; 146e45ce728Sahrens 147a227b7f4Shs static zprop_index_t canmount_table[] = { 148a227b7f4Shs { "off", ZFS_CANMOUNT_OFF }, 149a227b7f4Shs { "on", ZFS_CANMOUNT_ON }, 150a227b7f4Shs { "noauto", ZFS_CANMOUNT_NOAUTO }, 151a227b7f4Shs { NULL } 152a227b7f4Shs }; 153a227b7f4Shs 154*3baa08fcSek static zprop_index_t cache_table[] = { 155*3baa08fcSek { "none", ZFS_CACHE_NONE }, 156*3baa08fcSek { "metadata", ZFS_CACHE_METADATA }, 157*3baa08fcSek { "all", ZFS_CACHE_ALL }, 158*3baa08fcSek { NULL } 159*3baa08fcSek }; 160*3baa08fcSek 16191ebeef5Sahrens /* inherit index properties */ 16291ebeef5Sahrens register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 163e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 16491ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 16591ebeef5Sahrens checksum_table); 16691ebeef5Sahrens register_index(ZFS_PROP_COMPRESSION, "compression", 167e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 168e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 16991ebeef5Sahrens "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table); 17091ebeef5Sahrens register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 171e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 172e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 17391ebeef5Sahrens register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 174e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 175990b4856Slling "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 176b3d141f8Smarks register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 177e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 178b3d141f8Smarks "discard | noallow | restricted | passthrough", 179b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 18091ebeef5Sahrens register_index(ZFS_PROP_COPIES, "copies", 1, 181e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 18291ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 183*3baa08fcSek register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 184*3baa08fcSek ZFS_CACHE_ALL, PROP_INHERIT, 185*3baa08fcSek ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 186*3baa08fcSek "all | none | metadata", "PRIMARYCACHE", cache_table); 187*3baa08fcSek register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 188*3baa08fcSek ZFS_CACHE_ALL, PROP_INHERIT, 189*3baa08fcSek ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 190*3baa08fcSek "all | none | metadata", "SECONDARYCACHE", cache_table); 191e45ce728Sahrens 192e45ce728Sahrens /* inherit index (boolean) properties */ 193e45ce728Sahrens register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 194e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 195e45ce728Sahrens register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 196e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 197e45ce728Sahrens boolean_table); 198e45ce728Sahrens register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 199e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 200e45ce728Sahrens boolean_table); 201e45ce728Sahrens register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 202e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 203e45ce728Sahrens boolean_table); 204e45ce728Sahrens register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 205e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 206e45ce728Sahrens boolean_table); 207e45ce728Sahrens register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 208e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 209e45ce728Sahrens register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 210e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 211e45ce728Sahrens boolean_table); 212da6c28aaSamw register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 213da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 214da6c28aaSamw boolean_table); 215da6c28aaSamw register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 216da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 217da6c28aaSamw boolean_table); 218e45ce728Sahrens 219e45ce728Sahrens /* default index properties */ 220e45ce728Sahrens register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 2217b55fa8eSck ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 222da6c28aaSamw "1 | 2 | 3 | current", "VERSION", version_table); 223a227b7f4Shs register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 224a227b7f4Shs PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 225a227b7f4Shs "CANMOUNT", canmount_table); 226e45ce728Sahrens 227e45ce728Sahrens /* readonly index (boolean) properties */ 228e45ce728Sahrens register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 229990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 230e45ce728Sahrens 231da6c28aaSamw /* set once index properties */ 232de8267e0Stimh register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 233da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 234da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 235da6c28aaSamw normalize_table); 236da6c28aaSamw register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 237da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 238da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 239da6c28aaSamw 240da6c28aaSamw /* set once index (boolean) properties */ 241da6c28aaSamw register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 242da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 243da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 244da6c28aaSamw 24591ebeef5Sahrens /* string properties */ 24691ebeef5Sahrens register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 24791ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 24891ebeef5Sahrens register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 24991ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 25091ebeef5Sahrens register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 25191ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 25291ebeef5Sahrens register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT, 253990b4856Slling ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI"); 25491ebeef5Sahrens register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 255990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 256da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 257da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 25891ebeef5Sahrens 25991ebeef5Sahrens /* readonly number properties */ 26091ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 261990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 26291ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 263990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 26491ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 265990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 26691ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 267990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 26891ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 26991ebeef5Sahrens register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192, 270da6c28aaSamw PROP_ONETIME, 271da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 27291ebeef5Sahrens 27391ebeef5Sahrens /* default number properties */ 27491ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 27591ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 27691ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 27791ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 27891ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 27991ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 280a9799022Sck register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 281a9799022Sck ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 282a9799022Sck register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 283a9799022Sck PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 284a9799022Sck "<size> | none", "REFRESERV"); 28591ebeef5Sahrens 28691ebeef5Sahrens /* inherit number properties */ 28791ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 28891ebeef5Sahrens PROP_INHERIT, 28991ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 29091ebeef5Sahrens 29191ebeef5Sahrens /* hidden properties */ 29291ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 293990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, NULL); 29491ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 29591ebeef5Sahrens PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL); 29691ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 297990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 29891ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 29991ebeef5Sahrens PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 300c5904d13Seschrock register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 301c5904d13Seschrock ZFS_TYPE_DATASET, "GUID"); 30291ebeef5Sahrens 30391ebeef5Sahrens /* oddball properties */ 30491ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 305990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 30691ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 30791ebeef5Sahrens } 30891ebeef5Sahrens 309b1b8ab34Slling boolean_t 310990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 311fa9e4066Sahrens { 312990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 313990b4856Slling return (pd->pd_attr != PROP_READONLY); 314fa9e4066Sahrens } 315fa9e4066Sahrens 316b1b8ab34Slling /* 317b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 318b1b8ab34Slling */ 319b1b8ab34Slling zfs_prop_t 320b1b8ab34Slling zfs_name_to_prop(const char *propname) 321b1b8ab34Slling { 322990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 323b1b8ab34Slling } 324b1b8ab34Slling 325ecd6cf80Smarks 326e9dbad6fSeschrock /* 327e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 328e9dbad6fSeschrock * a few useful punctuation characters. 329e9dbad6fSeschrock */ 330e9dbad6fSeschrock static int 331e9dbad6fSeschrock valid_char(char c) 332e9dbad6fSeschrock { 333e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 334e9dbad6fSeschrock (c >= '0' && c <= '9') || 335e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 336e9dbad6fSeschrock } 337e9dbad6fSeschrock 338e9dbad6fSeschrock /* 339e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 340e9dbad6fSeschrock */ 341e9dbad6fSeschrock boolean_t 342e9dbad6fSeschrock zfs_prop_user(const char *name) 343e9dbad6fSeschrock { 344e9dbad6fSeschrock int i; 345e9dbad6fSeschrock char c; 346e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 347e9dbad6fSeschrock 348e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 349e9dbad6fSeschrock c = name[i]; 350e9dbad6fSeschrock if (!valid_char(c)) 351e9dbad6fSeschrock return (B_FALSE); 352e9dbad6fSeschrock if (c == ':') 353e9dbad6fSeschrock foundsep = B_TRUE; 354e9dbad6fSeschrock } 355e9dbad6fSeschrock 356e9dbad6fSeschrock if (!foundsep) 357e9dbad6fSeschrock return (B_FALSE); 358e9dbad6fSeschrock 359e9dbad6fSeschrock return (B_TRUE); 360e9dbad6fSeschrock } 361e9dbad6fSeschrock 362fa9e4066Sahrens /* 363990b4856Slling * Tables of index types, plus functions to convert between the user view 364990b4856Slling * (strings) and internal representation (uint64_t). 365fa9e4066Sahrens */ 366990b4856Slling int 367990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 368fa9e4066Sahrens { 369990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 370fa9e4066Sahrens } 371fa9e4066Sahrens 372990b4856Slling int 373990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 3743d7072f8Seschrock { 375990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 3763d7072f8Seschrock } 3773d7072f8Seschrock 378990b4856Slling /* 379990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 380990b4856Slling */ 3814853e976Sgw boolean_t 382990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 383fa9e4066Sahrens { 384990b4856Slling return (zprop_valid_for_type(prop, types)); 385fa9e4066Sahrens } 386fa9e4066Sahrens 387990b4856Slling zprop_type_t 388990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 3893d7072f8Seschrock { 390990b4856Slling return (zfs_prop_table[prop].pd_proptype); 3913d7072f8Seschrock } 3923d7072f8Seschrock 393fa9e4066Sahrens /* 394fa9e4066Sahrens * Returns TRUE if the property is readonly. 395fa9e4066Sahrens */ 396990b4856Slling boolean_t 397fa9e4066Sahrens zfs_prop_readonly(zfs_prop_t prop) 398fa9e4066Sahrens { 399da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 400da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 401da6c28aaSamw } 402da6c28aaSamw 403da6c28aaSamw /* 404da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 405da6c28aaSamw */ 406da6c28aaSamw boolean_t 407da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 408da6c28aaSamw { 409da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 410fa9e4066Sahrens } 411fa9e4066Sahrens 412fa9e4066Sahrens const char * 413990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 414fa9e4066Sahrens { 415990b4856Slling return (zfs_prop_table[prop].pd_strdefault); 416990b4856Slling } 417990b4856Slling 418990b4856Slling uint64_t 419990b4856Slling zfs_prop_default_numeric(zfs_prop_t prop) 420990b4856Slling { 421990b4856Slling return (zfs_prop_table[prop].pd_numdefault); 422fa9e4066Sahrens } 423fa9e4066Sahrens 424b1b8ab34Slling /* 425990b4856Slling * Given a dataset property ID, returns the corresponding name. 426990b4856Slling * Assuming the zfs dataset property ID is valid. 427b1b8ab34Slling */ 428b1b8ab34Slling const char * 429990b4856Slling zfs_prop_to_name(zfs_prop_t prop) 430b1b8ab34Slling { 431b1b8ab34Slling return (zfs_prop_table[prop].pd_name); 432b1b8ab34Slling } 433b1b8ab34Slling 434fa9e4066Sahrens /* 435fa9e4066Sahrens * Returns TRUE if the property is inheritable. 436fa9e4066Sahrens */ 437990b4856Slling boolean_t 438fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 439fa9e4066Sahrens { 440da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 441da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 442e9dbad6fSeschrock } 443e9dbad6fSeschrock 444acd76fe5Seschrock #ifndef _KERNEL 445acd76fe5Seschrock 446fa9e4066Sahrens /* 447b1b8ab34Slling * Returns a string describing the set of acceptable values for the given 448b1b8ab34Slling * zfs property, or NULL if it cannot be set. 449fa9e4066Sahrens */ 450b1b8ab34Slling const char * 451b1b8ab34Slling zfs_prop_values(zfs_prop_t prop) 452fa9e4066Sahrens { 453fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 454fa9e4066Sahrens } 455fa9e4066Sahrens 456fa9e4066Sahrens /* 457fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 458fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 459fa9e4066Sahrens * are stored numerically on disk. 460fa9e4066Sahrens */ 461fa9e4066Sahrens int 462fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 463fa9e4066Sahrens { 46491ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 46591ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 466fa9e4066Sahrens } 467fa9e4066Sahrens 468fa9e4066Sahrens /* 469fa9e4066Sahrens * Returns the column header for the given property. Used only in 470fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 471fa9e4066Sahrens */ 472fa9e4066Sahrens const char * 473fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 474fa9e4066Sahrens { 475fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 476fa9e4066Sahrens } 477fa9e4066Sahrens 478fa9e4066Sahrens /* 479e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 480e9dbad6fSeschrock * 'zfs list'. 481fa9e4066Sahrens */ 482e9dbad6fSeschrock boolean_t 483e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 484fa9e4066Sahrens { 485e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 486fa9e4066Sahrens } 487da6c28aaSamw 488fa9e4066Sahrens #endif 489