xref: /illumos-gate/usr/src/common/zfs/zfs_prop.h (revision 990b4856d0eaada6f8140335733a1b1771ed2746)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_ZFS_PROP_H
27 #define	_ZFS_PROP_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/fs/zfs.h>
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * For index types (e.g. compression and checksum), we want the numeric value
40  * in the kernel, but the string value in userland.
41  */
42 typedef enum {
43 	PROP_TYPE_NUMBER,	/* numeric value */
44 	PROP_TYPE_STRING,	/* string value */
45 	PROP_TYPE_INDEX		/* numeric value indexed by string */
46 } zprop_type_t;
47 
48 typedef enum {
49 	PROP_DEFAULT,
50 	PROP_READONLY,
51 	PROP_INHERIT
52 } zprop_attr_t;
53 
54 typedef struct zfs_index {
55 	const char *pi_name;
56 	uint64_t pi_value;
57 } zprop_index_t;
58 
59 typedef struct {
60 	const char *pd_name;		/* human-readable property name */
61 	int pd_propnum;			/* property number */
62 	zprop_type_t pd_proptype;	/* string, boolean, index, number */
63 	const char *pd_strdefault;	/* default for strings */
64 	uint64_t pd_numdefault;		/* for boolean / index / number */
65 	zprop_attr_t pd_attr;		/* default, readonly, inherit */
66 	int pd_types;			/* bitfield of valid dataset types */
67 					/* fs | vol | snap; or pool */
68 	const char *pd_values;		/* string telling acceptable values */
69 	const char *pd_colname;		/* column header for "zfs list" */
70 	boolean_t pd_rightalign;	/* column alignment for "zfs list" */
71 	boolean_t pd_visible;		/* do we list this property with the */
72 					/* "zfs get" help message */
73 	const zprop_index_t *pd_table;	/* for index properties, a table */
74 					/* defining the possible values */
75 } zprop_desc_t;
76 
77 /*
78  * zfs dataset property functions
79  */
80 void zfs_prop_init(void);
81 zprop_type_t zfs_prop_get_type(zfs_prop_t);
82 boolean_t zfs_prop_delegatable(zfs_prop_t prop);
83 zprop_desc_t *zfs_prop_get_table(void);
84 
85 /*
86  * zpool property functions
87  */
88 void zpool_prop_init(void);
89 zprop_type_t zpool_prop_get_type(zpool_prop_t);
90 zprop_desc_t *zpool_prop_get_table(void);
91 
92 /*
93  * Common routines to initialize property tables
94  */
95 void register_impl(int, const char *, zprop_type_t, uint64_t,
96     const char *, zprop_attr_t, int, const char *, const char *,
97     boolean_t, boolean_t, const zprop_index_t *);
98 void register_string(int, const char *, const char *, zprop_attr_t attr,
99     int, const char *, const char *);
100 void register_number(int, const char *, uint64_t, zprop_attr_t, int,
101     const char *, const char *);
102 void register_index(int, const char *, uint64_t, zprop_attr_t, int,
103     const char *, const char *, const zprop_index_t *);
104 void register_hidden(int, const char *, zprop_type_t, zprop_attr_t,
105     int, const char *);
106 
107 /*
108  * Common routines for zfs and zpool property management
109  */
110 int zprop_iter_common(zprop_func, void *, boolean_t, boolean_t, zfs_type_t);
111 int zprop_name_to_prop(const char *, zfs_type_t);
112 int zprop_string_to_index(int, const char *, uint64_t *, zfs_type_t);
113 int zprop_index_to_string(int, uint64_t, const char **, zfs_type_t);
114 const char *zprop_values(int, zfs_type_t);
115 size_t zprop_width(int, boolean_t *, zfs_type_t);
116 int zprop_valid_for_type(int, zfs_type_t);
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif	/* _ZFS_PROP_H */
123