xref: /titanic_52/usr/src/lib/libdscfg/common/cfg.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #ifndef	_CFG_H
27*fcf3ce44SJohn Forte #define	_CFG_H
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte #ifdef	__cplusplus
30*fcf3ce44SJohn Forte extern "C" {
31*fcf3ce44SJohn Forte #endif
32*fcf3ce44SJohn Forte 
33*fcf3ce44SJohn Forte #include <sys/nsctl/nsctl.h>
34*fcf3ce44SJohn Forte 
35*fcf3ce44SJohn Forte #define	CFG_MAX_BUF	1024    /* maximum buffer size for cfg_get_?string() */
36*fcf3ce44SJohn Forte #define	CFG_MAX_KEY	256	/* maximum key size for cfg_get_?string() */
37*fcf3ce44SJohn Forte 
38*fcf3ce44SJohn Forte #ifndef _CFG_IMPL_H
39*fcf3ce44SJohn Forte /*
40*fcf3ce44SJohn Forte  * These are really declared in cfg_impl.h, declare as dummy's here to
41*fcf3ce44SJohn Forte  * allow clients to compile without including cfg_impl.h.
42*fcf3ce44SJohn Forte  */
43*fcf3ce44SJohn Forte typedef struct cfgfile CFGFILE;
44*fcf3ce44SJohn Forte typedef struct cfp cfp_t;
45*fcf3ce44SJohn Forte 
46*fcf3ce44SJohn Forte #endif	/* _CFG_IMPL_H */
47*fcf3ce44SJohn Forte 
48*fcf3ce44SJohn Forte int cfg_get_cstring(CFGFILE *cfg, const char *key, void *value, int value_len);
49*fcf3ce44SJohn Forte int cfg_put_cstring(CFGFILE *cfg, const char *key, void *value, int value_len);
50*fcf3ce44SJohn Forte int cfg_find_cstring(CFGFILE *cfg, const char *target, const char *section,
51*fcf3ce44SJohn Forte     int numflds, ...);
52*fcf3ce44SJohn Forte int cfg_get_options(CFGFILE *cfg, int section, const char *basekey,
53*fcf3ce44SJohn Forte 				char *tag, int tag_len, char *val, int val_len);
54*fcf3ce44SJohn Forte int cfg_put_options(CFGFILE *cfg, int section, const char *basekey,
55*fcf3ce44SJohn Forte 				char *tag, char *val);
56*fcf3ce44SJohn Forte int cfg_get_single_option(CFGFILE *, int, const char *, char *, char *, int);
57*fcf3ce44SJohn Forte int cfg_del_option(CFGFILE *, int, const char *, char *);
58*fcf3ce44SJohn Forte 
59*fcf3ce44SJohn Forte int cfg_get_num_entries(CFGFILE *cfg, char *section);
60*fcf3ce44SJohn Forte 
61*fcf3ce44SJohn Forte int cfg_get_tags(CFGFILE *cfg, char ***taglist);
62*fcf3ce44SJohn Forte 
63*fcf3ce44SJohn Forte int cfg_cfg_isempty(CFGFILE *cfg);
64*fcf3ce44SJohn Forte int cfg_get_section(CFGFILE *cfg, char ***buf, const char *section);
65*fcf3ce44SJohn Forte CFGFILE *cfg_open(char *filename);
66*fcf3ce44SJohn Forte void cfg_rewind(CFGFILE *cfg, int section);
67*fcf3ce44SJohn Forte int cfg_is_cfg(CFGFILE *cfg);
68*fcf3ce44SJohn Forte int cfg_shldskip_vtoc(int fd, const char *loc);
69*fcf3ce44SJohn Forte int cfg_get_srtdsec(CFGFILE *cfg, char ***list,
70*fcf3ce44SJohn Forte 	const char *sec, const char *field);
71*fcf3ce44SJohn Forte void cfg_free_section(char ***, int);
72*fcf3ce44SJohn Forte 
73*fcf3ce44SJohn Forte 
74*fcf3ce44SJohn Forte /*
75*fcf3ce44SJohn Forte  * Handle cluster configuration
76*fcf3ce44SJohn Forte  */
77*fcf3ce44SJohn Forte #define	FP_SUN_CLUSTER(x) \
78*fcf3ce44SJohn Forte 	(((x->cf_node) && (x->cf[1].cf_fd)) ? &x->cf[1] : &x->cf[0])
79*fcf3ce44SJohn Forte 
80*fcf3ce44SJohn Forte /*
81*fcf3ce44SJohn Forte  * rewind sections
82*fcf3ce44SJohn Forte  */
83*fcf3ce44SJohn Forte #define	CFG_SEC_CONF	0	/* configuration section */
84*fcf3ce44SJohn Forte #define	CFG_SEC_PERS	1	/* persistent section */
85*fcf3ce44SJohn Forte #define	CFG_SEC_ALL	2	/* rewind both sections */
86*fcf3ce44SJohn Forte 
87*fcf3ce44SJohn Forte int cfg_update_parser_config(CFGFILE *, const char *key, int section);
88*fcf3ce44SJohn Forte /*
89*fcf3ce44SJohn Forte  * parser sections
90*fcf3ce44SJohn Forte  */
91*fcf3ce44SJohn Forte #define	CFG_PARSE_CONF	0	/* config section key */
92*fcf3ce44SJohn Forte #define	CFG_PARSE_PERS	1	/* persistent section key */
93*fcf3ce44SJohn Forte 
94*fcf3ce44SJohn Forte char *cfg_error(int *severity);
95*fcf3ce44SJohn Forte /*
96*fcf3ce44SJohn Forte  * error codes
97*fcf3ce44SJohn Forte  */
98*fcf3ce44SJohn Forte #define	CFG_ENONFATAL	0	/* non fatal error */
99*fcf3ce44SJohn Forte #define	CFG_EFATAL	1	/* fatal error exit */
100*fcf3ce44SJohn Forte 
101*fcf3ce44SJohn Forte /*
102*fcf3ce44SJohn Forte  * some error strings
103*fcf3ce44SJohn Forte  */
104*fcf3ce44SJohn Forte #define	CFG_NOTLOCKED	"Configuration not locked"
105*fcf3ce44SJohn Forte #define	CFG_RDFAILED	"Unable to read configuration"
106*fcf3ce44SJohn Forte #define	CFG_EINVAL	"Invalid Argument"
107*fcf3ce44SJohn Forte #define	CFG_EGENERIC	"Generic cfg failure"
108*fcf3ce44SJohn Forte 
109*fcf3ce44SJohn Forte 
110*fcf3ce44SJohn Forte char *cfg_location(char *location, int mode, char *altroot);
111*fcf3ce44SJohn Forte 
112*fcf3ce44SJohn Forte /*
113*fcf3ce44SJohn Forte  * location modes
114*fcf3ce44SJohn Forte  */
115*fcf3ce44SJohn Forte #define	CFG_LOC_SET_LOCAL	0
116*fcf3ce44SJohn Forte #define	CFG_LOC_GET_LOCAL	1
117*fcf3ce44SJohn Forte #define	CFG_LOC_SET_CLUSTER	2
118*fcf3ce44SJohn Forte #define	CFG_LOC_GET_CLUSTER	3
119*fcf3ce44SJohn Forte 
120*fcf3ce44SJohn Forte /*
121*fcf3ce44SJohn Forte  * location strings
122*fcf3ce44SJohn Forte  */
123*fcf3ce44SJohn Forte #define	CFG_LOCAL_LOCATION	"/etc/dscfg_local"
124*fcf3ce44SJohn Forte #define	CFG_CLUSTER_LOCATION	"/etc/dscfg_cluster"
125*fcf3ce44SJohn Forte 
126*fcf3ce44SJohn Forte void cfg_close(CFGFILE *);
127*fcf3ce44SJohn Forte 
128*fcf3ce44SJohn Forte /*
129*fcf3ce44SJohn Forte  * lock mode
130*fcf3ce44SJohn Forte  */
131*fcf3ce44SJohn Forte typedef enum {
132*fcf3ce44SJohn Forte 	CFG_RDLOCK,
133*fcf3ce44SJohn Forte 	CFG_WRLOCK,
134*fcf3ce44SJohn Forte 	CFG_UPGRADE
135*fcf3ce44SJohn Forte } CFGLOCK;
136*fcf3ce44SJohn Forte 
137*fcf3ce44SJohn Forte int cfg_lock(CFGFILE *, CFGLOCK);	/* lock the configuration */
138*fcf3ce44SJohn Forte void cfp_unlock(cfp_t *);		/* unlock the configuration */
139*fcf3ce44SJohn Forte void cfg_unlock(CFGFILE *);
140*fcf3ce44SJohn Forte int cfg_get_lock(CFGFILE *, CFGLOCK *, pid_t *);	/* get config lock */
141*fcf3ce44SJohn Forte 
142*fcf3ce44SJohn Forte int cfg_commit(CFGFILE *);
143*fcf3ce44SJohn Forte void cfg_resource(CFGFILE *, const char *);	/* Set/clear cluster node */
144*fcf3ce44SJohn Forte char *cfg_get_resource(CFGFILE *);		/* get current cluster node */
145*fcf3ce44SJohn Forte char *cfg_dgname(const char *, char *, size_t);	/* parse dg from pathname */
146*fcf3ce44SJohn Forte char *cfg_l_dgname(const char *, char *, size_t); /* parse dg from pathname */
147*fcf3ce44SJohn Forte int cfg_dgname_islocal(char *, char **);	/* find locality of dg */
148*fcf3ce44SJohn Forte int cfg_iscluster(void);			/* running in a cluster? */
149*fcf3ce44SJohn Forte int cfg_issuncluster(void);			/* running in a Sun Cluster? */
150*fcf3ce44SJohn Forte void cfg_invalidate_sizes(int);
151*fcf3ce44SJohn Forte 
152*fcf3ce44SJohn Forte /*
153*fcf3ce44SJohn Forte  * add/rem result codes
154*fcf3ce44SJohn Forte  */
155*fcf3ce44SJohn Forte #define	CFG_USER_ERR 1
156*fcf3ce44SJohn Forte #define	CFG_USER_OK 2
157*fcf3ce44SJohn Forte #define	CFG_USER_FIRST 3
158*fcf3ce44SJohn Forte #define	CFG_USER_LAST 4
159*fcf3ce44SJohn Forte #define	CFG_USER_GONE 5
160*fcf3ce44SJohn Forte #define	CFG_USER_REPEAT 6
161*fcf3ce44SJohn Forte 
162*fcf3ce44SJohn Forte int cfg_add_user(CFGFILE *, char *, char *, char *);	/* add volume user */
163*fcf3ce44SJohn Forte int cfg_rem_user(CFGFILE *, char *, char *, char *);	/* remove vol user */
164*fcf3ce44SJohn Forte int cfg_vol_enable(CFGFILE *, char *, char *, char *);	/* enable volume */
165*fcf3ce44SJohn Forte int cfg_vol_disable(CFGFILE *, char *, char *, char *);	/* disable volume */
166*fcf3ce44SJohn Forte 
167*fcf3ce44SJohn Forte int cfg_load_dsvols(CFGFILE *);		/* load dsvol: section */
168*fcf3ce44SJohn Forte void cfg_unload_dsvols();		/* unload dsvol: section */
169*fcf3ce44SJohn Forte int cfg_load_svols(CFGFILE *);		/* load sv: section */
170*fcf3ce44SJohn Forte void cfg_unload_svols();		/* unload sv: section */
171*fcf3ce44SJohn Forte int cfg_load_shadows(CFGFILE *);	/* load shadows & bitmaps from ii: */
172*fcf3ce44SJohn Forte void cfg_unload_shadows();		/* unload ii: */
173*fcf3ce44SJohn Forte 
174*fcf3ce44SJohn Forte int cfg_get_canonical_name(CFGFILE *, const char *, char **);
175*fcf3ce44SJohn Forte 
176*fcf3ce44SJohn Forte #ifdef	__cplusplus
177*fcf3ce44SJohn Forte }
178*fcf3ce44SJohn Forte #endif
179*fcf3ce44SJohn Forte 
180*fcf3ce44SJohn Forte #endif /* _CFG_H */
181