summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdscfg/common/cfg.h
blob: 84e64b8ebee32844e8dd6378ea82bfe824674002 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_CFG_H
#define	_CFG_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/nsctl/nsctl.h>

#define	CFG_MAX_BUF	1024    /* maximum buffer size for cfg_get_?string() */
#define	CFG_MAX_KEY	256	/* maximum key size for cfg_get_?string() */

#ifndef _CFG_IMPL_H
/*
 * These are really declared in cfg_impl.h, declare as dummy's here to
 * allow clients to compile without including cfg_impl.h.
 */
typedef struct cfgfile CFGFILE;
typedef struct cfp cfp_t;

#endif	/* _CFG_IMPL_H */

int cfg_get_cstring(CFGFILE *cfg, const char *key, void *value, int value_len);
int cfg_put_cstring(CFGFILE *cfg, const char *key, void *value, int value_len);
int cfg_find_cstring(CFGFILE *cfg, const char *target, const char *section,
    int numflds, ...);
int cfg_get_options(CFGFILE *cfg, int section, const char *basekey,
				char *tag, int tag_len, char *val, int val_len);
int cfg_put_options(CFGFILE *cfg, int section, const char *basekey,
				char *tag, char *val);
int cfg_get_single_option(CFGFILE *, int, const char *, char *, char *, int);
int cfg_del_option(CFGFILE *, int, const char *, char *);

int cfg_get_num_entries(CFGFILE *cfg, char *section);

int cfg_get_tags(CFGFILE *cfg, char ***taglist);

int cfg_cfg_isempty(CFGFILE *cfg);
int cfg_get_section(CFGFILE *cfg, char ***buf, const char *section);
CFGFILE *cfg_open(char *filename);
void cfg_rewind(CFGFILE *cfg, int section);
int cfg_is_cfg(CFGFILE *cfg);
int cfg_shldskip_vtoc(int fd, const char *loc);
int cfg_get_srtdsec(CFGFILE *cfg, char ***list,
	const char *sec, const char *field);
void cfg_free_section(char ***, int);


/*
 * Handle cluster configuration
 */
#define	FP_SUN_CLUSTER(x) \
	(((x->cf_node) && (x->cf[1].cf_fd)) ? &x->cf[1] : &x->cf[0])

/*
 * rewind sections
 */
#define	CFG_SEC_CONF	0	/* configuration section */
#define	CFG_SEC_PERS	1	/* persistent section */
#define	CFG_SEC_ALL	2	/* rewind both sections */

int cfg_update_parser_config(CFGFILE *, const char *key, int section);
/*
 * parser sections
 */
#define	CFG_PARSE_CONF	0	/* config section key */
#define	CFG_PARSE_PERS	1	/* persistent section key */

char *cfg_error(int *severity);
/*
 * error codes
 */
#define	CFG_ENONFATAL	0	/* non fatal error */
#define	CFG_EFATAL	1	/* fatal error exit */

/*
 * some error strings
 */
#define	CFG_NOTLOCKED	"Configuration not locked"
#define	CFG_RDFAILED	"Unable to read configuration"
#define	CFG_EINVAL	"Invalid Argument"
#define	CFG_EGENERIC	"Generic cfg failure"


char *cfg_location(char *location, int mode, char *altroot);

/*
 * location modes
 */
#define	CFG_LOC_SET_LOCAL	0
#define	CFG_LOC_GET_LOCAL	1
#define	CFG_LOC_SET_CLUSTER	2
#define	CFG_LOC_GET_CLUSTER	3

/*
 * location strings
 */
#define	CFG_LOCAL_LOCATION	"/etc/dscfg_local"
#define	CFG_CLUSTER_LOCATION	"/etc/dscfg_cluster"

void cfg_close(CFGFILE *);

/*
 * lock mode
 */
typedef enum {
	CFG_RDLOCK,
	CFG_WRLOCK,
	CFG_UPGRADE
} CFGLOCK;

int cfg_lock(CFGFILE *, CFGLOCK);	/* lock the configuration */
void cfp_unlock(cfp_t *);		/* unlock the configuration */
void cfg_unlock(CFGFILE *);
int cfg_get_lock(CFGFILE *, CFGLOCK *, pid_t *);	/* get config lock */

int cfg_commit(CFGFILE *);
void cfg_resource(CFGFILE *, const char *);	/* Set/clear cluster node */
char *cfg_get_resource(CFGFILE *);		/* get current cluster node */
char *cfg_dgname(const char *, char *, size_t);	/* parse dg from pathname */
char *cfg_l_dgname(const char *, char *, size_t); /* parse dg from pathname */
int cfg_dgname_islocal(char *, char **);	/* find locality of dg */
int cfg_iscluster(void);			/* running in a cluster? */
int cfg_issuncluster(void);			/* running in a Sun Cluster? */
void cfg_invalidate_sizes(int);

/*
 * add/rem result codes
 */
#define	CFG_USER_ERR 1
#define	CFG_USER_OK 2
#define	CFG_USER_FIRST 3
#define	CFG_USER_LAST 4
#define	CFG_USER_GONE 5
#define	CFG_USER_REPEAT 6

int cfg_add_user(CFGFILE *, char *, char *, char *);	/* add volume user */
int cfg_rem_user(CFGFILE *, char *, char *, char *);	/* remove vol user */
int cfg_vol_enable(CFGFILE *, char *, char *, char *);	/* enable volume */
int cfg_vol_disable(CFGFILE *, char *, char *, char *);	/* disable volume */

int cfg_load_dsvols(CFGFILE *);		/* load dsvol: section */
void cfg_unload_dsvols();		/* unload dsvol: section */
int cfg_load_svols(CFGFILE *);		/* load sv: section */
void cfg_unload_svols();		/* unload sv: section */
int cfg_load_shadows(CFGFILE *);	/* load shadows & bitmaps from ii: */
void cfg_unload_shadows();		/* unload ii: */

int cfg_get_canonical_name(CFGFILE *, const char *, char **);

#ifdef	__cplusplus
}
#endif

#endif /* _CFG_H */