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