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 /* 2227dd1e87SMark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23fa9e4066Sahrens */ 24fa9e4066Sahrens 25*55da60b9SMark J Musante /* Portions Copyright 2010 Robert Milkowski */ 26*55da60b9SMark J Musante 27fa9e4066Sahrens #include <sys/zio.h> 28fa9e4066Sahrens #include <sys/spa.h> 29de8267e0Stimh #include <sys/u8_textprep.h> 30fa9e4066Sahrens #include <sys/zfs_acl.h> 31fa9e4066Sahrens #include <sys/zfs_ioctl.h> 32e7437265Sahrens #include <sys/zfs_znode.h> 33fa9e4066Sahrens 34fa9e4066Sahrens #include "zfs_prop.h" 35ecd6cf80Smarks #include "zfs_deleg.h" 36fa9e4066Sahrens 37fa9e4066Sahrens #if defined(_KERNEL) 38fa9e4066Sahrens #include <sys/systm.h> 39fa9e4066Sahrens #else 40fa9e4066Sahrens #include <stdlib.h> 41fa9e4066Sahrens #include <string.h> 42fa9e4066Sahrens #include <ctype.h> 43fa9e4066Sahrens #endif 44fa9e4066Sahrens 45990b4856Slling static zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 46fa9e4066Sahrens 4714843421SMatthew Ahrens /* Note this is indexed by zfs_userquota_prop_t, keep the order the same */ 4814843421SMatthew Ahrens const char *zfs_userquota_prop_prefixes[] = { 4914843421SMatthew Ahrens "userused@", 5014843421SMatthew Ahrens "userquota@", 5114843421SMatthew Ahrens "groupused@", 5214843421SMatthew Ahrens "groupquota@" 5314843421SMatthew Ahrens }; 5414843421SMatthew Ahrens 55990b4856Slling zprop_desc_t * 56990b4856Slling zfs_prop_get_table(void) 5791ebeef5Sahrens { 58990b4856Slling return (zfs_prop_table); 5991ebeef5Sahrens } 6091ebeef5Sahrens 6191ebeef5Sahrens void 6291ebeef5Sahrens zfs_prop_init(void) 6391ebeef5Sahrens { 64990b4856Slling static zprop_index_t checksum_table[] = { 6591ebeef5Sahrens { "on", ZIO_CHECKSUM_ON }, 6691ebeef5Sahrens { "off", ZIO_CHECKSUM_OFF }, 6791ebeef5Sahrens { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 6891ebeef5Sahrens { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 6991ebeef5Sahrens { "sha256", ZIO_CHECKSUM_SHA256 }, 7091ebeef5Sahrens { NULL } 71fa9e4066Sahrens }; 72fa9e4066Sahrens 73b24ab676SJeff Bonwick static zprop_index_t dedup_table[] = { 74b24ab676SJeff Bonwick { "on", ZIO_CHECKSUM_ON }, 75b24ab676SJeff Bonwick { "off", ZIO_CHECKSUM_OFF }, 76b24ab676SJeff Bonwick { "verify", ZIO_CHECKSUM_ON | ZIO_CHECKSUM_VERIFY }, 77b24ab676SJeff Bonwick { "sha256", ZIO_CHECKSUM_SHA256 }, 78b24ab676SJeff Bonwick { "sha256,verify", 79b24ab676SJeff Bonwick ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY }, 80b24ab676SJeff Bonwick { NULL } 81b24ab676SJeff Bonwick }; 82b24ab676SJeff Bonwick 83990b4856Slling static zprop_index_t compress_table[] = { 8491ebeef5Sahrens { "on", ZIO_COMPRESS_ON }, 8591ebeef5Sahrens { "off", ZIO_COMPRESS_OFF }, 8691ebeef5Sahrens { "lzjb", ZIO_COMPRESS_LZJB }, 8791ebeef5Sahrens { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 8891ebeef5Sahrens { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 8991ebeef5Sahrens { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 9091ebeef5Sahrens { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 9191ebeef5Sahrens { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 9291ebeef5Sahrens { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 9391ebeef5Sahrens { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 9491ebeef5Sahrens { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 9591ebeef5Sahrens { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 9691ebeef5Sahrens { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 97b24ab676SJeff Bonwick { "zle", ZIO_COMPRESS_ZLE }, 9891ebeef5Sahrens { NULL } 9991ebeef5Sahrens }; 10091ebeef5Sahrens 101990b4856Slling static zprop_index_t snapdir_table[] = { 10291ebeef5Sahrens { "hidden", ZFS_SNAPDIR_HIDDEN }, 10391ebeef5Sahrens { "visible", ZFS_SNAPDIR_VISIBLE }, 10491ebeef5Sahrens { NULL } 10591ebeef5Sahrens }; 10691ebeef5Sahrens 107990b4856Slling static zprop_index_t acl_inherit_table[] = { 10891ebeef5Sahrens { "discard", ZFS_ACL_DISCARD }, 10991ebeef5Sahrens { "noallow", ZFS_ACL_NOALLOW }, 110b3d141f8Smarks { "restricted", ZFS_ACL_RESTRICTED }, 11191ebeef5Sahrens { "passthrough", ZFS_ACL_PASSTHROUGH }, 112b3d141f8Smarks { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 113d0f3f37eSMark Shellenbaum { "passthrough-x", ZFS_ACL_PASSTHROUGH_X }, 11491ebeef5Sahrens { NULL } 11591ebeef5Sahrens }; 11691ebeef5Sahrens 117da6c28aaSamw static zprop_index_t case_table[] = { 118da6c28aaSamw { "sensitive", ZFS_CASE_SENSITIVE }, 119da6c28aaSamw { "insensitive", ZFS_CASE_INSENSITIVE }, 120da6c28aaSamw { "mixed", ZFS_CASE_MIXED }, 121da6c28aaSamw { NULL } 122da6c28aaSamw }; 123da6c28aaSamw 124990b4856Slling static zprop_index_t copies_table[] = { 12591ebeef5Sahrens { "1", 1 }, 12691ebeef5Sahrens { "2", 2 }, 12791ebeef5Sahrens { "3", 3 }, 12891ebeef5Sahrens { NULL } 12991ebeef5Sahrens }; 13091ebeef5Sahrens 131de8267e0Stimh /* 132de8267e0Stimh * Use the unique flags we have to send to u8_strcmp() and/or 133de8267e0Stimh * u8_textprep() to represent the various normalization property 134de8267e0Stimh * values. 135de8267e0Stimh */ 136da6c28aaSamw static zprop_index_t normalize_table[] = { 137de8267e0Stimh { "none", 0 }, 138de8267e0Stimh { "formD", U8_TEXTPREP_NFD }, 139de8267e0Stimh { "formKC", U8_TEXTPREP_NFKC }, 140de8267e0Stimh { "formC", U8_TEXTPREP_NFC }, 141de8267e0Stimh { "formKD", U8_TEXTPREP_NFKD }, 142da6c28aaSamw { NULL } 143da6c28aaSamw }; 144da6c28aaSamw 145990b4856Slling static zprop_index_t version_table[] = { 14691ebeef5Sahrens { "1", 1 }, 14791ebeef5Sahrens { "2", 2 }, 148da6c28aaSamw { "3", 3 }, 14914843421SMatthew Ahrens { "4", 4 }, 1500a586ceaSMark Shellenbaum { "5", 5 }, 15191ebeef5Sahrens { "current", ZPL_VERSION }, 15291ebeef5Sahrens { NULL } 15391ebeef5Sahrens }; 15491ebeef5Sahrens 155990b4856Slling static zprop_index_t boolean_table[] = { 156e45ce728Sahrens { "off", 0 }, 157e45ce728Sahrens { "on", 1 }, 158e45ce728Sahrens { NULL } 159e45ce728Sahrens }; 160e45ce728Sahrens 161e09fa4daSNeil Perrin static zprop_index_t logbias_table[] = { 162e09fa4daSNeil Perrin { "latency", ZFS_LOGBIAS_LATENCY }, 163e09fa4daSNeil Perrin { "throughput", ZFS_LOGBIAS_THROUGHPUT }, 164e09fa4daSNeil Perrin { NULL } 165e09fa4daSNeil Perrin }; 166e09fa4daSNeil Perrin 167a227b7f4Shs24103 static zprop_index_t canmount_table[] = { 168a227b7f4Shs24103 { "off", ZFS_CANMOUNT_OFF }, 169a227b7f4Shs24103 { "on", ZFS_CANMOUNT_ON }, 170a227b7f4Shs24103 { "noauto", ZFS_CANMOUNT_NOAUTO }, 171a227b7f4Shs24103 { NULL } 172a227b7f4Shs24103 }; 173a227b7f4Shs24103 1743baa08fcSek110237 static zprop_index_t cache_table[] = { 1753baa08fcSek110237 { "none", ZFS_CACHE_NONE }, 1763baa08fcSek110237 { "metadata", ZFS_CACHE_METADATA }, 1773baa08fcSek110237 { "all", ZFS_CACHE_ALL }, 1783baa08fcSek110237 { NULL } 1793baa08fcSek110237 }; 1803baa08fcSek110237 181*55da60b9SMark J Musante static zprop_index_t sync_table[] = { 182*55da60b9SMark J Musante { "standard", ZFS_SYNC_STANDARD }, 183*55da60b9SMark J Musante { "always", ZFS_SYNC_ALWAYS }, 184*55da60b9SMark J Musante { "disabled", ZFS_SYNC_DISABLED }, 185*55da60b9SMark J Musante { NULL } 186*55da60b9SMark J Musante }; 187*55da60b9SMark J Musante 18891ebeef5Sahrens /* inherit index properties */ 189*55da60b9SMark J Musante zprop_register_index(ZFS_PROP_SYNC, "sync", ZFS_SYNC_STANDARD, 190*55da60b9SMark J Musante PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 191*55da60b9SMark J Musante "standard | always | disabled", "SYNC", 192*55da60b9SMark J Musante sync_table); 19383d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", 19483d7f9feSTom Erickson ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | 19583d7f9feSTom Erickson ZFS_TYPE_VOLUME, 19691ebeef5Sahrens "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 19791ebeef5Sahrens checksum_table); 19883d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, 199b24ab676SJeff Bonwick PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 200b1033ae2SMatthew Ahrens "on | off | verify | sha256[,verify]", "DEDUP", 201b24ab676SJeff Bonwick dedup_table); 20283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_COMPRESSION, "compression", 203e45ce728Sahrens ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 204e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 205b24ab676SJeff Bonwick "on | off | lzjb | gzip | gzip-[1-9] | zle", "COMPRESS", 206b24ab676SJeff Bonwick compress_table); 20783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 208e45ce728Sahrens PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 209e45ce728Sahrens "hidden | visible", "SNAPDIR", snapdir_table); 21083d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit", 21183d7f9feSTom Erickson ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 212d0f3f37eSMark Shellenbaum "discard | noallow | restricted | passthrough | passthrough-x", 213b3d141f8Smarks "ACLINHERIT", acl_inherit_table); 21483d7f9feSTom Erickson zprop_register_index(ZFS_PROP_COPIES, "copies", 1, PROP_INHERIT, 21583d7f9feSTom Erickson ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 21691ebeef5Sahrens "1 | 2 | 3", "COPIES", copies_table); 21783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 2183baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2193baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2203baa08fcSek110237 "all | none | metadata", "PRIMARYCACHE", cache_table); 22183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 2223baa08fcSek110237 ZFS_CACHE_ALL, PROP_INHERIT, 2233baa08fcSek110237 ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 2243baa08fcSek110237 "all | none | metadata", "SECONDARYCACHE", cache_table); 22583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_LOGBIAS, "logbias", ZFS_LOGBIAS_LATENCY, 226e09fa4daSNeil Perrin PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 227e09fa4daSNeil Perrin "latency | throughput", "LOGBIAS", logbias_table); 228e45ce728Sahrens 229e45ce728Sahrens /* inherit index (boolean) properties */ 23083d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 231e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 23283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 233e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 234e45ce728Sahrens boolean_table); 23583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 236e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 237e45ce728Sahrens boolean_table); 23883d7f9feSTom Erickson zprop_register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 239e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 240e45ce728Sahrens boolean_table); 24183d7f9feSTom Erickson zprop_register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 242e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 243e45ce728Sahrens boolean_table); 24483d7f9feSTom Erickson zprop_register_index(ZFS_PROP_ZONED, "zoned", 0, PROP_INHERIT, 245e45ce728Sahrens ZFS_TYPE_FILESYSTEM, "on | off", "ZONED", boolean_table); 24683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 247e45ce728Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 248e45ce728Sahrens boolean_table); 24983d7f9feSTom Erickson zprop_register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 250da6c28aaSamw ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 251da6c28aaSamw boolean_table); 25283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 253da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 254da6c28aaSamw boolean_table); 255e45ce728Sahrens 256e45ce728Sahrens /* default index properties */ 25783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 25891ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 25914843421SMatthew Ahrens "1 | 2 | 3 | 4 | current", "VERSION", version_table); 26083d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 261a227b7f4Shs24103 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 262a227b7f4Shs24103 "CANMOUNT", canmount_table); 263e45ce728Sahrens 264e45ce728Sahrens /* readonly index (boolean) properties */ 26583d7f9feSTom Erickson zprop_register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 266990b4856Slling ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 26783d7f9feSTom Erickson zprop_register_index(ZFS_PROP_DEFER_DESTROY, "defer_destroy", 0, 268842727c2SChris Kirby PROP_READONLY, ZFS_TYPE_SNAPSHOT, "yes | no", "DEFER_DESTROY", 269842727c2SChris Kirby boolean_table); 270e45ce728Sahrens 271da6c28aaSamw /* set once index properties */ 27283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 273da6c28aaSamw PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 274da6c28aaSamw "none | formC | formD | formKC | formKD", "NORMALIZATION", 275da6c28aaSamw normalize_table); 27683d7f9feSTom Erickson zprop_register_index(ZFS_PROP_CASE, "casesensitivity", 27783d7f9feSTom Erickson ZFS_CASE_SENSITIVE, PROP_ONETIME, ZFS_TYPE_FILESYSTEM | 27883d7f9feSTom Erickson ZFS_TYPE_SNAPSHOT, 279da6c28aaSamw "sensitive | insensitive | mixed", "CASE", case_table); 280da6c28aaSamw 281da6c28aaSamw /* set once index (boolean) properties */ 28283d7f9feSTom Erickson zprop_register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 283da6c28aaSamw ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 284da6c28aaSamw "on | off", "UTF8ONLY", boolean_table); 285da6c28aaSamw 28691ebeef5Sahrens /* string properties */ 28783d7f9feSTom Erickson zprop_register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 28891ebeef5Sahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 28983d7f9feSTom Erickson zprop_register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", 29083d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", 29183d7f9feSTom Erickson "MOUNTPOINT"); 29283d7f9feSTom Erickson zprop_register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", 29383d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", 29483d7f9feSTom Erickson "SHARENFS"); 29583d7f9feSTom Erickson zprop_register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 296990b4856Slling ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 29783d7f9feSTom Erickson zprop_register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", 29883d7f9feSTom Erickson PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 29983d7f9feSTom Erickson "on | off | sharemgr(1M) options", "SHARESMB"); 30083d7f9feSTom Erickson zprop_register_string(ZFS_PROP_MLSLABEL, "mlslabel", 30183d7f9feSTom Erickson ZFS_MLSLABEL_DEFAULT, PROP_INHERIT, ZFS_TYPE_DATASET, 30283d7f9feSTom Erickson "<sensitivity label>", "MLSLABEL"); 30391ebeef5Sahrens 30491ebeef5Sahrens /* readonly number properties */ 30583d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 306990b4856Slling ZFS_TYPE_DATASET, "<size>", "USED"); 30783d7f9feSTom Erickson zprop_register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 308990b4856Slling ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 30983d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFERENCED, "referenced", 0, 31083d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_DATASET, "<size>", "REFER"); 31183d7f9feSTom Erickson zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 312990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, 31391ebeef5Sahrens "<1.00x or higher if compressed>", "RATIO"); 31483d7f9feSTom Erickson zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 315c1449561SEric Taylor ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME, 316da6c28aaSamw ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 31783d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, 31883d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 31983d7f9feSTom Erickson "USEDSNAP"); 32083d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, 32183d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 32283d7f9feSTom Erickson "USEDDS"); 32383d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, 32483d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", 32583d7f9feSTom Erickson "USEDCHILD"); 32683d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 32774e7dc98SMatthew Ahrens PROP_READONLY, 32874e7dc98SMatthew Ahrens ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 32983d7f9feSTom Erickson zprop_register_number(ZFS_PROP_USERREFS, "userrefs", 0, PROP_READONLY, 330842727c2SChris Kirby ZFS_TYPE_SNAPSHOT, "<count>", "USERREFS"); 33191ebeef5Sahrens 33291ebeef5Sahrens /* default number properties */ 33383d7f9feSTom Erickson zprop_register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 33491ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 33583d7f9feSTom Erickson zprop_register_number(ZFS_PROP_RESERVATION, "reservation", 0, 33683d7f9feSTom Erickson PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 33783d7f9feSTom Erickson "<size> | none", "RESERV"); 33883d7f9feSTom Erickson zprop_register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 33991ebeef5Sahrens ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 34083d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 341a9799022Sck153898 ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 34283d7f9feSTom Erickson zprop_register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 343a9799022Sck153898 PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 344a9799022Sck153898 "<size> | none", "REFRESERV"); 34591ebeef5Sahrens 34691ebeef5Sahrens /* inherit number properties */ 34783d7f9feSTom Erickson zprop_register_number(ZFS_PROP_RECORDSIZE, "recordsize", 34883d7f9feSTom Erickson SPA_MAXBLOCKSIZE, PROP_INHERIT, 34991ebeef5Sahrens ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 35091ebeef5Sahrens 35191ebeef5Sahrens /* hidden properties */ 35283d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 353b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 35483d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 355b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_SNAPSHOT, "NUMCLONES"); 35683d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 357990b4856Slling PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 35883d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", 35983d7f9feSTom Erickson PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 36083d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_STMF_SHAREINFO, "stmf_sbd_lu", 361478ed9adSEric Taylor PROP_TYPE_STRING, PROP_INHERIT, ZFS_TYPE_VOLUME, 362478ed9adSEric Taylor "STMF_SBD_LU"); 36383d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, 36483d7f9feSTom Erickson PROP_READONLY, ZFS_TYPE_DATASET, "GUID"); 36583d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_USERACCOUNTING, "useraccounting", 366b24ab676SJeff Bonwick PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_DATASET, 367b24ab676SJeff Bonwick "USERACCOUNTING"); 36883d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_UNIQUE, "unique", PROP_TYPE_NUMBER, 369b24ab676SJeff Bonwick PROP_READONLY, ZFS_TYPE_DATASET, "UNIQUE"); 37083d7f9feSTom Erickson zprop_register_hidden(ZFS_PROP_OBJSETID, "objsetid", PROP_TYPE_NUMBER, 3711d713200SEric Schrock PROP_READONLY, ZFS_TYPE_DATASET, "OBJSETID"); 37291ebeef5Sahrens 37327dd1e87SMark Shellenbaum /* 37427dd1e87SMark Shellenbaum * Property to be removed once libbe is integrated 37527dd1e87SMark Shellenbaum */ 37627dd1e87SMark Shellenbaum zprop_register_hidden(ZFS_PROP_PRIVATE, "priv_prop", 37727dd1e87SMark Shellenbaum PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_FILESYSTEM, 37827dd1e87SMark Shellenbaum "PRIV_PROP"); 37927dd1e87SMark Shellenbaum 38091ebeef5Sahrens /* oddball properties */ 38183d7f9feSTom Erickson zprop_register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, 38283d7f9feSTom Erickson NULL, PROP_READONLY, ZFS_TYPE_DATASET, 38391ebeef5Sahrens "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 38491ebeef5Sahrens } 38591ebeef5Sahrens 386b1b8ab34Slling boolean_t 387990b4856Slling zfs_prop_delegatable(zfs_prop_t prop) 388b1b8ab34Slling { 389990b4856Slling zprop_desc_t *pd = &zfs_prop_table[prop]; 3904201a95eSRic Aleshire 3914201a95eSRic Aleshire /* The mlslabel property is never delegatable. */ 3924201a95eSRic Aleshire if (prop == ZFS_PROP_MLSLABEL) 3934201a95eSRic Aleshire return (B_FALSE); 3944201a95eSRic Aleshire 395990b4856Slling return (pd->pd_attr != PROP_READONLY); 396b1b8ab34Slling } 397b1b8ab34Slling 398b1b8ab34Slling /* 399b1b8ab34Slling * Given a zfs dataset property name, returns the corresponding property ID. 400fa9e4066Sahrens */ 401fa9e4066Sahrens zfs_prop_t 402fa9e4066Sahrens zfs_name_to_prop(const char *propname) 403fa9e4066Sahrens { 404990b4856Slling return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 405b1b8ab34Slling } 406fa9e4066Sahrens 407fa9e4066Sahrens /* 408e9dbad6fSeschrock * For user property names, we allow all lowercase alphanumeric characters, plus 409e9dbad6fSeschrock * a few useful punctuation characters. 410e9dbad6fSeschrock */ 411e9dbad6fSeschrock static int 412e9dbad6fSeschrock valid_char(char c) 413e9dbad6fSeschrock { 414e9dbad6fSeschrock return ((c >= 'a' && c <= 'z') || 415e9dbad6fSeschrock (c >= '0' && c <= '9') || 416e9dbad6fSeschrock c == '-' || c == '_' || c == '.' || c == ':'); 417e9dbad6fSeschrock } 418e9dbad6fSeschrock 419e9dbad6fSeschrock /* 420e9dbad6fSeschrock * Returns true if this is a valid user-defined property (one with a ':'). 421e9dbad6fSeschrock */ 422e9dbad6fSeschrock boolean_t 423e9dbad6fSeschrock zfs_prop_user(const char *name) 424e9dbad6fSeschrock { 425e9dbad6fSeschrock int i; 426e9dbad6fSeschrock char c; 427e9dbad6fSeschrock boolean_t foundsep = B_FALSE; 428e9dbad6fSeschrock 429e9dbad6fSeschrock for (i = 0; i < strlen(name); i++) { 430e9dbad6fSeschrock c = name[i]; 431e9dbad6fSeschrock if (!valid_char(c)) 432e9dbad6fSeschrock return (B_FALSE); 433e9dbad6fSeschrock if (c == ':') 434e9dbad6fSeschrock foundsep = B_TRUE; 435e9dbad6fSeschrock } 436e9dbad6fSeschrock 437e9dbad6fSeschrock if (!foundsep) 438e9dbad6fSeschrock return (B_FALSE); 439e9dbad6fSeschrock 440e9dbad6fSeschrock return (B_TRUE); 441e9dbad6fSeschrock } 442e9dbad6fSeschrock 443e9dbad6fSeschrock /* 44414843421SMatthew Ahrens * Returns true if this is a valid userspace-type property (one with a '@'). 44514843421SMatthew Ahrens * Note that after the @, any character is valid (eg, another @, for SID 44614843421SMatthew Ahrens * user@domain). 44714843421SMatthew Ahrens */ 44814843421SMatthew Ahrens boolean_t 44914843421SMatthew Ahrens zfs_prop_userquota(const char *name) 45014843421SMatthew Ahrens { 45114843421SMatthew Ahrens zfs_userquota_prop_t prop; 45214843421SMatthew Ahrens 45314843421SMatthew Ahrens for (prop = 0; prop < ZFS_NUM_USERQUOTA_PROPS; prop++) { 45414843421SMatthew Ahrens if (strncmp(name, zfs_userquota_prop_prefixes[prop], 45514843421SMatthew Ahrens strlen(zfs_userquota_prop_prefixes[prop])) == 0) { 45614843421SMatthew Ahrens return (B_TRUE); 45714843421SMatthew Ahrens } 45814843421SMatthew Ahrens } 45914843421SMatthew Ahrens 46014843421SMatthew Ahrens return (B_FALSE); 46114843421SMatthew Ahrens } 46214843421SMatthew Ahrens 46314843421SMatthew Ahrens /* 464990b4856Slling * Tables of index types, plus functions to convert between the user view 465990b4856Slling * (strings) and internal representation (uint64_t). 466fa9e4066Sahrens */ 467990b4856Slling int 468990b4856Slling zfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 469fa9e4066Sahrens { 470990b4856Slling return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 471990b4856Slling } 472990b4856Slling 473990b4856Slling int 474990b4856Slling zfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 475990b4856Slling { 476990b4856Slling return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 477990b4856Slling } 478990b4856Slling 479b24ab676SJeff Bonwick uint64_t 480b24ab676SJeff Bonwick zfs_prop_random_value(zfs_prop_t prop, uint64_t seed) 481b24ab676SJeff Bonwick { 482b24ab676SJeff Bonwick return (zprop_random_value(prop, seed, ZFS_TYPE_DATASET)); 483b24ab676SJeff Bonwick } 484b24ab676SJeff Bonwick 485990b4856Slling /* 486990b4856Slling * Returns TRUE if the property applies to any of the given dataset types. 487990b4856Slling */ 4884853e976Sgw25295 boolean_t 489990b4856Slling zfs_prop_valid_for_type(int prop, zfs_type_t types) 490990b4856Slling { 491990b4856Slling return (zprop_valid_for_type(prop, types)); 492990b4856Slling } 493990b4856Slling 494990b4856Slling zprop_type_t 495990b4856Slling zfs_prop_get_type(zfs_prop_t prop) 496990b4856Slling { 497990b4856Slling return (zfs_prop_table[prop].pd_proptype); 498990b4856Slling } 499990b4856Slling 500990b4856Slling /* 501990b4856Slling * Returns TRUE if the property is readonly. 502990b4856Slling */ 503990b4856Slling boolean_t 504990b4856Slling zfs_prop_readonly(zfs_prop_t prop) 505990b4856Slling { 506da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 507da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 508da6c28aaSamw } 509da6c28aaSamw 510da6c28aaSamw /* 511da6c28aaSamw * Returns TRUE if the property is only allowed to be set once. 512da6c28aaSamw */ 513da6c28aaSamw boolean_t 514da6c28aaSamw zfs_prop_setonce(zfs_prop_t prop) 515da6c28aaSamw { 516da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 517fa9e4066Sahrens } 518fa9e4066Sahrens 5193d7072f8Seschrock const char * 520990b4856Slling zfs_prop_default_string(zfs_prop_t prop) 5213d7072f8Seschrock { 5223d7072f8Seschrock return (zfs_prop_table[prop].pd_strdefault); 5233d7072f8Seschrock } 5243d7072f8Seschrock 525fa9e4066Sahrens uint64_t 526fa9e4066Sahrens zfs_prop_default_numeric(zfs_prop_t prop) 527fa9e4066Sahrens { 528fa9e4066Sahrens return (zfs_prop_table[prop].pd_numdefault); 529fa9e4066Sahrens } 530fa9e4066Sahrens 531fa9e4066Sahrens /* 532b1b8ab34Slling * Given a dataset property ID, returns the corresponding name. 5333d7072f8Seschrock * Assuming the zfs dataset property ID is valid. 534fa9e4066Sahrens */ 535fa9e4066Sahrens const char * 536fa9e4066Sahrens zfs_prop_to_name(zfs_prop_t prop) 537fa9e4066Sahrens { 538fa9e4066Sahrens return (zfs_prop_table[prop].pd_name); 539fa9e4066Sahrens } 540fa9e4066Sahrens 541fa9e4066Sahrens /* 542fa9e4066Sahrens * Returns TRUE if the property is inheritable. 543fa9e4066Sahrens */ 544990b4856Slling boolean_t 545fa9e4066Sahrens zfs_prop_inheritable(zfs_prop_t prop) 546fa9e4066Sahrens { 547da6c28aaSamw return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 548da6c28aaSamw zfs_prop_table[prop].pd_attr == PROP_ONETIME); 549e9dbad6fSeschrock } 550e9dbad6fSeschrock 551acd76fe5Seschrock #ifndef _KERNEL 552acd76fe5Seschrock 553fa9e4066Sahrens /* 554fa9e4066Sahrens * Returns a string describing the set of acceptable values for the given 555b1b8ab34Slling * zfs property, or NULL if it cannot be set. 556fa9e4066Sahrens */ 557fa9e4066Sahrens const char * 558fa9e4066Sahrens zfs_prop_values(zfs_prop_t prop) 559fa9e4066Sahrens { 560fa9e4066Sahrens return (zfs_prop_table[prop].pd_values); 561fa9e4066Sahrens } 562fa9e4066Sahrens 563fa9e4066Sahrens /* 564fa9e4066Sahrens * Returns TRUE if this property is a string type. Note that index types 565fa9e4066Sahrens * (compression, checksum) are treated as strings in userland, even though they 566fa9e4066Sahrens * are stored numerically on disk. 567fa9e4066Sahrens */ 568fa9e4066Sahrens int 569fa9e4066Sahrens zfs_prop_is_string(zfs_prop_t prop) 570fa9e4066Sahrens { 57191ebeef5Sahrens return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 57291ebeef5Sahrens zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 573fa9e4066Sahrens } 574fa9e4066Sahrens 575fa9e4066Sahrens /* 576fa9e4066Sahrens * Returns the column header for the given property. Used only in 577fa9e4066Sahrens * 'zfs list -o', but centralized here with the other property information. 578fa9e4066Sahrens */ 579fa9e4066Sahrens const char * 580fa9e4066Sahrens zfs_prop_column_name(zfs_prop_t prop) 581fa9e4066Sahrens { 582fa9e4066Sahrens return (zfs_prop_table[prop].pd_colname); 583fa9e4066Sahrens } 584fa9e4066Sahrens 585fa9e4066Sahrens /* 586e9dbad6fSeschrock * Returns whether the given property should be displayed right-justified for 587e9dbad6fSeschrock * 'zfs list'. 588fa9e4066Sahrens */ 589e9dbad6fSeschrock boolean_t 590e9dbad6fSeschrock zfs_prop_align_right(zfs_prop_t prop) 591fa9e4066Sahrens { 592e9dbad6fSeschrock return (zfs_prop_table[prop].pd_rightalign); 593fa9e4066Sahrens } 594da6c28aaSamw 595fa9e4066Sahrens #endif 596