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