zfs_prop.h revision 185029
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#ifndef	_ZFS_PROP_H
27168404Spjd#define	_ZFS_PROP_H
28168404Spjd
29168404Spjd#pragma ident	"%Z%%M%	%I%	%E% SMI"
30168404Spjd
31168404Spjd#include <sys/fs/zfs.h>
32168404Spjd#include <sys/types.h>
33168404Spjd
34168404Spjd#ifdef	__cplusplus
35168404Spjdextern "C" {
36168404Spjd#endif
37168404Spjd
38168404Spjd/*
39168404Spjd * For index types (e.g. compression and checksum), we want the numeric value
40168404Spjd * in the kernel, but the string value in userland.
41168404Spjd */
42168404Spjdtypedef enum {
43185029Spjd	PROP_TYPE_NUMBER,	/* numeric value */
44185029Spjd	PROP_TYPE_STRING,	/* string value */
45185029Spjd	PROP_TYPE_INDEX		/* numeric value indexed by string */
46185029Spjd} zprop_type_t;
47168404Spjd
48185029Spjdtypedef enum {
49185029Spjd	PROP_DEFAULT,
50185029Spjd	PROP_READONLY,
51185029Spjd	PROP_INHERIT,
52185029Spjd	/*
53185029Spjd	 * ONETIME properties are a sort of conglomeration of READONLY
54185029Spjd	 * and INHERIT.  They can be set only during object creation,
55185029Spjd	 * after that they are READONLY.  If not explicitly set during
56185029Spjd	 * creation, they can be inherited.
57185029Spjd	 */
58185029Spjd	PROP_ONETIME
59185029Spjd} zprop_attr_t;
60168404Spjd
61185029Spjdtypedef struct zfs_index {
62185029Spjd	const char *pi_name;
63185029Spjd	uint64_t pi_value;
64185029Spjd} zprop_index_t;
65185029Spjd
66185029Spjdtypedef struct {
67185029Spjd	const char *pd_name;		/* human-readable property name */
68185029Spjd	int pd_propnum;			/* property number */
69185029Spjd	zprop_type_t pd_proptype;	/* string, boolean, index, number */
70185029Spjd	const char *pd_strdefault;	/* default for strings */
71185029Spjd	uint64_t pd_numdefault;		/* for boolean / index / number */
72185029Spjd	zprop_attr_t pd_attr;		/* default, readonly, inherit */
73185029Spjd	int pd_types;			/* bitfield of valid dataset types */
74185029Spjd					/* fs | vol | snap; or pool */
75185029Spjd	const char *pd_values;		/* string telling acceptable values */
76185029Spjd	const char *pd_colname;		/* column header for "zfs list" */
77185029Spjd	boolean_t pd_rightalign;	/* column alignment for "zfs list" */
78185029Spjd	boolean_t pd_visible;		/* do we list this property with the */
79185029Spjd					/* "zfs get" help message */
80185029Spjd	const zprop_index_t *pd_table;	/* for index properties, a table */
81185029Spjd					/* defining the possible values */
82185029Spjd} zprop_desc_t;
83185029Spjd
84185029Spjd/*
85185029Spjd * zfs dataset property functions
86185029Spjd */
87185029Spjdvoid zfs_prop_init(void);
88185029Spjdzprop_type_t zfs_prop_get_type(zfs_prop_t);
89185029Spjdboolean_t zfs_prop_delegatable(zfs_prop_t prop);
90185029Spjdzprop_desc_t *zfs_prop_get_table(void);
91185029Spjd
92185029Spjd/*
93185029Spjd * zpool property functions
94185029Spjd */
95185029Spjdvoid zpool_prop_init(void);
96185029Spjdzprop_type_t zpool_prop_get_type(zpool_prop_t);
97185029Spjdzprop_desc_t *zpool_prop_get_table(void);
98185029Spjd
99185029Spjd/*
100185029Spjd * Common routines to initialize property tables
101185029Spjd */
102185029Spjdvoid register_impl(int, const char *, zprop_type_t, uint64_t,
103185029Spjd    const char *, zprop_attr_t, int, const char *, const char *,
104185029Spjd    boolean_t, boolean_t, const zprop_index_t *);
105185029Spjdvoid register_string(int, const char *, const char *, zprop_attr_t attr,
106185029Spjd    int, const char *, const char *);
107185029Spjdvoid register_number(int, const char *, uint64_t, zprop_attr_t, int,
108185029Spjd    const char *, const char *);
109185029Spjdvoid register_index(int, const char *, uint64_t, zprop_attr_t, int,
110185029Spjd    const char *, const char *, const zprop_index_t *);
111185029Spjdvoid register_hidden(int, const char *, zprop_type_t, zprop_attr_t,
112185029Spjd    int, const char *);
113185029Spjd
114185029Spjd/*
115185029Spjd * Common routines for zfs and zpool property management
116185029Spjd */
117185029Spjdint zprop_iter_common(zprop_func, void *, boolean_t, boolean_t, zfs_type_t);
118185029Spjdint zprop_name_to_prop(const char *, zfs_type_t);
119185029Spjdint zprop_string_to_index(int, const char *, uint64_t *, zfs_type_t);
120185029Spjdint zprop_index_to_string(int, uint64_t, const char **, zfs_type_t);
121185029Spjdconst char *zprop_values(int, zfs_type_t);
122185029Spjdsize_t zprop_width(int, boolean_t *, zfs_type_t);
123185029Spjdboolean_t zprop_valid_for_type(int, zfs_type_t);
124185029Spjd
125168404Spjd#ifdef	__cplusplus
126168404Spjd}
127168404Spjd#endif
128168404Spjd
129168404Spjd#endif	/* _ZFS_PROP_H */
130