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 #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]; 47fa9e4066Sahrens 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 } 64fa9e4066Sahrens }; 65fa9e4066Sahrens 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 }, 99*b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 10091ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 101*b3d141f8Smarks { "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 147a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 148a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 149a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 150a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 151a227b7f4Shs24103 { NULL } 152a227b7f4Shs24103 }; 153a227b7f4Shs24103 15491ebeef5Sahrens /* inherit index properties */ 15591ebeef5Sahrens register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 156e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 15791ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 15891ebeef5Sahrens checksum_table); 15991ebeef5Sahrens register_index(ZFS_PROP_COMPRESSION, "compression", 160e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 161e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 16291ebeef5Sahrens "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table); 16391ebeef5Sahrens register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 164e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 165e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 16691ebeef5Sahrens register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 167e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 168990b4856Slling "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 169*b3d141f8Smarks register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 170e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 171*b3d141f8Smarks "discard | noallow | restricted | passthrough", 172*b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 17391ebeef5Sahrens register_index(ZFS_PROP_COPIES, "copies", 1, 174e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 17591ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 176e45ce728Sahrens 177e45ce728Sahrens /* inherit index (boolean) properties */ 178e45ce728Sahrens register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 179e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 180e45ce728Sahrens register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 181e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 182e45ce728Sahrens boolean_table); 183e45ce728Sahrens register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 184e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 185e45ce728Sahrens boolean_table); 186e45ce728Sahrens register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 187e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 188e45ce728Sahrens boolean_table); 189e45ce728Sahrens register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 190e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 191e45ce728Sahrens boolean_table); 192e45ce728Sahrens register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 193e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 194e45ce728Sahrens register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 195e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 196e45ce728Sahrens boolean_table); 197da6c28aaSamw register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 198da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 199da6c28aaSamw boolean_table); 200da6c28aaSamw register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 201da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 202da6c28aaSamw boolean_table); 203e45ce728Sahrens 204e45ce728Sahrens /* default index properties */ 205e45ce728Sahrens register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 20691ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 207da6c28aaSamw "1 | 2 | 3 | current", "VERSION", version_table); 208a227b7f4Shs24103 register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 209a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 210a227b7f4Shs24103 "CANMOUNT", canmount_table); 211e45ce728Sahrens 212e45ce728Sahrens /* readonly index (boolean) properties */ 213e45ce728Sahrens register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 214990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 215e45ce728Sahrens 216da6c28aaSamw /* set once index properties */ 217de8267e0Stimh register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 218da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 219da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 220da6c28aaSamw normalize_table); 221da6c28aaSamw register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 222da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 223da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 224da6c28aaSamw 225da6c28aaSamw /* set once index (boolean) properties */ 226da6c28aaSamw register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 227da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 228da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 229da6c28aaSamw 23091ebeef5Sahrens /* string properties */ 23191ebeef5Sahrens register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 23291ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 23391ebeef5Sahrens register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 23491ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 23591ebeef5Sahrens register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 23691ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 23791ebeef5Sahrens register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT, 238990b4856Slling ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI"); 23991ebeef5Sahrens register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 240990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 241da6c28aaSamw register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 242da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 24391ebeef5Sahrens 24491ebeef5Sahrens /* readonly number properties */ 24591ebeef5Sahrens register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 246990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 24791ebeef5Sahrens register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 248990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 24991ebeef5Sahrens register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 250990b4856Slling ZFS_TYPE_DATASET, "<size>", "REFER"); 25191ebeef5Sahrens register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 252990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 25391ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 25491ebeef5Sahrens register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192, 255da6c28aaSamw PROP_ONETIME, 256da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 25791ebeef5Sahrens 25891ebeef5Sahrens /* default number properties */ 25991ebeef5Sahrens register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 26091ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 26191ebeef5Sahrens register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 26291ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 26391ebeef5Sahrens register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 26491ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 265a9799022Sck153898 register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 266a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 267a9799022Sck153898 register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 268a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 269a9799022Sck153898 "<size> | none", "REFRESERV"); 27091ebeef5Sahrens 27191ebeef5Sahrens /* inherit number properties */ 27291ebeef5Sahrens register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 27391ebeef5Sahrens PROP_INHERIT, 27491ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 27591ebeef5Sahrens 27691ebeef5Sahrens /* hidden properties */ 27791ebeef5Sahrens register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 278990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, NULL); 27991ebeef5Sahrens register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 28091ebeef5Sahrens PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL); 28191ebeef5Sahrens register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 282990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 28391ebeef5Sahrens register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 28491ebeef5Sahrens PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 28591ebeef5Sahrens 28691ebeef5Sahrens /* oddball properties */ 28791ebeef5Sahrens register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 288990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 28991ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 29091ebeef5Sahrens } 29191ebeef5Sahrens 292b1b8ab34Slling boolean_t 293990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 294b1b8ab34Slling { 295990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 296990b4856Slling return (pd->pd_attr != PROP_READONLY); 297b1b8ab34Slling } 298b1b8ab34Slling 299b1b8ab34Slling /* 300b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 301fa9e4066Sahrens */ 302fa9e4066Sahrens zfs_prop_t 303fa9e4066Sahrens zfs_name_to_prop(const char *propname) 304fa9e4066Sahrens { 305990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 306b1b8ab34Slling } 307fa9e4066Sahrens 308ecd6cf80Smarks 309fa9e4066Sahrens /* 310e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 311e9dbad6fSeschrock * a few useful punctuation characters. 312e9dbad6fSeschrock */ 313e9dbad6fSeschrock static int 314e9dbad6fSeschrock valid_char(char c) 315e9dbad6fSeschrock { 316e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 317e9dbad6fSeschrock (c >= '0' && c <= '9') || 318e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 319e9dbad6fSeschrock } 320e9dbad6fSeschrock 321e9dbad6fSeschrock /* 322e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 323e9dbad6fSeschrock */ 324e9dbad6fSeschrock boolean_t 325e9dbad6fSeschrock zfs_prop_user(const char *name) 326e9dbad6fSeschrock { 327e9dbad6fSeschrock int i; 328e9dbad6fSeschrock char c; 329e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 330e9dbad6fSeschrock 331e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 332e9dbad6fSeschrock c = name[i]; 333e9dbad6fSeschrock if (!valid_char(c)) 334e9dbad6fSeschrock return (B_FALSE); 335e9dbad6fSeschrock if (c == ':') 336e9dbad6fSeschrock foundsep = B_TRUE; 337e9dbad6fSeschrock } 338e9dbad6fSeschrock 339e9dbad6fSeschrock if (!foundsep) 340e9dbad6fSeschrock return (B_FALSE); 341e9dbad6fSeschrock 342e9dbad6fSeschrock return (B_TRUE); 343e9dbad6fSeschrock } 344e9dbad6fSeschrock 345e9dbad6fSeschrock /* 346990b4856Slling * Tables of index types, plus functions to convert between the user view 347990b4856Slling * (strings) and internal representation (uint64_t). 348fa9e4066Sahrens */ 349990b4856Slling int 350990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 351fa9e4066Sahrens { 352990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 353990b4856Slling } 354990b4856Slling 355990b4856Slling int 356990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 357990b4856Slling { 358990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 359990b4856Slling } 360990b4856Slling 361990b4856Slling /* 362990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 363990b4856Slling */ 364990b4856Slling int 365990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 366990b4856Slling { 367990b4856Slling return (zprop_valid_for_type(prop, types)); 368990b4856Slling } 369990b4856Slling 370990b4856Slling zprop_type_t 371990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 372990b4856Slling { 373990b4856Slling return (zfs_prop_table[prop].pd_proptype); 374990b4856Slling } 375990b4856Slling 376990b4856Slling /* 377990b4856Slling * Returns TRUE if the property is readonly. 378990b4856Slling */ 379990b4856Slling boolean_t 380990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 381990b4856Slling { 382da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 383da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 384da6c28aaSamw } 385da6c28aaSamw 386da6c28aaSamw /* 387da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 388da6c28aaSamw */ 389da6c28aaSamw boolean_t 390da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 391da6c28aaSamw { 392da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 393fa9e4066Sahrens } 394fa9e4066Sahrens 3953d7072f8Seschrock const char * 396990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 3973d7072f8Seschrock { 3983d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 3993d7072f8Seschrock } 4003d7072f8Seschrock 401fa9e4066Sahrens uint64_t 402fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 403fa9e4066Sahrens { 404fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 405fa9e4066Sahrens } 406fa9e4066Sahrens 407fa9e4066Sahrens /* 408b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 4093d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 410fa9e4066Sahrens */ 411fa9e4066Sahrens const char * 412fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 413fa9e4066Sahrens { 414fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 415fa9e4066Sahrens } 416fa9e4066Sahrens 417fa9e4066Sahrens /* 418fa9e4066Sahrens * Returns TRUE if the property is inheritable. 419fa9e4066Sahrens */ 420990b4856Slling boolean_t 421fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 422fa9e4066Sahrens { 423da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 424da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 425e9dbad6fSeschrock } 426e9dbad6fSeschrock 427acd76fe5Seschrock #ifndef _KERNEL 428acd76fe5Seschrock 429fa9e4066Sahrens /* 430fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 431b1b8ab34Slling * zfs property, or NULL if it cannot be set. 432fa9e4066Sahrens */ 433fa9e4066Sahrens const char * 434fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 435fa9e4066Sahrens { 436fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 437fa9e4066Sahrens } 438fa9e4066Sahrens 439fa9e4066Sahrens /* 440fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 441fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 442fa9e4066Sahrens * are stored numerically on disk. 443fa9e4066Sahrens */ 444fa9e4066Sahrens int 445fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 446fa9e4066Sahrens { 44791ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 44891ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 449fa9e4066Sahrens } 450fa9e4066Sahrens 451fa9e4066Sahrens /* 452fa9e4066Sahrens * Returns the column header for the given property. Used only in 453fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 454fa9e4066Sahrens */ 455fa9e4066Sahrens const char * 456fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 457fa9e4066Sahrens { 458fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 459fa9e4066Sahrens } 460fa9e4066Sahrens 461fa9e4066Sahrens /* 462e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 463e9dbad6fSeschrock * 'zfs list'. 464fa9e4066Sahrens */ 465e9dbad6fSeschrock boolean_t 466e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 467fa9e4066Sahrens { 468e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 469fa9e4066Sahrens } 470da6c28aaSamw 471fa9e4066Sahrens #endif 472