xref: /illumos-gate/usr/src/cmd/cfgadm/cfgadm.h (revision 2a8bcb4e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1998-1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_CFGADM_H
28 #define	_CFGADM_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * Command line options
36  */
37 #define	OPTIONS		"ac:fhlno:s:tx:vy"
38 
39 /*
40  * Configuration operations
41  */
42 typedef enum {
43 	CFGA_OP_NONE = 0,
44 	CFGA_OP_CHANGE_STATE,
45 	CFGA_OP_TEST,
46 	CFGA_OP_LIST,
47 	CFGA_OP_PRIVATE,
48 	CFGA_OP_HELP
49 } cfga_op_t;
50 
51 /*
52  * Names for -c functions
53  */
54 static char *state_opts[] = {
55 	"",
56 	"insert",
57 	"remove",
58 	"connect",
59 	"disconnect",
60 	"configure",
61 	"unconfigure",
62 	NULL
63 };
64 
65 /*
66  * Attachment point specifier types.
67  */
68 typedef enum {
69 	UNKNOWN_AP,
70 	LOGICAL_AP_ID,
71 	PHYSICAL_AP_ID,
72 	AP_TYPE
73 } cfga_ap_types_t;
74 
75 /*
76  * Confirm values.
77  */
78 enum confirm { CONFIRM_DEFAULT, CONFIRM_NO, CONFIRM_YES };
79 
80 /* Limit size of sysinfo return */
81 #define	SYSINFO_LENGTH	256
82 #define	YESNO_STR_MAX	127
83 
84 /* exit codes */
85 #define	EXIT_OK		0
86 #define	EXIT_OPFAILED	1
87 #define	EXIT_NOTSUPP	2
88 #define	EXIT_ARGERROR	3
89 
90 /* Macro to figure size of cfga_list_data items */
91 #define	SZ_EL(EL)	(sizeof ((struct cfga_list_data *)NULL)->EL)
92 
93 /* Maximum number of fields in cfgadm output */
94 #define	N_FIELDS	(sizeof (all_fields)/sizeof (all_fields[0]))
95 
96 /* printing format controls */
97 #define	DEF_SORT_FIELDS		"ap_id"
98 
99 #define	DEF_COLS		"ap_id:type:r_state:o_state:condition"
100 #define	DEF_COLS2		NULL
101 #define	DEF_COLS_VERBOSE	"ap_id:r_state:o_state:condition:info"
102 #define	DEF_COLS2_VERBOSE	"status_time:type:busy:physid"
103 #define	DEF_DELIM		" "
104 
105 /* listing field delimiter */
106 #define	FDELIM		':'
107 #define	ARG_DELIM	' '
108 
109 /* listing lengths for various fields */
110 #define	STATE_WIDTH	12	/* longest - "disconnected" */
111 #define	COND_WIDTH	10	/* longest is the heading - "condition" */
112 #define	TIME_WIDTH	12
113 #define	TIME_P_WIDTH	14	/* YYYYMMDDhhmmss */
114 /*	Date and time	formats	*/
115 /*
116  * b --- abbreviated month name
117  * e --- day number
118  * Y --- year in the form ccyy
119  * H --- hour(24-hour version)
120  * M --- minute
121  */
122 #define	FORMAT1	 "%b %e  %Y"
123 #define	FORMAT2  "%b %e %H:%M"
124 
125 /* listing control data */
126 struct sort_el {
127 	int reverse;
128 	struct field_info *fld;
129 };
130 
131 struct print_col {
132 	int width;
133 	struct field_info *line1;
134 	struct field_info *line2;
135 };
136 
137 /*
138  * The first three types are used for filtering and the last for sorting.
139  */
140 typedef enum {
141 	CFGA_MATCH_PARTIAL,	/* pass if a partial match */
142 	CFGA_MATCH_EXACT,	/* pass only if an exact match */
143 	CFGA_MATCH_NOFILTER,	/* pass all. Not valid user input */
144 	CFGA_MATCH_ORDER	/* compare and return relative order */
145 } match_type_t;
146 
147 struct field_info {
148 	char *name;
149 	char *heading;
150 	int width;
151 	int (*compare)(struct cfga_list_data *, struct cfga_list_data *,
152 	    match_type_t);
153 	void (*printfn)(struct cfga_list_data *, int, char *);
154 	cfga_err_t (*set_filter)(struct cfga_list_data *, const char *);
155 };
156 
157 /* list option strings */
158 static char *list_options[] = {
159 #define	LIST_SORT	0
160 	"sort",
161 #define	LIST_COLS	1
162 	"cols",
163 #define	LIST_COLS2	2
164 	"cols2",
165 #define	LIST_DELIM	3
166 	"delim",
167 #define	LIST_NOHEADINGS	4
168 	"noheadings",
169 #define	LIST_SELECT	5
170 	"select",
171 #define	LIST_MATCH	6
172 	"match",
173 	NULL
174 };
175 
176 /* Selection related */
177 typedef struct {
178 	char *arg;
179 	int resp; /* If set, this cmd arg received a response */
180 } ap_arg_t;
181 
182 typedef struct {
183 	cfga_list_data_t *ldatap;
184 	int req; /* If set, this list_data was requested by user */
185 } ap_out_t;
186 
187 /* Filtering related */
188 #define	CFGA_DEFAULT_MATCH	CFGA_MATCH_EXACT
189 #define	LEFT_PAREN	'('
190 #define	RIGHT_PAREN	')'
191 #define	CFGA_DEV_DIR	"/dev/cfg"
192 #define	SLASH		"/"
193 #define	EQUALS		"="
194 
195 typedef enum {
196 	CFGA_PSTATE_INIT,
197 	CFGA_PSTATE_ATTR_DONE,
198 	CFGA_PSTATE_VAL_DONE,
199 	CFGA_PSTATE_ERR
200 } parse_state_t;
201 
202 typedef struct match_cvt {
203 	char *str;
204 	match_type_t type;
205 } match_cvt_t;
206 
207 #ifdef	__cplusplus
208 }
209 #endif
210 
211 #endif	/* _CFGADM_H */
212