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/*
22219089Spjd * Copyright 2010 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#include <sys/fs/zfs.h>
30168404Spjd#include <sys/types.h>
31168404Spjd
32168404Spjd#ifdef	__cplusplus
33168404Spjdextern "C" {
34168404Spjd#endif
35168404Spjd
36168404Spjd/*
37168404Spjd * For index types (e.g. compression and checksum), we want the numeric value
38168404Spjd * in the kernel, but the string value in userland.
39168404Spjd */
40168404Spjdtypedef enum {
41185029Spjd	PROP_TYPE_NUMBER,	/* numeric value */
42185029Spjd	PROP_TYPE_STRING,	/* string value */
43185029Spjd	PROP_TYPE_INDEX		/* numeric value indexed by string */
44185029Spjd} zprop_type_t;
45168404Spjd
46185029Spjdtypedef enum {
47185029Spjd	PROP_DEFAULT,
48185029Spjd	PROP_READONLY,
49185029Spjd	PROP_INHERIT,
50185029Spjd	/*
51185029Spjd	 * ONETIME properties are a sort of conglomeration of READONLY
52185029Spjd	 * and INHERIT.  They can be set only during object creation,
53185029Spjd	 * after that they are READONLY.  If not explicitly set during
54185029Spjd	 * creation, they can be inherited.
55185029Spjd	 */
56185029Spjd	PROP_ONETIME
57185029Spjd} zprop_attr_t;
58168404Spjd
59185029Spjdtypedef struct zfs_index {
60185029Spjd	const char *pi_name;
61185029Spjd	uint64_t pi_value;
62185029Spjd} zprop_index_t;
63185029Spjd
64185029Spjdtypedef struct {
65185029Spjd	const char *pd_name;		/* human-readable property name */
66185029Spjd	int pd_propnum;			/* property number */
67185029Spjd	zprop_type_t pd_proptype;	/* string, boolean, index, number */
68185029Spjd	const char *pd_strdefault;	/* default for strings */
69185029Spjd	uint64_t pd_numdefault;		/* for boolean / index / number */
70185029Spjd	zprop_attr_t pd_attr;		/* default, readonly, inherit */
71185029Spjd	int pd_types;			/* bitfield of valid dataset types */
72185029Spjd					/* fs | vol | snap; or pool */
73185029Spjd	const char *pd_values;		/* string telling acceptable values */
74185029Spjd	const char *pd_colname;		/* column header for "zfs list" */
75185029Spjd	boolean_t pd_rightalign;	/* column alignment for "zfs list" */
76185029Spjd	boolean_t pd_visible;		/* do we list this property with the */
77185029Spjd					/* "zfs get" help message */
78185029Spjd	const zprop_index_t *pd_table;	/* for index properties, a table */
79185029Spjd					/* defining the possible values */
80219089Spjd	size_t pd_table_size;		/* number of entries in pd_table[] */
81185029Spjd} zprop_desc_t;
82185029Spjd
83185029Spjd/*
84185029Spjd * zfs dataset property functions
85185029Spjd */
86185029Spjdvoid zfs_prop_init(void);
87185029Spjdzprop_type_t zfs_prop_get_type(zfs_prop_t);
88185029Spjdboolean_t zfs_prop_delegatable(zfs_prop_t prop);
89185029Spjdzprop_desc_t *zfs_prop_get_table(void);
90185029Spjd
91185029Spjd/*
92185029Spjd * zpool property functions
93185029Spjd */
94185029Spjdvoid zpool_prop_init(void);
95185029Spjdzprop_type_t zpool_prop_get_type(zpool_prop_t);
96185029Spjdzprop_desc_t *zpool_prop_get_table(void);
97185029Spjd
98185029Spjd/*
99185029Spjd * Common routines to initialize property tables
100185029Spjd */
101219089Spjdvoid zprop_register_impl(int, const char *, zprop_type_t, uint64_t,
102185029Spjd    const char *, zprop_attr_t, int, const char *, const char *,
103185029Spjd    boolean_t, boolean_t, const zprop_index_t *);
104219089Spjdvoid zprop_register_string(int, const char *, const char *,
105219089Spjd    zprop_attr_t attr, int, const char *, const char *);
106219089Spjdvoid zprop_register_number(int, const char *, uint64_t, zprop_attr_t, int,
107185029Spjd    const char *, const char *);
108219089Spjdvoid zprop_register_index(int, const char *, uint64_t, zprop_attr_t, int,
109185029Spjd    const char *, const char *, const zprop_index_t *);
110219089Spjdvoid zprop_register_hidden(int, const char *, zprop_type_t, zprop_attr_t,
111185029Spjd    int, const char *);
112185029Spjd
113185029Spjd/*
114185029Spjd * Common routines for zfs and zpool property management
115185029Spjd */
116185029Spjdint zprop_iter_common(zprop_func, void *, boolean_t, boolean_t, zfs_type_t);
117185029Spjdint zprop_name_to_prop(const char *, zfs_type_t);
118185029Spjdint zprop_string_to_index(int, const char *, uint64_t *, zfs_type_t);
119185029Spjdint zprop_index_to_string(int, uint64_t, const char **, zfs_type_t);
120219089Spjduint64_t zprop_random_value(int, uint64_t, 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);
124229578Smmboolean_t zfs_prop_written(const char *name);
125185029Spjd
126229578Smm
127168404Spjd#ifdef	__cplusplus
128168404Spjd}
129168404Spjd#endif
130168404Spjd
131168404Spjd#endif	/* _ZFS_PROP_H */
132