xref: /freebsd/sys/contrib/openzfs/include/zfs_prop.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_ZFS_PROP_H
28 #define	_ZFS_PROP_H extern __attribute__((visibility("default")))
29 
30 #include <sys/fs/zfs.h>
31 #include <sys/types.h>
32 #include <sys/zfs_sysfs.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 	/*
53 	 * ONETIME properties are a sort of conglomeration of READONLY
54 	 * and INHERIT.  They can be set only during object creation,
55 	 * after that they are READONLY.  If not explicitly set during
56 	 * creation, they can be inherited. ONETIME_DEFAULT properties
57 	 * work the same way, but they will default instead of
58 	 * inheriting a value.
59 	 */
60 	PROP_ONETIME,
61 	PROP_ONETIME_DEFAULT
62 } zprop_attr_t;
63 
64 typedef struct zfs_index {
65 	const char *pi_name;
66 	uint64_t pi_value;
67 } zprop_index_t;
68 
69 typedef struct {
70 	const char *pd_name;		/* human-readable property name */
71 	int pd_propnum;			/* property number */
72 	zprop_type_t pd_proptype;	/* string, boolean, index, number */
73 	const char *pd_strdefault;	/* default for strings */
74 	uint64_t pd_numdefault;		/* for boolean / index / number */
75 	zprop_attr_t pd_attr;		/* default, readonly, inherit */
76 	int pd_types;			/* bitfield of valid dataset types */
77 					/* fs | vol | snap; or pool */
78 	const char *pd_values;		/* string telling acceptable values */
79 	const char *pd_colname;		/* column header for "zfs list" */
80 	boolean_t pd_rightalign: 1;	/* column alignment for "zfs list" */
81 	boolean_t pd_visible: 1;	/* do we list this property with the */
82 					/* "zfs get" help message */
83 	boolean_t pd_zfs_mod_supported: 1; /* supported by running zfs module */
84 	boolean_t pd_always_flex: 1;	/* never fixed-width */
85 	const zprop_index_t *pd_table;	/* for index properties, a table */
86 					/* defining the possible values */
87 	size_t pd_table_size;		/* number of entries in pd_table[] */
88 } zprop_desc_t;
89 
90 /*
91  * zfs dataset property functions
92  */
93 _ZFS_PROP_H void zfs_prop_init(void);
94 _ZFS_PROP_H zprop_type_t zfs_prop_get_type(zfs_prop_t);
95 _ZFS_PROP_H boolean_t zfs_prop_delegatable(zfs_prop_t prop);
96 _ZFS_PROP_H zprop_desc_t *zfs_prop_get_table(void);
97 
98 /*
99  * zpool property functions
100  */
101 _ZFS_PROP_H void zpool_prop_init(void);
102 _ZFS_PROP_H zprop_type_t zpool_prop_get_type(zpool_prop_t);
103 _ZFS_PROP_H zprop_desc_t *zpool_prop_get_table(void);
104 
105 /*
106  * vdev property functions
107  */
108 _ZFS_PROP_H void vdev_prop_init(void);
109 _ZFS_PROP_H zprop_type_t vdev_prop_get_type(vdev_prop_t prop);
110 _ZFS_PROP_H zprop_desc_t *vdev_prop_get_table(void);
111 
112 /*
113  * Common routines to initialize property tables
114  */
115 _ZFS_PROP_H void zprop_register_impl(int, const char *, zprop_type_t, uint64_t,
116     const char *, zprop_attr_t, int, const char *, const char *,
117     boolean_t, boolean_t, boolean_t, const zprop_index_t *,
118     const struct zfs_mod_supported_features *);
119 _ZFS_PROP_H void zprop_register_string(int, const char *, const char *,
120     zprop_attr_t attr, int, const char *, const char *,
121     const struct zfs_mod_supported_features *);
122 _ZFS_PROP_H void zprop_register_number(int, const char *, uint64_t,
123     zprop_attr_t, int, const char *, const char *, boolean_t,
124     const struct zfs_mod_supported_features *);
125 _ZFS_PROP_H void zprop_register_index(int, const char *, uint64_t, zprop_attr_t,
126     int, const char *, const char *, const zprop_index_t *,
127     const struct zfs_mod_supported_features *);
128 _ZFS_PROP_H void zprop_register_hidden(int, const char *, zprop_type_t,
129     zprop_attr_t, int, const char *, boolean_t,
130     const struct zfs_mod_supported_features *);
131 
132 /*
133  * Common routines for zfs and zpool property management
134  */
135 _ZFS_PROP_H int zprop_iter_common(zprop_func, void *, boolean_t, boolean_t,
136     zfs_type_t);
137 _ZFS_PROP_H int zprop_name_to_prop(const char *, zfs_type_t);
138 _ZFS_PROP_H int zprop_string_to_index(int, const char *, uint64_t *,
139     zfs_type_t);
140 _ZFS_PROP_H int zprop_index_to_string(int, uint64_t, const char **,
141     zfs_type_t);
142 _ZFS_PROP_H uint64_t zprop_random_value(int, uint64_t, zfs_type_t);
143 _ZFS_PROP_H const char *zprop_values(int, zfs_type_t);
144 _ZFS_PROP_H size_t zprop_width(int, boolean_t *, zfs_type_t);
145 _ZFS_PROP_H boolean_t zprop_valid_for_type(int, zfs_type_t, boolean_t);
146 _ZFS_PROP_H int zprop_valid_char(char c);
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _ZFS_PROP_H */
153