xref: /illumos-gate/usr/src/common/zfs/zfs_prop.h (revision 4c2bdae2)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5e9dbad6fSeschrock  * Common Development and Distribution License (the "License").
6e9dbad6fSeschrock  * 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 /*
2283d7f9feSTom Erickson  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef	_ZFS_PROP_H
27fa9e4066Sahrens #define	_ZFS_PROP_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/fs/zfs.h>
30fa9e4066Sahrens #include <sys/types.h>
31fa9e4066Sahrens 
32fa9e4066Sahrens #ifdef	__cplusplus
33fa9e4066Sahrens extern "C" {
34fa9e4066Sahrens #endif
35fa9e4066Sahrens 
36101f5531Slling /*
37101f5531Slling  * For index types (e.g. compression and checksum), we want the numeric value
38101f5531Slling  * in the kernel, but the string value in userland.
39101f5531Slling  */
40fa9e4066Sahrens typedef enum {
4191ebeef5Sahrens 	PROP_TYPE_NUMBER,	/* numeric value */
4291ebeef5Sahrens 	PROP_TYPE_STRING,	/* string value */
4391ebeef5Sahrens 	PROP_TYPE_INDEX		/* numeric value indexed by string */
44990b4856Slling } zprop_type_t;
45fa9e4066Sahrens 
46990b4856Slling typedef enum {
47990b4856Slling 	PROP_DEFAULT,
48990b4856Slling 	PROP_READONLY,
49da6c28aaSamw 	PROP_INHERIT,
50da6c28aaSamw 	/*
51da6c28aaSamw 	 * ONETIME properties are a sort of conglomeration of READONLY
52da6c28aaSamw 	 * and INHERIT.  They can be set only during object creation,
53da6c28aaSamw 	 * after that they are READONLY.  If not explicitly set during
54eb633035STom Caputi 	 * creation, they can be inherited. ONETIME_DEFAULT properties
55eb633035STom Caputi 	 * work the same way, but they will default instead of
56eb633035STom Caputi 	 * inheriting a value.
57da6c28aaSamw 	 */
58eb633035STom Caputi 	PROP_ONETIME,
59eb633035STom Caputi 	PROP_ONETIME_DEFAULT
60990b4856Slling } zprop_attr_t;
61990b4856Slling 
62990b4856Slling typedef struct zfs_index {
63990b4856Slling 	const char *pi_name;
64990b4856Slling 	uint64_t pi_value;
65990b4856Slling } zprop_index_t;
66990b4856Slling 
67990b4856Slling typedef struct {
68990b4856Slling 	const char *pd_name;		/* human-readable property name */
69990b4856Slling 	int pd_propnum;			/* property number */
70990b4856Slling 	zprop_type_t pd_proptype;	/* string, boolean, index, number */
71990b4856Slling 	const char *pd_strdefault;	/* default for strings */
72990b4856Slling 	uint64_t pd_numdefault;		/* for boolean / index / number */
73990b4856Slling 	zprop_attr_t pd_attr;		/* default, readonly, inherit */
74990b4856Slling 	int pd_types;			/* bitfield of valid dataset types */
75990b4856Slling 					/* fs | vol | snap; or pool */
76990b4856Slling 	const char *pd_values;		/* string telling acceptable values */
77990b4856Slling 	const char *pd_colname;		/* column header for "zfs list" */
78990b4856Slling 	boolean_t pd_rightalign;	/* column alignment for "zfs list" */
79990b4856Slling 	boolean_t pd_visible;		/* do we list this property with the */
80990b4856Slling 					/* "zfs get" help message */
81990b4856Slling 	const zprop_index_t *pd_table;	/* for index properties, a table */
82990b4856Slling 					/* defining the possible values */
83b24ab676SJeff Bonwick 	size_t pd_table_size;		/* number of entries in pd_table[] */
84990b4856Slling } zprop_desc_t;
85990b4856Slling 
86990b4856Slling /*
87990b4856Slling  * zfs dataset property functions
88990b4856Slling  */
8991ebeef5Sahrens void zfs_prop_init(void);
90990b4856Slling zprop_type_t zfs_prop_get_type(zfs_prop_t);
91990b4856Slling boolean_t zfs_prop_delegatable(zfs_prop_t prop);
92990b4856Slling zprop_desc_t *zfs_prop_get_table(void);
93990b4856Slling 
94990b4856Slling /*
95990b4856Slling  * zpool property functions
96990b4856Slling  */
97990b4856Slling void zpool_prop_init(void);
98990b4856Slling zprop_type_t zpool_prop_get_type(zpool_prop_t);
99990b4856Slling zprop_desc_t *zpool_prop_get_table(void);
100990b4856Slling 
101990b4856Slling /*
102990b4856Slling  * Common routines to initialize property tables
103990b4856Slling  */
10483d7f9feSTom Erickson void zprop_register_impl(int, const char *, zprop_type_t, uint64_t,
105990b4856Slling     const char *, zprop_attr_t, int, const char *, const char *,
106990b4856Slling     boolean_t, boolean_t, const zprop_index_t *);
10783d7f9feSTom Erickson void zprop_register_string(int, const char *, const char *,
10883d7f9feSTom Erickson     zprop_attr_t attr, int, const char *, const char *);
10983d7f9feSTom Erickson void zprop_register_number(int, const char *, uint64_t, zprop_attr_t, int,
110990b4856Slling     const char *, const char *);
11183d7f9feSTom Erickson void zprop_register_index(int, const char *, uint64_t, zprop_attr_t, int,
112990b4856Slling     const char *, const char *, const zprop_index_t *);
11383d7f9feSTom Erickson void zprop_register_hidden(int, const char *, zprop_type_t, zprop_attr_t,
114990b4856Slling     int, const char *);
115990b4856Slling 
116990b4856Slling /*
117990b4856Slling  * Common routines for zfs and zpool property management
118990b4856Slling  */
119990b4856Slling int zprop_iter_common(zprop_func, void *, boolean_t, boolean_t, zfs_type_t);
120990b4856Slling int zprop_name_to_prop(const char *, zfs_type_t);
121990b4856Slling int zprop_string_to_index(int, const char *, uint64_t *, zfs_type_t);
122990b4856Slling int zprop_index_to_string(int, uint64_t, const char **, zfs_type_t);
123b24ab676SJeff Bonwick uint64_t zprop_random_value(int, uint64_t, zfs_type_t);
124990b4856Slling const char *zprop_values(int, zfs_type_t);
125990b4856Slling size_t zprop_width(int, boolean_t *, zfs_type_t);
126*4c2bdae2STim Chase boolean_t zprop_valid_for_type(int, zfs_type_t, boolean_t);
127fa9e4066Sahrens 
128fa9e4066Sahrens #ifdef	__cplusplus
129fa9e4066Sahrens }
130fa9e4066Sahrens #endif
131fa9e4066Sahrens 
132fa9e4066Sahrens #endif	/* _ZFS_PROP_H */
133