17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*4c06356bSdh * Common Development and Distribution License (the "License").
6*4c06356bSdh * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*4c06356bSdh * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include "cfga_scsi.h"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #define MAX_FORMAT 80
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate static scfga_ret_t scsi_rcm_info_table(rcm_info_t *, char **);
317c478bd9Sstevel@tonic-gate static scfga_ret_t scsi_rcm_init(uint_t, char **, rcm_handle_t **);
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate * scsi_rcm_offline()
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate * Offline SCSI resource consumers.
377c478bd9Sstevel@tonic-gate */
387c478bd9Sstevel@tonic-gate scfga_ret_t
scsi_rcm_offline(char ** rsrclist,char ** errstring,cfga_flags_t flags)397c478bd9Sstevel@tonic-gate scsi_rcm_offline(char **rsrclist, char **errstring, cfga_flags_t flags)
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate int rret;
427c478bd9Sstevel@tonic-gate uint_t rflags = 0;
437c478bd9Sstevel@tonic-gate rcm_info_t *rinfo = NULL;
447c478bd9Sstevel@tonic-gate scfga_ret_t ret = SCFGA_OK;
457c478bd9Sstevel@tonic-gate rcm_handle_t *rcm_handle;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate if (rsrclist == NULL)
487c478bd9Sstevel@tonic-gate return (ret);
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate if ((ret = scsi_rcm_init(0, errstring, &rcm_handle))
517c478bd9Sstevel@tonic-gate != SCFGA_OK)
527c478bd9Sstevel@tonic-gate return (ret);
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate if (flags & CFGA_FLAG_FORCE)
557c478bd9Sstevel@tonic-gate rflags = RCM_FORCE;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate if ((rret = rcm_request_offline_list(rcm_handle, rsrclist, rflags,
587c478bd9Sstevel@tonic-gate &rinfo)) != RCM_SUCCESS) {
59*4c06356bSdh if ((flags & FLAG_CLIENT_DEV) == FLAG_CLIENT_DEV) {
60*4c06356bSdh cfga_err(errstring, 0, ERRARG_RCM_CLIENT_OFFLINE, 0);
61*4c06356bSdh } else {
62*4c06356bSdh cfga_err(errstring, 0, ERRARG_RCM_OFFLINE, 0);
63*4c06356bSdh }
647c478bd9Sstevel@tonic-gate if (rinfo) {
657c478bd9Sstevel@tonic-gate (void) scsi_rcm_info_table(rinfo, errstring);
667c478bd9Sstevel@tonic-gate rcm_free_info(rinfo);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate if (rret == RCM_FAILURE)
697c478bd9Sstevel@tonic-gate (void) rcm_notify_online_list(rcm_handle, rsrclist,
707c478bd9Sstevel@tonic-gate rflags & ~RCM_FORCE, NULL);
717c478bd9Sstevel@tonic-gate ret = SCFGA_BUSY;
727c478bd9Sstevel@tonic-gate }
73*4c06356bSdh (void) rcm_free_handle(rcm_handle);
747c478bd9Sstevel@tonic-gate return (ret);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * scsi_rcm_online()
797c478bd9Sstevel@tonic-gate *
807c478bd9Sstevel@tonic-gate * Online SCSI resource consumers that were previously offlined.
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
837c478bd9Sstevel@tonic-gate scfga_ret_t
scsi_rcm_online(char ** rsrclist,char ** errstring,cfga_flags_t flags)847c478bd9Sstevel@tonic-gate scsi_rcm_online(char **rsrclist, char **errstring, cfga_flags_t flags)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate rcm_info_t *rinfo = NULL;
877c478bd9Sstevel@tonic-gate scfga_ret_t ret = SCFGA_OK;
887c478bd9Sstevel@tonic-gate rcm_handle_t *rcm_handle;
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if (rsrclist == NULL)
917c478bd9Sstevel@tonic-gate return (ret);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate if ((ret = scsi_rcm_init(0, errstring, &rcm_handle))
947c478bd9Sstevel@tonic-gate != SCFGA_OK)
957c478bd9Sstevel@tonic-gate return (ret);
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate if (rcm_notify_online_list(rcm_handle, rsrclist, 0, &rinfo)
987c478bd9Sstevel@tonic-gate != RCM_SUCCESS) {
997c478bd9Sstevel@tonic-gate cfga_err(errstring, 0, ERRARG_RCM_ONLINE, 0);
1007c478bd9Sstevel@tonic-gate if (rinfo != NULL) {
1017c478bd9Sstevel@tonic-gate (void) scsi_rcm_info_table(rinfo, errstring);
1027c478bd9Sstevel@tonic-gate rcm_free_info(rinfo);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate ret = SCFGA_BUSY;
1057c478bd9Sstevel@tonic-gate }
106*4c06356bSdh (void) rcm_free_handle(rcm_handle);
1077c478bd9Sstevel@tonic-gate return (ret);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * scsi_rcm_remove()
1127c478bd9Sstevel@tonic-gate *
1137c478bd9Sstevel@tonic-gate * Remove SCSI resource consumers after their kernel removal.
1147c478bd9Sstevel@tonic-gate */
1157c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
1167c478bd9Sstevel@tonic-gate scfga_ret_t
scsi_rcm_remove(char ** rsrclist,char ** errstring,cfga_flags_t flags)1177c478bd9Sstevel@tonic-gate scsi_rcm_remove(char **rsrclist, char **errstring, cfga_flags_t flags)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate rcm_info_t *rinfo = NULL;
1207c478bd9Sstevel@tonic-gate scfga_ret_t ret = SCFGA_OK;
1217c478bd9Sstevel@tonic-gate rcm_handle_t *rcm_handle;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate if (rsrclist == NULL)
1247c478bd9Sstevel@tonic-gate return (ret);
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate if ((ret = scsi_rcm_init(0, errstring, &rcm_handle))
1277c478bd9Sstevel@tonic-gate != SCFGA_OK)
1287c478bd9Sstevel@tonic-gate return (ret);
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate if (rcm_notify_remove_list(rcm_handle, rsrclist, 0, &rinfo)
1317c478bd9Sstevel@tonic-gate != RCM_SUCCESS) {
1327c478bd9Sstevel@tonic-gate cfga_err(errstring, 0, ERRARG_RCM_REMOVE, 0);
1337c478bd9Sstevel@tonic-gate if (rinfo) {
1347c478bd9Sstevel@tonic-gate (void) scsi_rcm_info_table(rinfo, errstring);
1357c478bd9Sstevel@tonic-gate rcm_free_info(rinfo);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate ret = SCFGA_BUSY;
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
140*4c06356bSdh (void) rcm_free_handle(rcm_handle);
1417c478bd9Sstevel@tonic-gate return (ret);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * scsi_rcm_suspend()
1467c478bd9Sstevel@tonic-gate *
1477c478bd9Sstevel@tonic-gate * Suspend SCSI resource consumers before a bus quiesce.
1487c478bd9Sstevel@tonic-gate */
1497c478bd9Sstevel@tonic-gate scfga_ret_t
scsi_rcm_suspend(char ** rsrclist,char ** errstring,cfga_flags_t flags,int pflag)1507c478bd9Sstevel@tonic-gate scsi_rcm_suspend(char **rsrclist, char **errstring, cfga_flags_t flags,
1517c478bd9Sstevel@tonic-gate int pflag)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate int rret;
1547c478bd9Sstevel@tonic-gate uint_t rflags = 0;
1557c478bd9Sstevel@tonic-gate rcm_info_t *rinfo = NULL;
1567c478bd9Sstevel@tonic-gate scfga_ret_t ret = SCFGA_OK;
1577c478bd9Sstevel@tonic-gate rcm_handle_t *rcm_handle;
1587c478bd9Sstevel@tonic-gate timespec_t zerotime = { 0, 0 };
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate if (rsrclist == NULL)
1617c478bd9Sstevel@tonic-gate return (ret);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate pflag = pflag ? RCM_NOPID : 0;
1647c478bd9Sstevel@tonic-gate if ((ret = scsi_rcm_init(pflag, errstring, &rcm_handle))
1657c478bd9Sstevel@tonic-gate != SCFGA_OK)
1667c478bd9Sstevel@tonic-gate return (ret);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate if (flags & CFGA_FLAG_FORCE)
1697c478bd9Sstevel@tonic-gate rflags = RCM_FORCE;
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate * attempt a suspension on a list of resources
1737c478bd9Sstevel@tonic-gate */
1747c478bd9Sstevel@tonic-gate if ((rret = rcm_request_suspend_list(rcm_handle, rsrclist, rflags,
1757c478bd9Sstevel@tonic-gate &zerotime, &rinfo)) != RCM_SUCCESS) {
1767c478bd9Sstevel@tonic-gate cfga_err(errstring, 0, ERRARG_RCM_SUSPEND, 0);
1777c478bd9Sstevel@tonic-gate if (rinfo) {
1787c478bd9Sstevel@tonic-gate (void) scsi_rcm_info_table(rinfo, errstring);
1797c478bd9Sstevel@tonic-gate rcm_free_info(rinfo);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate if (rret == RCM_FAILURE)
1827c478bd9Sstevel@tonic-gate (void) rcm_notify_resume_list(rcm_handle, rsrclist,
1837c478bd9Sstevel@tonic-gate (rflags & (~RCM_FORCE)), NULL);
1847c478bd9Sstevel@tonic-gate ret = SCFGA_BUSY;
1857c478bd9Sstevel@tonic-gate }
186*4c06356bSdh (void) rcm_free_handle(rcm_handle);
1877c478bd9Sstevel@tonic-gate return (ret);
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate * scsi_rcm_resume()
1927c478bd9Sstevel@tonic-gate *
1937c478bd9Sstevel@tonic-gate * Resume SCSI resource consumers after a bus has been unquiesced.
1947c478bd9Sstevel@tonic-gate */
1957c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
1967c478bd9Sstevel@tonic-gate scfga_ret_t
scsi_rcm_resume(char ** rsrclist,char ** errstring,cfga_flags_t flags,int pflag)1977c478bd9Sstevel@tonic-gate scsi_rcm_resume(char **rsrclist, char **errstring, cfga_flags_t flags,
1987c478bd9Sstevel@tonic-gate int pflag)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate rcm_info_t *rinfo = NULL;
2017c478bd9Sstevel@tonic-gate scfga_ret_t ret = SCFGA_OK;
2027c478bd9Sstevel@tonic-gate rcm_handle_t *rcm_handle;
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate if (rsrclist == NULL)
2057c478bd9Sstevel@tonic-gate return (ret);
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate pflag = pflag ? RCM_NOPID : 0;
2087c478bd9Sstevel@tonic-gate if ((ret = scsi_rcm_init(pflag, errstring, &rcm_handle))
2097c478bd9Sstevel@tonic-gate != SCFGA_OK)
2107c478bd9Sstevel@tonic-gate return (ret);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate * resume the resource list.
2147c478bd9Sstevel@tonic-gate */
2157c478bd9Sstevel@tonic-gate if (rcm_notify_resume_list(rcm_handle, rsrclist, 0, &rinfo)
2167c478bd9Sstevel@tonic-gate != RCM_SUCCESS) {
2177c478bd9Sstevel@tonic-gate cfga_err(errstring, 0, ERRARG_RCM_RESUME, 0);
2187c478bd9Sstevel@tonic-gate if (rinfo != NULL) {
2197c478bd9Sstevel@tonic-gate (void) scsi_rcm_info_table(rinfo, errstring);
2207c478bd9Sstevel@tonic-gate rcm_free_info(rinfo);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate ret = SCFGA_BUSY;
2237c478bd9Sstevel@tonic-gate }
224*4c06356bSdh (void) rcm_free_handle(rcm_handle);
2257c478bd9Sstevel@tonic-gate return (ret);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate * scsi_rcm_init()
2307c478bd9Sstevel@tonic-gate *
2317c478bd9Sstevel@tonic-gate * Contains common initialization code for entering a scsi_rcm_xx()
2327c478bd9Sstevel@tonic-gate * routine.
2337c478bd9Sstevel@tonic-gate */
2347c478bd9Sstevel@tonic-gate static scfga_ret_t
scsi_rcm_init(uint_t rcm_flag,char ** errstring,rcm_handle_t ** hdlp)2357c478bd9Sstevel@tonic-gate scsi_rcm_init(uint_t rcm_flag, char **errstring, rcm_handle_t **hdlp)
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate /* Get a handle for the RCM operations */
2387c478bd9Sstevel@tonic-gate if (rcm_alloc_handle(NULL, rcm_flag, NULL, hdlp) != RCM_SUCCESS) {
2397c478bd9Sstevel@tonic-gate cfga_err(errstring, 0, ERR_RCM_HANDLE, 0);
2407c478bd9Sstevel@tonic-gate return (SCFGA_LIB_ERR);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate return (SCFGA_OK);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate * scsi_rcm_info_table
2487c478bd9Sstevel@tonic-gate *
2497c478bd9Sstevel@tonic-gate * Takes an opaque rcm_info_t pointer and a character pointer, and appends
2507c478bd9Sstevel@tonic-gate * the rcm_info_t data in the form of a table to the given character pointer.
2517c478bd9Sstevel@tonic-gate */
2527c478bd9Sstevel@tonic-gate static scfga_ret_t
scsi_rcm_info_table(rcm_info_t * rinfo,char ** table)2537c478bd9Sstevel@tonic-gate scsi_rcm_info_table(rcm_info_t *rinfo, char **table)
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate int i;
2567c478bd9Sstevel@tonic-gate size_t w;
2577c478bd9Sstevel@tonic-gate size_t width = 0;
2587c478bd9Sstevel@tonic-gate size_t w_rsrc = 0;
2597c478bd9Sstevel@tonic-gate size_t w_info = 0;
2607c478bd9Sstevel@tonic-gate size_t table_size = 0;
2617c478bd9Sstevel@tonic-gate uint_t tuples = 0;
2627c478bd9Sstevel@tonic-gate rcm_info_tuple_t *tuple = NULL;
2637c478bd9Sstevel@tonic-gate char *rsrc;
2647c478bd9Sstevel@tonic-gate char *info;
2657c478bd9Sstevel@tonic-gate char *newtable;
2667c478bd9Sstevel@tonic-gate static char format[MAX_FORMAT];
2677c478bd9Sstevel@tonic-gate const char *infostr;
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate /* Protect against invalid arguments */
2707c478bd9Sstevel@tonic-gate if (rinfo == NULL || table == NULL)
2717c478bd9Sstevel@tonic-gate return (SCFGA_ERR);
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate /* Set localized table header strings */
2747c478bd9Sstevel@tonic-gate rsrc = dgettext(TEXT_DOMAIN, "Resource");
2757c478bd9Sstevel@tonic-gate info = dgettext(TEXT_DOMAIN, "Information");
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate /* A first pass, to size up the RCM information */
2787c478bd9Sstevel@tonic-gate while (tuple = rcm_info_next(rinfo, tuple)) {
2797c478bd9Sstevel@tonic-gate if ((infostr = rcm_info_info(tuple)) != NULL) {
2807c478bd9Sstevel@tonic-gate tuples++;
2817c478bd9Sstevel@tonic-gate if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
2827c478bd9Sstevel@tonic-gate w_rsrc = w;
2837c478bd9Sstevel@tonic-gate if ((w = strlen(infostr)) > w_info)
2847c478bd9Sstevel@tonic-gate w_info = w;
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate /* If nothing was sized up above, stop early */
2897c478bd9Sstevel@tonic-gate if (tuples == 0)
2907c478bd9Sstevel@tonic-gate return (SCFGA_OK);
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate /* Adjust column widths for column headings */
2937c478bd9Sstevel@tonic-gate if ((w = strlen(rsrc)) > w_rsrc)
2947c478bd9Sstevel@tonic-gate w_rsrc = w;
2957c478bd9Sstevel@tonic-gate else if ((w_rsrc - w) % 2)
2967c478bd9Sstevel@tonic-gate w_rsrc++;
2977c478bd9Sstevel@tonic-gate if ((w = strlen(info)) > w_info)
2987c478bd9Sstevel@tonic-gate w_info = w;
2997c478bd9Sstevel@tonic-gate else if ((w_info - w) % 2)
3007c478bd9Sstevel@tonic-gate w_info++;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate * Compute the total line width of each line,
3047c478bd9Sstevel@tonic-gate * accounting for intercolumn spacing.
3057c478bd9Sstevel@tonic-gate */
3067c478bd9Sstevel@tonic-gate width = w_info + w_rsrc + 4;
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate /* Allocate space for the table */
3097c478bd9Sstevel@tonic-gate table_size = (2 + tuples) * (width + 1) + 2;
3107c478bd9Sstevel@tonic-gate if (*table == NULL) {
3117c478bd9Sstevel@tonic-gate /* zero fill for the strcat() call below */
3127c478bd9Sstevel@tonic-gate *table = calloc(table_size, sizeof (char));
3137c478bd9Sstevel@tonic-gate if (*table == NULL)
3147c478bd9Sstevel@tonic-gate return (SCFGA_ERR);
3157c478bd9Sstevel@tonic-gate } else {
3167c478bd9Sstevel@tonic-gate newtable = realloc(*table, strlen(*table) + table_size);
3177c478bd9Sstevel@tonic-gate if (newtable == NULL)
3187c478bd9Sstevel@tonic-gate return (SCFGA_ERR);
3197c478bd9Sstevel@tonic-gate else
3207c478bd9Sstevel@tonic-gate *table = newtable;
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate /* Place a table header into the string */
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate /* The resource header */
3267c478bd9Sstevel@tonic-gate (void) strcat(*table, "\n");
3277c478bd9Sstevel@tonic-gate w = strlen(rsrc);
3287c478bd9Sstevel@tonic-gate for (i = 0; i < ((w_rsrc - w) / 2); i++)
3297c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3307c478bd9Sstevel@tonic-gate (void) strcat(*table, rsrc);
3317c478bd9Sstevel@tonic-gate for (i = 0; i < ((w_rsrc - w) / 2); i++)
3327c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /* The information header */
3357c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3367c478bd9Sstevel@tonic-gate w = strlen(info);
3377c478bd9Sstevel@tonic-gate for (i = 0; i < ((w_info - w) / 2); i++)
3387c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3397c478bd9Sstevel@tonic-gate (void) strcat(*table, info);
3407c478bd9Sstevel@tonic-gate for (i = 0; i < ((w_info - w) / 2); i++)
3417c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate /* Underline the headers */
3447c478bd9Sstevel@tonic-gate (void) strcat(*table, "\n");
3457c478bd9Sstevel@tonic-gate for (i = 0; i < w_rsrc; i++)
3467c478bd9Sstevel@tonic-gate (void) strcat(*table, "-");
3477c478bd9Sstevel@tonic-gate (void) strcat(*table, " ");
3487c478bd9Sstevel@tonic-gate for (i = 0; i < w_info; i++)
3497c478bd9Sstevel@tonic-gate (void) strcat(*table, "-");
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate /* Construct the format string */
3527c478bd9Sstevel@tonic-gate (void) snprintf(format, MAX_FORMAT, "%%-%ds %%-%ds",
3537c478bd9Sstevel@tonic-gate (int)w_rsrc, (int)w_info);
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /* Add the tuples to the table string */
3567c478bd9Sstevel@tonic-gate tuple = NULL;
3577c478bd9Sstevel@tonic-gate while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
3587c478bd9Sstevel@tonic-gate if ((infostr = rcm_info_info(tuple)) != NULL) {
3597c478bd9Sstevel@tonic-gate (void) strcat(*table, "\n");
3607c478bd9Sstevel@tonic-gate (void) sprintf(&((*table)[strlen(*table)]),
3617c478bd9Sstevel@tonic-gate format, rcm_info_rsrc(tuple),
3627c478bd9Sstevel@tonic-gate infostr);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate return (SCFGA_OK);
3677c478bd9Sstevel@tonic-gate }
368