zfs_prop.c revision 192240
1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22185029Spjd * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23168404Spjd * Use is subject to license terms. 24168404Spjd */ 25168404Spjd 26168404Spjd#include <sys/zio.h> 27168404Spjd#include <sys/spa.h> 28185029Spjd#include <sys/u8_textprep.h> 29168404Spjd#include <sys/zfs_acl.h> 30168404Spjd#include <sys/zfs_ioctl.h> 31185029Spjd#include <sys/zfs_znode.h> 32168404Spjd 33168404Spjd#include "zfs_prop.h" 34185029Spjd#include "zfs_deleg.h" 35168404Spjd 36168404Spjd#if defined(_KERNEL) 37168404Spjd#include <sys/systm.h> 38168404Spjd#else 39168404Spjd#include <stdlib.h> 40168404Spjd#include <string.h> 41168404Spjd#include <ctype.h> 42168404Spjd#endif 43168404Spjd 44185029Spjdstatic zprop_desc_t zfs_prop_table[ZFS_NUM_PROPS]; 45168404Spjd 46185029Spjdzprop_desc_t * 47185029Spjdzfs_prop_get_table(void) 48168404Spjd{ 49185029Spjd return (zfs_prop_table); 50168404Spjd} 51168404Spjd 52185029Spjdvoid 53185029Spjdzfs_prop_init(void) 54168404Spjd{ 55185029Spjd static zprop_index_t checksum_table[] = { 56185029Spjd { "on", ZIO_CHECKSUM_ON }, 57185029Spjd { "off", ZIO_CHECKSUM_OFF }, 58185029Spjd { "fletcher2", ZIO_CHECKSUM_FLETCHER_2 }, 59185029Spjd { "fletcher4", ZIO_CHECKSUM_FLETCHER_4 }, 60185029Spjd { "sha256", ZIO_CHECKSUM_SHA256 }, 61185029Spjd { NULL } 62185029Spjd }; 63168404Spjd 64185029Spjd static zprop_index_t compress_table[] = { 65185029Spjd { "on", ZIO_COMPRESS_ON }, 66185029Spjd { "off", ZIO_COMPRESS_OFF }, 67185029Spjd { "lzjb", ZIO_COMPRESS_LZJB }, 68185029Spjd { "gzip", ZIO_COMPRESS_GZIP_6 }, /* gzip default */ 69185029Spjd { "gzip-1", ZIO_COMPRESS_GZIP_1 }, 70185029Spjd { "gzip-2", ZIO_COMPRESS_GZIP_2 }, 71185029Spjd { "gzip-3", ZIO_COMPRESS_GZIP_3 }, 72185029Spjd { "gzip-4", ZIO_COMPRESS_GZIP_4 }, 73185029Spjd { "gzip-5", ZIO_COMPRESS_GZIP_5 }, 74185029Spjd { "gzip-6", ZIO_COMPRESS_GZIP_6 }, 75185029Spjd { "gzip-7", ZIO_COMPRESS_GZIP_7 }, 76185029Spjd { "gzip-8", ZIO_COMPRESS_GZIP_8 }, 77185029Spjd { "gzip-9", ZIO_COMPRESS_GZIP_9 }, 78185029Spjd { NULL } 79185029Spjd }; 80168404Spjd 81185029Spjd static zprop_index_t snapdir_table[] = { 82185029Spjd { "hidden", ZFS_SNAPDIR_HIDDEN }, 83185029Spjd { "visible", ZFS_SNAPDIR_VISIBLE }, 84185029Spjd { NULL } 85185029Spjd }; 86168404Spjd 87185029Spjd static zprop_index_t acl_mode_table[] = { 88185029Spjd { "discard", ZFS_ACL_DISCARD }, 89185029Spjd { "groupmask", ZFS_ACL_GROUPMASK }, 90185029Spjd { "passthrough", ZFS_ACL_PASSTHROUGH }, 91185029Spjd { NULL } 92185029Spjd }; 93168404Spjd 94185029Spjd static zprop_index_t acl_inherit_table[] = { 95185029Spjd { "discard", ZFS_ACL_DISCARD }, 96185029Spjd { "noallow", ZFS_ACL_NOALLOW }, 97185029Spjd { "restricted", ZFS_ACL_RESTRICTED }, 98185029Spjd { "passthrough", ZFS_ACL_PASSTHROUGH }, 99185029Spjd { "secure", ZFS_ACL_RESTRICTED }, /* bkwrd compatability */ 100185029Spjd { NULL } 101185029Spjd }; 102168404Spjd 103185029Spjd static zprop_index_t case_table[] = { 104185029Spjd { "sensitive", ZFS_CASE_SENSITIVE }, 105185029Spjd { "insensitive", ZFS_CASE_INSENSITIVE }, 106185029Spjd { "mixed", ZFS_CASE_MIXED }, 107185029Spjd { NULL } 108185029Spjd }; 109168404Spjd 110185029Spjd static zprop_index_t copies_table[] = { 111185029Spjd { "1", 1 }, 112185029Spjd { "2", 2 }, 113185029Spjd { "3", 3 }, 114185029Spjd { NULL } 115185029Spjd }; 116168404Spjd 117185029Spjd /* 118185029Spjd * Use the unique flags we have to send to u8_strcmp() and/or 119185029Spjd * u8_textprep() to represent the various normalization property 120185029Spjd * values. 121185029Spjd */ 122185029Spjd static zprop_index_t normalize_table[] = { 123185029Spjd { "none", 0 }, 124185029Spjd { "formD", U8_TEXTPREP_NFD }, 125185029Spjd { "formKC", U8_TEXTPREP_NFKC }, 126185029Spjd { "formC", U8_TEXTPREP_NFC }, 127185029Spjd { "formKD", U8_TEXTPREP_NFKD }, 128185029Spjd { NULL } 129185029Spjd }; 130168404Spjd 131185029Spjd static zprop_index_t version_table[] = { 132185029Spjd { "1", 1 }, 133185029Spjd { "2", 2 }, 134185029Spjd { "3", 3 }, 135185029Spjd { "current", ZPL_VERSION }, 136185029Spjd { NULL } 137185029Spjd }; 138168404Spjd 139185029Spjd static zprop_index_t boolean_table[] = { 140185029Spjd { "off", 0 }, 141185029Spjd { "on", 1 }, 142185029Spjd { NULL } 143185029Spjd }; 144168404Spjd 145185029Spjd static zprop_index_t canmount_table[] = { 146185029Spjd { "off", ZFS_CANMOUNT_OFF }, 147185029Spjd { "on", ZFS_CANMOUNT_ON }, 148185029Spjd { "noauto", ZFS_CANMOUNT_NOAUTO }, 149185029Spjd { NULL } 150185029Spjd }; 151168404Spjd 152185029Spjd static zprop_index_t cache_table[] = { 153185029Spjd { "none", ZFS_CACHE_NONE }, 154185029Spjd { "metadata", ZFS_CACHE_METADATA }, 155185029Spjd { "all", ZFS_CACHE_ALL }, 156185029Spjd { NULL } 157185029Spjd }; 158168404Spjd 159185029Spjd /* inherit index properties */ 160185029Spjd register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, 161185029Spjd PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 162185029Spjd "on | off | fletcher2 | fletcher4 | sha256", "CHECKSUM", 163185029Spjd checksum_table); 164185029Spjd register_index(ZFS_PROP_COMPRESSION, "compression", 165185029Spjd ZIO_COMPRESS_DEFAULT, PROP_INHERIT, 166185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 167185029Spjd "on | off | lzjb | gzip | gzip-[1-9]", "COMPRESS", compress_table); 168185029Spjd register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN, 169185029Spjd PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 170185029Spjd "hidden | visible", "SNAPDIR", snapdir_table); 171185029Spjd register_index(ZFS_PROP_ACLMODE, "aclmode", ZFS_ACL_GROUPMASK, 172185029Spjd PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 173185029Spjd "discard | groupmask | passthrough", "ACLMODE", acl_mode_table); 174185029Spjd register_index(ZFS_PROP_ACLINHERIT, "aclinherit", ZFS_ACL_RESTRICTED, 175185029Spjd PROP_INHERIT, ZFS_TYPE_FILESYSTEM, 176185029Spjd "discard | noallow | restricted | passthrough", 177185029Spjd "ACLINHERIT", acl_inherit_table); 178185029Spjd register_index(ZFS_PROP_COPIES, "copies", 1, 179185029Spjd PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 180185029Spjd "1 | 2 | 3", "COPIES", copies_table); 181185029Spjd register_index(ZFS_PROP_PRIMARYCACHE, "primarycache", 182185029Spjd ZFS_CACHE_ALL, PROP_INHERIT, 183185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 184185029Spjd "all | none | metadata", "PRIMARYCACHE", cache_table); 185185029Spjd register_index(ZFS_PROP_SECONDARYCACHE, "secondarycache", 186185029Spjd ZFS_CACHE_ALL, PROP_INHERIT, 187185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT | ZFS_TYPE_VOLUME, 188185029Spjd "all | none | metadata", "SECONDARYCACHE", cache_table); 189168404Spjd 190185029Spjd /* inherit index (boolean) properties */ 191185029Spjd register_index(ZFS_PROP_ATIME, "atime", 1, PROP_INHERIT, 192185029Spjd ZFS_TYPE_FILESYSTEM, "on | off", "ATIME", boolean_table); 193185029Spjd register_index(ZFS_PROP_DEVICES, "devices", 1, PROP_INHERIT, 194185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "DEVICES", 195185029Spjd boolean_table); 196185029Spjd register_index(ZFS_PROP_EXEC, "exec", 1, PROP_INHERIT, 197185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "EXEC", 198185029Spjd boolean_table); 199185029Spjd register_index(ZFS_PROP_SETUID, "setuid", 1, PROP_INHERIT, 200185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "SETUID", 201185029Spjd boolean_table); 202185029Spjd register_index(ZFS_PROP_READONLY, "readonly", 0, PROP_INHERIT, 203185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off", "RDONLY", 204185029Spjd boolean_table); 205185029Spjd register_index(ZFS_PROP_ZONED, "jailed", 0, PROP_INHERIT, 206185029Spjd ZFS_TYPE_FILESYSTEM, "on | off", "JAILED", boolean_table); 207185029Spjd register_index(ZFS_PROP_XATTR, "xattr", 1, PROP_INHERIT, 208185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "XATTR", 209185029Spjd boolean_table); 210185029Spjd register_index(ZFS_PROP_VSCAN, "vscan", 0, PROP_INHERIT, 211185029Spjd ZFS_TYPE_FILESYSTEM, "on | off", "VSCAN", 212185029Spjd boolean_table); 213185029Spjd register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, 214185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", 215185029Spjd boolean_table); 216168404Spjd 217185029Spjd /* default index properties */ 218185029Spjd register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, 219185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 220185029Spjd "1 | 2 | 3 | current", "VERSION", version_table); 221185029Spjd register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, 222185029Spjd PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", 223185029Spjd "CANMOUNT", canmount_table); 224168404Spjd 225185029Spjd /* readonly index (boolean) properties */ 226185029Spjd register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, 227185029Spjd ZFS_TYPE_FILESYSTEM, "yes | no", "MOUNTED", boolean_table); 228185029Spjd 229185029Spjd /* set once index properties */ 230185029Spjd register_index(ZFS_PROP_NORMALIZE, "normalization", 0, 231185029Spjd PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 232185029Spjd "none | formC | formD | formKC | formKD", "NORMALIZATION", 233185029Spjd normalize_table); 234185029Spjd register_index(ZFS_PROP_CASE, "casesensitivity", ZFS_CASE_SENSITIVE, 235185029Spjd PROP_ONETIME, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 236185029Spjd "sensitive | insensitive | mixed", "CASE", case_table); 237185029Spjd 238185029Spjd /* set once index (boolean) properties */ 239185029Spjd register_index(ZFS_PROP_UTF8ONLY, "utf8only", 0, PROP_ONETIME, 240185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, 241185029Spjd "on | off", "UTF8ONLY", boolean_table); 242185029Spjd 243185029Spjd /* string properties */ 244185029Spjd register_string(ZFS_PROP_ORIGIN, "origin", NULL, PROP_READONLY, 245185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<snapshot>", "ORIGIN"); 246185029Spjd register_string(ZFS_PROP_MOUNTPOINT, "mountpoint", "/", PROP_INHERIT, 247185029Spjd ZFS_TYPE_FILESYSTEM, "<path> | legacy | none", "MOUNTPOINT"); 248185029Spjd register_string(ZFS_PROP_SHARENFS, "sharenfs", "off", PROP_INHERIT, 249185029Spjd ZFS_TYPE_FILESYSTEM, "on | off | share(1M) options", "SHARENFS"); 250185029Spjd register_string(ZFS_PROP_SHAREISCSI, "shareiscsi", "off", PROP_INHERIT, 251185029Spjd ZFS_TYPE_DATASET, "on | off | type=<type>", "SHAREISCSI"); 252185029Spjd register_string(ZFS_PROP_TYPE, "type", NULL, PROP_READONLY, 253185029Spjd ZFS_TYPE_DATASET, "filesystem | volume | snapshot", "TYPE"); 254185029Spjd register_string(ZFS_PROP_SHARESMB, "sharesmb", "off", PROP_INHERIT, 255185029Spjd ZFS_TYPE_FILESYSTEM, "on | off | sharemgr(1M) options", "SHARESMB"); 256185029Spjd 257185029Spjd /* readonly number properties */ 258185029Spjd register_number(ZFS_PROP_USED, "used", 0, PROP_READONLY, 259185029Spjd ZFS_TYPE_DATASET, "<size>", "USED"); 260185029Spjd register_number(ZFS_PROP_AVAILABLE, "available", 0, PROP_READONLY, 261185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "AVAIL"); 262185029Spjd register_number(ZFS_PROP_REFERENCED, "referenced", 0, PROP_READONLY, 263185029Spjd ZFS_TYPE_DATASET, "<size>", "REFER"); 264185029Spjd register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0, 265185029Spjd PROP_READONLY, ZFS_TYPE_DATASET, 266185029Spjd "<1.00x or higher if compressed>", "RATIO"); 267185029Spjd register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize", 8192, 268185029Spjd PROP_ONETIME, 269185029Spjd ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK"); 270185029Spjd register_number(ZFS_PROP_USEDSNAP, "usedbysnapshots", 0, PROP_READONLY, 271185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDSNAP"); 272185029Spjd register_number(ZFS_PROP_USEDDS, "usedbydataset", 0, PROP_READONLY, 273185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDDS"); 274185029Spjd register_number(ZFS_PROP_USEDCHILD, "usedbychildren", 0, PROP_READONLY, 275185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDCHILD"); 276185029Spjd register_number(ZFS_PROP_USEDREFRESERV, "usedbyrefreservation", 0, 277185029Spjd PROP_READONLY, 278185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size>", "USEDREFRESERV"); 279185029Spjd 280185029Spjd /* default number properties */ 281185029Spjd register_number(ZFS_PROP_QUOTA, "quota", 0, PROP_DEFAULT, 282185029Spjd ZFS_TYPE_FILESYSTEM, "<size> | none", "QUOTA"); 283185029Spjd register_number(ZFS_PROP_RESERVATION, "reservation", 0, PROP_DEFAULT, 284185029Spjd ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "<size> | none", "RESERV"); 285185029Spjd register_number(ZFS_PROP_VOLSIZE, "volsize", 0, PROP_DEFAULT, 286185029Spjd ZFS_TYPE_VOLUME, "<size>", "VOLSIZE"); 287185029Spjd register_number(ZFS_PROP_REFQUOTA, "refquota", 0, PROP_DEFAULT, 288185029Spjd ZFS_TYPE_FILESYSTEM, "<size> | none", "REFQUOTA"); 289185029Spjd register_number(ZFS_PROP_REFRESERVATION, "refreservation", 0, 290185029Spjd PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, 291185029Spjd "<size> | none", "REFRESERV"); 292185029Spjd 293185029Spjd /* inherit number properties */ 294185029Spjd register_number(ZFS_PROP_RECORDSIZE, "recordsize", SPA_MAXBLOCKSIZE, 295185029Spjd PROP_INHERIT, 296185029Spjd ZFS_TYPE_FILESYSTEM, "512 to 128k, power of 2", "RECSIZE"); 297185029Spjd 298185029Spjd /* hidden properties */ 299185029Spjd register_hidden(ZFS_PROP_CREATETXG, "createtxg", PROP_TYPE_NUMBER, 300192240Skmacy PROP_READONLY, ZFS_TYPE_DATASET, "CREATETXG"); 301185029Spjd register_hidden(ZFS_PROP_NUMCLONES, "numclones", PROP_TYPE_NUMBER, 302185029Spjd PROP_READONLY, ZFS_TYPE_SNAPSHOT, NULL); 303185029Spjd register_hidden(ZFS_PROP_NAME, "name", PROP_TYPE_STRING, 304185029Spjd PROP_READONLY, ZFS_TYPE_DATASET, "NAME"); 305185029Spjd register_hidden(ZFS_PROP_ISCSIOPTIONS, "iscsioptions", PROP_TYPE_STRING, 306185029Spjd PROP_INHERIT, ZFS_TYPE_VOLUME, "ISCSIOPTIONS"); 307185029Spjd register_hidden(ZFS_PROP_GUID, "guid", PROP_TYPE_NUMBER, PROP_READONLY, 308185029Spjd ZFS_TYPE_DATASET, "GUID"); 309185029Spjd 310185029Spjd /* oddball properties */ 311185029Spjd register_impl(ZFS_PROP_CREATION, "creation", PROP_TYPE_NUMBER, 0, NULL, 312185029Spjd PROP_READONLY, ZFS_TYPE_DATASET, 313185029Spjd "<date>", "CREATION", B_FALSE, B_TRUE, NULL); 314168404Spjd} 315168404Spjd 316185029Spjdboolean_t 317185029Spjdzfs_prop_delegatable(zfs_prop_t prop) 318168404Spjd{ 319185029Spjd zprop_desc_t *pd = &zfs_prop_table[prop]; 320185029Spjd return (pd->pd_attr != PROP_READONLY); 321168404Spjd} 322168404Spjd 323168404Spjd/* 324168404Spjd * Given a zfs dataset property name, returns the corresponding property ID. 325168404Spjd */ 326168404Spjdzfs_prop_t 327168404Spjdzfs_name_to_prop(const char *propname) 328168404Spjd{ 329185029Spjd return (zprop_name_to_prop(propname, ZFS_TYPE_DATASET)); 330168404Spjd} 331168404Spjd 332168404Spjd 333168404Spjd/* 334168404Spjd * For user property names, we allow all lowercase alphanumeric characters, plus 335168404Spjd * a few useful punctuation characters. 336168404Spjd */ 337168404Spjdstatic int 338168404Spjdvalid_char(char c) 339168404Spjd{ 340168404Spjd return ((c >= 'a' && c <= 'z') || 341168404Spjd (c >= '0' && c <= '9') || 342168404Spjd c == '-' || c == '_' || c == '.' || c == ':'); 343168404Spjd} 344168404Spjd 345168404Spjd/* 346168404Spjd * Returns true if this is a valid user-defined property (one with a ':'). 347168404Spjd */ 348168404Spjdboolean_t 349168404Spjdzfs_prop_user(const char *name) 350168404Spjd{ 351168404Spjd int i; 352168404Spjd char c; 353168404Spjd boolean_t foundsep = B_FALSE; 354168404Spjd 355168404Spjd for (i = 0; i < strlen(name); i++) { 356168404Spjd c = name[i]; 357168404Spjd if (!valid_char(c)) 358168404Spjd return (B_FALSE); 359168404Spjd if (c == ':') 360168404Spjd foundsep = B_TRUE; 361168404Spjd } 362168404Spjd 363168404Spjd if (!foundsep) 364168404Spjd return (B_FALSE); 365168404Spjd 366168404Spjd return (B_TRUE); 367168404Spjd} 368168404Spjd 369168404Spjd/* 370185029Spjd * Tables of index types, plus functions to convert between the user view 371185029Spjd * (strings) and internal representation (uint64_t). 372168404Spjd */ 373185029Spjdint 374185029Spjdzfs_prop_string_to_index(zfs_prop_t prop, const char *string, uint64_t *index) 375168404Spjd{ 376185029Spjd return (zprop_string_to_index(prop, string, index, ZFS_TYPE_DATASET)); 377168404Spjd} 378168404Spjd 379185029Spjdint 380185029Spjdzfs_prop_index_to_string(zfs_prop_t prop, uint64_t index, const char **string) 381168404Spjd{ 382185029Spjd return (zprop_index_to_string(prop, index, string, ZFS_TYPE_DATASET)); 383168404Spjd} 384168404Spjd 385168404Spjd/* 386185029Spjd * Returns TRUE if the property applies to any of the given dataset types. 387168404Spjd */ 388185029Spjdboolean_t 389185029Spjdzfs_prop_valid_for_type(int prop, zfs_type_t types) 390168404Spjd{ 391185029Spjd return (zprop_valid_for_type(prop, types)); 392168404Spjd} 393168404Spjd 394185029Spjdzprop_type_t 395185029Spjdzfs_prop_get_type(zfs_prop_t prop) 396168404Spjd{ 397185029Spjd return (zfs_prop_table[prop].pd_proptype); 398168404Spjd} 399168404Spjd 400168404Spjd/* 401185029Spjd * Returns TRUE if the property is readonly. 402168404Spjd */ 403185029Spjdboolean_t 404185029Spjdzfs_prop_readonly(zfs_prop_t prop) 405168404Spjd{ 406185029Spjd return (zfs_prop_table[prop].pd_attr == PROP_READONLY || 407185029Spjd zfs_prop_table[prop].pd_attr == PROP_ONETIME); 408168404Spjd} 409168404Spjd 410168404Spjd/* 411185029Spjd * Returns TRUE if the property is only allowed to be set once. 412168404Spjd */ 413185029Spjdboolean_t 414185029Spjdzfs_prop_setonce(zfs_prop_t prop) 415168404Spjd{ 416185029Spjd return (zfs_prop_table[prop].pd_attr == PROP_ONETIME); 417168404Spjd} 418168404Spjd 419185029Spjdconst char * 420185029Spjdzfs_prop_default_string(zfs_prop_t prop) 421185029Spjd{ 422185029Spjd return (zfs_prop_table[prop].pd_strdefault); 423185029Spjd} 424168404Spjd 425185029Spjduint64_t 426185029Spjdzfs_prop_default_numeric(zfs_prop_t prop) 427168404Spjd{ 428185029Spjd return (zfs_prop_table[prop].pd_numdefault); 429168404Spjd} 430168404Spjd 431168404Spjd/* 432185029Spjd * Given a dataset property ID, returns the corresponding name. 433185029Spjd * Assuming the zfs dataset property ID is valid. 434168404Spjd */ 435185029Spjdconst char * 436185029Spjdzfs_prop_to_name(zfs_prop_t prop) 437168404Spjd{ 438185029Spjd return (zfs_prop_table[prop].pd_name); 439168404Spjd} 440168404Spjd 441185029Spjd/* 442185029Spjd * Returns TRUE if the property is inheritable. 443185029Spjd */ 444185029Spjdboolean_t 445185029Spjdzfs_prop_inheritable(zfs_prop_t prop) 446168404Spjd{ 447185029Spjd return (zfs_prop_table[prop].pd_attr == PROP_INHERIT || 448185029Spjd zfs_prop_table[prop].pd_attr == PROP_ONETIME); 449168404Spjd} 450168404Spjd 451168404Spjd#ifndef _KERNEL 452168404Spjd 453168404Spjd/* 454168404Spjd * Returns a string describing the set of acceptable values for the given 455168404Spjd * zfs property, or NULL if it cannot be set. 456168404Spjd */ 457168404Spjdconst char * 458168404Spjdzfs_prop_values(zfs_prop_t prop) 459168404Spjd{ 460168404Spjd return (zfs_prop_table[prop].pd_values); 461168404Spjd} 462168404Spjd 463168404Spjd/* 464168404Spjd * Returns TRUE if this property is a string type. Note that index types 465168404Spjd * (compression, checksum) are treated as strings in userland, even though they 466168404Spjd * are stored numerically on disk. 467168404Spjd */ 468168404Spjdint 469168404Spjdzfs_prop_is_string(zfs_prop_t prop) 470168404Spjd{ 471185029Spjd return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING || 472185029Spjd zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX); 473168404Spjd} 474168404Spjd 475168404Spjd/* 476168404Spjd * Returns the column header for the given property. Used only in 477168404Spjd * 'zfs list -o', but centralized here with the other property information. 478168404Spjd */ 479168404Spjdconst char * 480168404Spjdzfs_prop_column_name(zfs_prop_t prop) 481168404Spjd{ 482168404Spjd return (zfs_prop_table[prop].pd_colname); 483168404Spjd} 484168404Spjd 485168404Spjd/* 486168404Spjd * Returns whether the given property should be displayed right-justified for 487168404Spjd * 'zfs list'. 488168404Spjd */ 489168404Spjdboolean_t 490168404Spjdzfs_prop_align_right(zfs_prop_t prop) 491168404Spjd{ 492168404Spjd return (zfs_prop_table[prop].pd_rightalign); 493168404Spjd} 494168404Spjd 495168404Spjd#endif 496