xref: /freebsd/sys/contrib/openzfs/include/zfs_prop.h (revision 681ce946f33e75c590e97c53076e86dff1fe8f4a)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9eda14cbcSMatt Macy  * or http://www.opensolaris.org/os/licensing.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23eda14cbcSMatt Macy  * Use is subject to license terms.
24eda14cbcSMatt Macy  */
25eda14cbcSMatt Macy 
26eda14cbcSMatt Macy #ifndef	_ZFS_PROP_H
2716038816SMartin Matuska #define	_ZFS_PROP_H extern __attribute__((visibility("default")))
28eda14cbcSMatt Macy 
29eda14cbcSMatt Macy #include <sys/fs/zfs.h>
30eda14cbcSMatt Macy #include <sys/types.h>
31eda14cbcSMatt Macy 
32eda14cbcSMatt Macy #ifdef	__cplusplus
33eda14cbcSMatt Macy extern "C" {
34eda14cbcSMatt Macy #endif
35eda14cbcSMatt Macy 
36eda14cbcSMatt Macy /*
37eda14cbcSMatt Macy  * For index types (e.g. compression and checksum), we want the numeric value
38eda14cbcSMatt Macy  * in the kernel, but the string value in userland.
39eda14cbcSMatt Macy  */
40eda14cbcSMatt Macy typedef enum {
41eda14cbcSMatt Macy 	PROP_TYPE_NUMBER,	/* numeric value */
42eda14cbcSMatt Macy 	PROP_TYPE_STRING,	/* string value */
43eda14cbcSMatt Macy 	PROP_TYPE_INDEX		/* numeric value indexed by string */
44eda14cbcSMatt Macy } zprop_type_t;
45eda14cbcSMatt Macy 
46eda14cbcSMatt Macy typedef enum {
47eda14cbcSMatt Macy 	PROP_DEFAULT,
48eda14cbcSMatt Macy 	PROP_READONLY,
49eda14cbcSMatt Macy 	PROP_INHERIT,
50eda14cbcSMatt Macy 	/*
51eda14cbcSMatt Macy 	 * ONETIME properties are a sort of conglomeration of READONLY
52eda14cbcSMatt Macy 	 * and INHERIT.  They can be set only during object creation,
53eda14cbcSMatt Macy 	 * after that they are READONLY.  If not explicitly set during
54eda14cbcSMatt Macy 	 * creation, they can be inherited. ONETIME_DEFAULT properties
55eda14cbcSMatt Macy 	 * work the same way, but they will default instead of
56eda14cbcSMatt Macy 	 * inheriting a value.
57eda14cbcSMatt Macy 	 */
58eda14cbcSMatt Macy 	PROP_ONETIME,
59eda14cbcSMatt Macy 	PROP_ONETIME_DEFAULT
60eda14cbcSMatt Macy } zprop_attr_t;
61eda14cbcSMatt Macy 
62eda14cbcSMatt Macy typedef struct zfs_index {
63eda14cbcSMatt Macy 	const char *pi_name;
64eda14cbcSMatt Macy 	uint64_t pi_value;
65eda14cbcSMatt Macy } zprop_index_t;
66eda14cbcSMatt Macy 
67eda14cbcSMatt Macy typedef struct {
68eda14cbcSMatt Macy 	const char *pd_name;		/* human-readable property name */
69eda14cbcSMatt Macy 	int pd_propnum;			/* property number */
70eda14cbcSMatt Macy 	zprop_type_t pd_proptype;	/* string, boolean, index, number */
71eda14cbcSMatt Macy 	const char *pd_strdefault;	/* default for strings */
72eda14cbcSMatt Macy 	uint64_t pd_numdefault;		/* for boolean / index / number */
73eda14cbcSMatt Macy 	zprop_attr_t pd_attr;		/* default, readonly, inherit */
74eda14cbcSMatt Macy 	int pd_types;			/* bitfield of valid dataset types */
75eda14cbcSMatt Macy 					/* fs | vol | snap; or pool */
76eda14cbcSMatt Macy 	const char *pd_values;		/* string telling acceptable values */
77eda14cbcSMatt Macy 	const char *pd_colname;		/* column header for "zfs list" */
78eda14cbcSMatt Macy 	boolean_t pd_rightalign;	/* column alignment for "zfs list" */
79eda14cbcSMatt Macy 	boolean_t pd_visible;		/* do we list this property with the */
80eda14cbcSMatt Macy 					/* "zfs get" help message */
81eda14cbcSMatt Macy 	boolean_t pd_zfs_mod_supported;	/* supported by running zfs module */
82eda14cbcSMatt Macy 	const zprop_index_t *pd_table;	/* for index properties, a table */
83eda14cbcSMatt Macy 					/* defining the possible values */
84eda14cbcSMatt Macy 	size_t pd_table_size;		/* number of entries in pd_table[] */
85eda14cbcSMatt Macy } zprop_desc_t;
86eda14cbcSMatt Macy 
87eda14cbcSMatt Macy /*
88eda14cbcSMatt Macy  * zfs dataset property functions
89eda14cbcSMatt Macy  */
9016038816SMartin Matuska _ZFS_PROP_H void zfs_prop_init(void);
9116038816SMartin Matuska _ZFS_PROP_H zprop_type_t zfs_prop_get_type(zfs_prop_t);
9216038816SMartin Matuska _ZFS_PROP_H boolean_t zfs_prop_delegatable(zfs_prop_t prop);
9316038816SMartin Matuska _ZFS_PROP_H zprop_desc_t *zfs_prop_get_table(void);
94eda14cbcSMatt Macy 
95eda14cbcSMatt Macy /*
96eda14cbcSMatt Macy  * zpool property functions
97eda14cbcSMatt Macy  */
9816038816SMartin Matuska _ZFS_PROP_H void zpool_prop_init(void);
9916038816SMartin Matuska _ZFS_PROP_H zprop_type_t zpool_prop_get_type(zpool_prop_t);
10016038816SMartin Matuska _ZFS_PROP_H zprop_desc_t *zpool_prop_get_table(void);
101eda14cbcSMatt Macy 
102eda14cbcSMatt Macy /*
103*681ce946SMartin Matuska  * vdev property functions
104*681ce946SMartin Matuska  */
105*681ce946SMartin Matuska _ZFS_PROP_H void vdev_prop_init(void);
106*681ce946SMartin Matuska _ZFS_PROP_H zprop_type_t vdev_prop_get_type(vdev_prop_t prop);
107*681ce946SMartin Matuska _ZFS_PROP_H zprop_desc_t *vdev_prop_get_table(void);
108*681ce946SMartin Matuska 
109*681ce946SMartin Matuska /*
110eda14cbcSMatt Macy  * Common routines to initialize property tables
111eda14cbcSMatt Macy  */
11216038816SMartin Matuska _ZFS_PROP_H void zprop_register_impl(int, const char *, zprop_type_t, uint64_t,
113eda14cbcSMatt Macy     const char *, zprop_attr_t, int, const char *, const char *,
114eda14cbcSMatt Macy     boolean_t, boolean_t, const zprop_index_t *);
11516038816SMartin Matuska _ZFS_PROP_H void zprop_register_string(int, const char *, const char *,
116eda14cbcSMatt Macy     zprop_attr_t attr, int, const char *, const char *);
11716038816SMartin Matuska _ZFS_PROP_H void zprop_register_number(int, const char *, uint64_t,
11816038816SMartin Matuska     zprop_attr_t, int, const char *, const char *);
11916038816SMartin Matuska _ZFS_PROP_H void zprop_register_index(int, const char *, uint64_t, zprop_attr_t,
12016038816SMartin Matuska     int, const char *, const char *, const zprop_index_t *);
12116038816SMartin Matuska _ZFS_PROP_H void zprop_register_hidden(int, const char *, zprop_type_t,
12216038816SMartin Matuska     zprop_attr_t, int, const char *);
123eda14cbcSMatt Macy 
124eda14cbcSMatt Macy /*
125eda14cbcSMatt Macy  * Common routines for zfs and zpool property management
126eda14cbcSMatt Macy  */
12716038816SMartin Matuska _ZFS_PROP_H int zprop_iter_common(zprop_func, void *, boolean_t, boolean_t,
12816038816SMartin Matuska     zfs_type_t);
12916038816SMartin Matuska _ZFS_PROP_H int zprop_name_to_prop(const char *, zfs_type_t);
13016038816SMartin Matuska _ZFS_PROP_H int zprop_string_to_index(int, const char *, uint64_t *,
13116038816SMartin Matuska     zfs_type_t);
132*681ce946SMartin Matuska _ZFS_PROP_H int zprop_index_to_string(int, uint64_t, const char **,
133*681ce946SMartin Matuska     zfs_type_t);
13416038816SMartin Matuska _ZFS_PROP_H uint64_t zprop_random_value(int, uint64_t, zfs_type_t);
13516038816SMartin Matuska _ZFS_PROP_H const char *zprop_values(int, zfs_type_t);
13616038816SMartin Matuska _ZFS_PROP_H size_t zprop_width(int, boolean_t *, zfs_type_t);
13716038816SMartin Matuska _ZFS_PROP_H boolean_t zprop_valid_for_type(int, zfs_type_t, boolean_t);
138*681ce946SMartin Matuska _ZFS_PROP_H int zprop_valid_char(char c);
139eda14cbcSMatt Macy 
140eda14cbcSMatt Macy #ifdef	__cplusplus
141eda14cbcSMatt Macy }
142eda14cbcSMatt Macy #endif
143eda14cbcSMatt Macy 
144eda14cbcSMatt Macy #endif	/* _ZFS_PROP_H */
145