xref: /onnv-gate/usr/src/lib/cfgadm_plugins/ib/common/cfga_rcm.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #include "cfga_ib.h"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #define	MAX_FORMAT	80	/* for info table */
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate cfga_ib_ret_t		ib_rcm_offline(const char *, char **, char *,
36*0Sstevel@tonic-gate 			    cfga_flags_t);
37*0Sstevel@tonic-gate cfga_ib_ret_t		ib_rcm_online(const char *, char **, char *,
38*0Sstevel@tonic-gate 			    cfga_flags_t);
39*0Sstevel@tonic-gate cfga_ib_ret_t		ib_rcm_remove(const char *, char **, char *,
40*0Sstevel@tonic-gate 			    cfga_flags_t);
41*0Sstevel@tonic-gate static cfga_ib_ret_t 	ib_rcm_info_table(rcm_info_t *, char **);
42*0Sstevel@tonic-gate static cfga_ib_ret_t 	ib_rcm_init(const char *, cfga_flags_t, char **,
43*0Sstevel@tonic-gate 			    uint_t *);
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate static rcm_handle_t *rcm_handle = NULL;
47*0Sstevel@tonic-gate static mutex_t rcm_handle_lock = DEFAULTMUTEX;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate  * Function:
52*0Sstevel@tonic-gate  *	ib_rcm_offline
53*0Sstevel@tonic-gate  * Input:
54*0Sstevel@tonic-gate  *	rsrc		- Resource name (typically an ap_id)
55*0Sstevel@tonic-gate  *	errstring	- Error message filled in case of a failure
56*0Sstevel@tonic-gate  *	rsrc_fixed	- Pointer to fixed path
57*0Sstevel@tonic-gate  *	flags		- flags to RCM
58*0Sstevel@tonic-gate  * Output:
59*0Sstevel@tonic-gate  *	NONE
60*0Sstevel@tonic-gate  * Returns:
61*0Sstevel@tonic-gate  *	CFGA_IB_OK on success or an appropriate error
62*0Sstevel@tonic-gate  * Description:
63*0Sstevel@tonic-gate  *	Offline IB resource consumers.
64*0Sstevel@tonic-gate  */
65*0Sstevel@tonic-gate cfga_ib_ret_t
ib_rcm_offline(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)66*0Sstevel@tonic-gate ib_rcm_offline(const char *rsrc, char **errstring, char *rsrc_fixed,
67*0Sstevel@tonic-gate     cfga_flags_t flags)
68*0Sstevel@tonic-gate {
69*0Sstevel@tonic-gate 	int		rret;
70*0Sstevel@tonic-gate 	uint_t		rflags = 0;
71*0Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
72*0Sstevel@tonic-gate 	cfga_ib_ret_t	ret = CFGA_IB_OK;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_offline:\n");
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate 	if ((ret = ib_rcm_init(rsrc, flags, errstring, &rflags)) !=
77*0Sstevel@tonic-gate 	    CFGA_IB_OK) {
78*0Sstevel@tonic-gate 		return (ret);
79*0Sstevel@tonic-gate 	}
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_offline: rsrc_fixed: %s\n", rsrc_fixed);
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate 	if ((rret = rcm_request_offline(rcm_handle, rsrc_fixed, rflags, &rinfo))
84*0Sstevel@tonic-gate 	    != RCM_SUCCESS) {
85*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_offline: rcm_request_offline failed\n");
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 		if (rinfo) {
88*0Sstevel@tonic-gate 			(void) ib_rcm_info_table(rinfo, errstring);
89*0Sstevel@tonic-gate 			rcm_free_info(rinfo);
90*0Sstevel@tonic-gate 			rinfo = NULL;
91*0Sstevel@tonic-gate 		}
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_offline: table = %s\n", *errstring);
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 		if (rret == RCM_FAILURE) {
96*0Sstevel@tonic-gate 			(void) ib_rcm_online(rsrc, errstring,
97*0Sstevel@tonic-gate 			    rsrc_fixed, flags);
98*0Sstevel@tonic-gate 		}
99*0Sstevel@tonic-gate 		ret = CFGA_IB_RCM_OFFLINE_ERR;
100*0Sstevel@tonic-gate 	}
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	return (ret);
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /*
107*0Sstevel@tonic-gate  * Function:
108*0Sstevel@tonic-gate  *	ib_rcm_online
109*0Sstevel@tonic-gate  * Input:
110*0Sstevel@tonic-gate  *	rsrc		- Resource name (typically an ap_id)
111*0Sstevel@tonic-gate  *	errstring	- Error message filled in case of a failure
112*0Sstevel@tonic-gate  *	rsrc_fixed	- Pointer to fixed path
113*0Sstevel@tonic-gate  *	flags		- flags to RCM
114*0Sstevel@tonic-gate  * Output:
115*0Sstevel@tonic-gate  *	NONE
116*0Sstevel@tonic-gate  * Returns:
117*0Sstevel@tonic-gate  *	CFGA_IB_OK on success or an appropriate error
118*0Sstevel@tonic-gate  * Description:
119*0Sstevel@tonic-gate  *	Online IB resource consumers that were previously offlined.
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate cfga_ib_ret_t
ib_rcm_online(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)122*0Sstevel@tonic-gate ib_rcm_online(const char *rsrc, char **errstring, char *rsrc_fixed,
123*0Sstevel@tonic-gate     cfga_flags_t flags)
124*0Sstevel@tonic-gate {
125*0Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
126*0Sstevel@tonic-gate 	cfga_ib_ret_t	ret = CFGA_IB_OK;
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_online:\n");
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate 	if ((ret = ib_rcm_init(rsrc, flags, errstring, NULL)) != CFGA_IB_OK) {
131*0Sstevel@tonic-gate 		return (ret);
132*0Sstevel@tonic-gate 	}
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	if (rcm_notify_online(rcm_handle, rsrc_fixed, 0, &rinfo) !=
135*0Sstevel@tonic-gate 	    RCM_SUCCESS && (rinfo != NULL)) {
136*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_online: rcm_notify_online failed\n");
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 		(void) ib_rcm_info_table(rinfo, errstring);
139*0Sstevel@tonic-gate 		rcm_free_info(rinfo);
140*0Sstevel@tonic-gate 		rinfo = NULL;
141*0Sstevel@tonic-gate 		ret = CFGA_IB_RCM_ONLINE_ERR;
142*0Sstevel@tonic-gate 	}
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 	return (ret);
145*0Sstevel@tonic-gate }
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate /*
149*0Sstevel@tonic-gate  * Function:
150*0Sstevel@tonic-gate  *	ib_rcm_remove
151*0Sstevel@tonic-gate  * Input:
152*0Sstevel@tonic-gate  *	rsrc		- Resource name (typically an ap_id)
153*0Sstevel@tonic-gate  *	errstring	- Error message filled in case of a failure
154*0Sstevel@tonic-gate  *	rsrc_fixed	- Pointer to fixed path
155*0Sstevel@tonic-gate  *	flags		- flags to RCM
156*0Sstevel@tonic-gate  * Output:
157*0Sstevel@tonic-gate  *	NONE
158*0Sstevel@tonic-gate  * Returns:
159*0Sstevel@tonic-gate  *	CFGA_IB_OK on success or an appropriate error
160*0Sstevel@tonic-gate  * Description:
161*0Sstevel@tonic-gate  *	Remove IB resource consumers after their kernel removal.
162*0Sstevel@tonic-gate  */
163*0Sstevel@tonic-gate cfga_ib_ret_t
ib_rcm_remove(const char * rsrc,char ** errstring,char * rsrc_fixed,cfga_flags_t flags)164*0Sstevel@tonic-gate ib_rcm_remove(const char *rsrc, char **errstring, char *rsrc_fixed,
165*0Sstevel@tonic-gate     cfga_flags_t flags)
166*0Sstevel@tonic-gate {
167*0Sstevel@tonic-gate 	rcm_info_t	*rinfo = NULL;
168*0Sstevel@tonic-gate 	cfga_ib_ret_t	ret = CFGA_IB_OK;
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_remove:\n");
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate 	if ((ret = ib_rcm_init(rsrc, flags, errstring, NULL)) != CFGA_IB_OK) {
173*0Sstevel@tonic-gate 		return (ret);
174*0Sstevel@tonic-gate 	}
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 	if (rcm_notify_remove(rcm_handle, rsrc_fixed, 0, &rinfo) !=
177*0Sstevel@tonic-gate 	    RCM_SUCCESS && (rinfo != NULL)) {
178*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_remove: rcm_notify_remove failed\n");
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate 		(void) ib_rcm_info_table(rinfo, errstring);
181*0Sstevel@tonic-gate 		rcm_free_info(rinfo);
182*0Sstevel@tonic-gate 		rinfo = NULL;
183*0Sstevel@tonic-gate 		ret = CFGA_IB_RCM_ONLINE_ERR;
184*0Sstevel@tonic-gate 	}
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	return (ret);
187*0Sstevel@tonic-gate }
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate /*
191*0Sstevel@tonic-gate  * Function:
192*0Sstevel@tonic-gate  *	ib_rcm_init
193*0Sstevel@tonic-gate  * Input:
194*0Sstevel@tonic-gate  *	rsrc		- Resource name (typically an ap_id)
195*0Sstevel@tonic-gate  *	flags		- flags to RCM
196*0Sstevel@tonic-gate  *	errstring	- Error message filled in case of a failure
197*0Sstevel@tonic-gate  *	rflags		- Flags filled up in case of a failure
198*0Sstevel@tonic-gate  * Output:
199*0Sstevel@tonic-gate  *	NONE
200*0Sstevel@tonic-gate  * Returns:
201*0Sstevel@tonic-gate  *	CFGA_IB_OK on success or an appropriate error
202*0Sstevel@tonic-gate  * Description:
203*0Sstevel@tonic-gate  *	Contains common initialization code for entering a ib_rcm_xx() routine.
204*0Sstevel@tonic-gate  */
205*0Sstevel@tonic-gate /* ARGSUSED */
206*0Sstevel@tonic-gate static cfga_ib_ret_t
ib_rcm_init(const char * rsrc,cfga_flags_t flags,char ** errstring,uint_t * rflags)207*0Sstevel@tonic-gate ib_rcm_init(const char *rsrc, cfga_flags_t flags, char **errstring,
208*0Sstevel@tonic-gate     uint_t *rflags)
209*0Sstevel@tonic-gate {
210*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_init:\n");
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate 	/* Validate the rsrc argument */
213*0Sstevel@tonic-gate 	if (rsrc == NULL) {
214*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_init: rsrc is NULL\n");
215*0Sstevel@tonic-gate 		return (CFGA_IB_INTERNAL_ERR);
216*0Sstevel@tonic-gate 	}
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate 	/* Translate the cfgadm flags to RCM flags */
219*0Sstevel@tonic-gate 	if (rflags && (flags & CFGA_FLAG_FORCE)) {
220*0Sstevel@tonic-gate 		*rflags |= RCM_FORCE;
221*0Sstevel@tonic-gate 	}
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate 	/* Get a handle for the RCM operations */
224*0Sstevel@tonic-gate 	(void) mutex_lock(&rcm_handle_lock);
225*0Sstevel@tonic-gate 	if (rcm_handle == NULL) {
226*0Sstevel@tonic-gate 		if (rcm_alloc_handle(NULL, RCM_NOPID, NULL, &rcm_handle) !=
227*0Sstevel@tonic-gate 		    RCM_SUCCESS) {
228*0Sstevel@tonic-gate 			DPRINTF("ib_rcm_init: alloc_handle failed\n");
229*0Sstevel@tonic-gate 			(void) mutex_unlock(&rcm_handle_lock);
230*0Sstevel@tonic-gate 			return (CFGA_IB_RCM_HANDLE_ERR);
231*0Sstevel@tonic-gate 		}
232*0Sstevel@tonic-gate 	}
233*0Sstevel@tonic-gate 	(void) mutex_unlock(&rcm_handle_lock);
234*0Sstevel@tonic-gate 	return (CFGA_IB_OK);
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate /*
239*0Sstevel@tonic-gate  * Function:
240*0Sstevel@tonic-gate  *	ib_rcm_info_table
241*0Sstevel@tonic-gate  * Input:
242*0Sstevel@tonic-gate  *	rinfo		- Resource information
243*0Sstevel@tonic-gate  *	table		- table to be printed
244*0Sstevel@tonic-gate  * Output:
245*0Sstevel@tonic-gate  *	NONE
246*0Sstevel@tonic-gate  * Returns:
247*0Sstevel@tonic-gate  *	CFGA_IB_OK on success or an appropriate error
248*0Sstevel@tonic-gate  * Description:
249*0Sstevel@tonic-gate  *	Takes an opaque rcm_info_t pointer and a character pointer,
250*0Sstevel@tonic-gate  *	and appends the rcm_info_t data in the form of a table to the
251*0Sstevel@tonic-gate  *	given character pointer.
252*0Sstevel@tonic-gate  */
253*0Sstevel@tonic-gate static cfga_ib_ret_t
ib_rcm_info_table(rcm_info_t * rinfo,char ** table)254*0Sstevel@tonic-gate ib_rcm_info_table(rcm_info_t *rinfo, char **table)
255*0Sstevel@tonic-gate {
256*0Sstevel@tonic-gate 	int i;
257*0Sstevel@tonic-gate 	size_t w;
258*0Sstevel@tonic-gate 	size_t width = 0;
259*0Sstevel@tonic-gate 	size_t w_rsrc = 0;
260*0Sstevel@tonic-gate 	size_t w_info = 0;
261*0Sstevel@tonic-gate 	size_t table_size = 0;
262*0Sstevel@tonic-gate 	uint_t tuples = 0;
263*0Sstevel@tonic-gate 	rcm_info_tuple_t *tuple = NULL;
264*0Sstevel@tonic-gate 	char *rsrc;
265*0Sstevel@tonic-gate 	char *info;
266*0Sstevel@tonic-gate 	char *newtable;
267*0Sstevel@tonic-gate 	static char format[MAX_FORMAT];
268*0Sstevel@tonic-gate 	const char *infostr;
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate 	DPRINTF("ib_rcm_info_table:\n");
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate 	/* Protect against invalid arguments */
273*0Sstevel@tonic-gate 	if (rinfo == NULL || table == NULL) {
274*0Sstevel@tonic-gate 		return (CFGA_IB_INTERNAL_ERR);
275*0Sstevel@tonic-gate 	}
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 	/* Set localized table header strings */
278*0Sstevel@tonic-gate 	rsrc = dgettext(TEXT_DOMAIN, "Resource");
279*0Sstevel@tonic-gate 	info = dgettext(TEXT_DOMAIN, "Information");
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 	/* A first pass, to size up the RCM information */
282*0Sstevel@tonic-gate 	while (tuple = rcm_info_next(rinfo, tuple)) {
283*0Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
284*0Sstevel@tonic-gate 			tuples++;
285*0Sstevel@tonic-gate 			if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
286*0Sstevel@tonic-gate 				w_rsrc = w;
287*0Sstevel@tonic-gate 			if ((w = strlen(infostr)) > w_info)
288*0Sstevel@tonic-gate 				w_info = w;
289*0Sstevel@tonic-gate 		}
290*0Sstevel@tonic-gate 	}
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate 	/* If nothing was sized up above, stop early */
293*0Sstevel@tonic-gate 	if (tuples == 0) {
294*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_info_table: no tuples\n");
295*0Sstevel@tonic-gate 		return (CFGA_IB_OK);
296*0Sstevel@tonic-gate 	}
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 	/* Adjust column widths for column headings */
299*0Sstevel@tonic-gate 	if ((w = strlen(rsrc)) > w_rsrc) {
300*0Sstevel@tonic-gate 		w_rsrc = w;
301*0Sstevel@tonic-gate 	} else if ((w_rsrc - w) % 2) {
302*0Sstevel@tonic-gate 		w_rsrc++;
303*0Sstevel@tonic-gate 	}
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate 	if ((w = strlen(info)) > w_info) {
306*0Sstevel@tonic-gate 		w_info = w;
307*0Sstevel@tonic-gate 	} else if ((w_info - w) % 2) {
308*0Sstevel@tonic-gate 		w_info++;
309*0Sstevel@tonic-gate 	}
310*0Sstevel@tonic-gate 
311*0Sstevel@tonic-gate 	/*
312*0Sstevel@tonic-gate 	 * Compute the total line width of each line,
313*0Sstevel@tonic-gate 	 * accounting for intercolumn spacing.
314*0Sstevel@tonic-gate 	 */
315*0Sstevel@tonic-gate 	width = w_info + w_rsrc + 4;
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	/* Allocate space for the table */
318*0Sstevel@tonic-gate 	table_size = (2 + tuples) * (width + 1) + 2;
319*0Sstevel@tonic-gate 	if (*table == NULL) {
320*0Sstevel@tonic-gate 		*table = malloc(table_size);
321*0Sstevel@tonic-gate 	} else {
322*0Sstevel@tonic-gate 		newtable = realloc(*table, strlen(*table) + table_size);
323*0Sstevel@tonic-gate 		if (newtable != NULL)
324*0Sstevel@tonic-gate 			*table = newtable;
325*0Sstevel@tonic-gate 		else {
326*0Sstevel@tonic-gate 			free(*table);
327*0Sstevel@tonic-gate 			*table = NULL;
328*0Sstevel@tonic-gate 			return (CFGA_IB_ALLOC_FAIL);
329*0Sstevel@tonic-gate 		}
330*0Sstevel@tonic-gate 	}
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	if (*table == NULL) {
333*0Sstevel@tonic-gate 		DPRINTF("ib_rcm_info_table: no table\n");
334*0Sstevel@tonic-gate 		return (CFGA_IB_ALLOC_FAIL);
335*0Sstevel@tonic-gate 	}
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 	/* Place a table header into the string */
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate 	/* The resource header */
340*0Sstevel@tonic-gate 	(void) strlcat(*table, "\n", sizeof (*table));
341*0Sstevel@tonic-gate 	w = strlen(rsrc);
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++) {
344*0Sstevel@tonic-gate 		(void) strcat(*table, " ");
345*0Sstevel@tonic-gate 	}
346*0Sstevel@tonic-gate 	(void) strlcat(*table, rsrc, sizeof (*table));
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 	for (i = 0; i < ((w_rsrc - w) / 2); i++) {
349*0Sstevel@tonic-gate 		(void) strcat(*table, " ");
350*0Sstevel@tonic-gate 	}
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	/* The information header */
353*0Sstevel@tonic-gate 	(void) strcat(*table, "  ");
354*0Sstevel@tonic-gate 	w = strlen(info);
355*0Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++) {
356*0Sstevel@tonic-gate 		(void) strcat(*table, " ");
357*0Sstevel@tonic-gate 	}
358*0Sstevel@tonic-gate 	(void) strlcat(*table, info, sizeof (*table));
359*0Sstevel@tonic-gate 
360*0Sstevel@tonic-gate 	for (i = 0; i < ((w_info - w) / 2); i++) {
361*0Sstevel@tonic-gate 		(void) strcat(*table, " ");
362*0Sstevel@tonic-gate 	}
363*0Sstevel@tonic-gate 
364*0Sstevel@tonic-gate 	(void) strcat(*table, "\n");
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 	/* Underline the headers */
367*0Sstevel@tonic-gate 	for (i = 0; i < w_rsrc; i++) {
368*0Sstevel@tonic-gate 		(void) strcat(*table, "-");
369*0Sstevel@tonic-gate 	}
370*0Sstevel@tonic-gate 
371*0Sstevel@tonic-gate 	(void) strcat(*table, "  ");
372*0Sstevel@tonic-gate 	for (i = 0; i < w_info; i++) {
373*0Sstevel@tonic-gate 		(void) strcat(*table, "-");
374*0Sstevel@tonic-gate 	}
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	(void) strcat(*table, "\n");
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate 	/* Construct the format string */
379*0Sstevel@tonic-gate 	(void) snprintf(format, MAX_FORMAT, "%%-%ds  %%-%ds",
380*0Sstevel@tonic-gate 	    (int)w_rsrc, (int)w_info);
381*0Sstevel@tonic-gate 
382*0Sstevel@tonic-gate 	/* Add the tuples to the table string */
383*0Sstevel@tonic-gate 	tuple = NULL;
384*0Sstevel@tonic-gate 	while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
385*0Sstevel@tonic-gate 		if ((infostr = rcm_info_info(tuple)) != NULL) {
386*0Sstevel@tonic-gate 			(void) sprintf(&((*table)[strlen(*table)]),
387*0Sstevel@tonic-gate 			    format, rcm_info_rsrc(tuple), infostr);
388*0Sstevel@tonic-gate 			(void) strcat(*table, "\n");
389*0Sstevel@tonic-gate 		}
390*0Sstevel@tonic-gate 	}
391*0Sstevel@tonic-gate 
392*0Sstevel@tonic-gate 	return (CFGA_IB_OK);
393*0Sstevel@tonic-gate }
394