xref: /titanic_51/usr/src/cmd/prtconf/prtconf.c (revision c3a9724da5c6e77268b3f725df640f2848b1ebf8)
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*c3a9724dSVikram Hegde  * Common Development and Distribution License (the "License").
6*c3a9724dSVikram Hegde  * 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*c3a9724dSVikram Hegde  * 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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <stdarg.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <strings.h>
357c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/stat.h>
387c478bd9Sstevel@tonic-gate #include "prtconf.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate struct prt_opts	opts;
417c478bd9Sstevel@tonic-gate struct prt_dbg	dbg;
427c478bd9Sstevel@tonic-gate static char	new_path[MAXPATHLEN];
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #define	INDENT_LENGTH	4
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__x86
477c478bd9Sstevel@tonic-gate static const char *usage = "%s [ -V | -x | -abcvpPD ] [ <device_path > ]\n";
487c478bd9Sstevel@tonic-gate #else
497c478bd9Sstevel@tonic-gate static const char *usage = "%s [ -F | -V | -x | -abcvpPD ][ <device_path > ]\n";
507c478bd9Sstevel@tonic-gate #endif	/* __x86 */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static void
537c478bd9Sstevel@tonic-gate setprogname(const char *name)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	char *p;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	if (name == NULL)
587c478bd9Sstevel@tonic-gate 		opts.o_progname = "prtconf";
597c478bd9Sstevel@tonic-gate 	else if (p = strrchr(name, '/'))
607c478bd9Sstevel@tonic-gate 		opts.o_progname = (const char *) p + 1;
617c478bd9Sstevel@tonic-gate 	else
627c478bd9Sstevel@tonic-gate 		opts.o_progname = name;
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
667c478bd9Sstevel@tonic-gate void
677c478bd9Sstevel@tonic-gate dprintf(const char *fmt, ...)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 	if (dbg.d_debug) {
707c478bd9Sstevel@tonic-gate 		va_list ap;
717c478bd9Sstevel@tonic-gate 		va_start(ap, fmt);
727c478bd9Sstevel@tonic-gate 		(void) vfprintf(stderr, fmt, ap);
737c478bd9Sstevel@tonic-gate 		va_end(ap);
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate void
787c478bd9Sstevel@tonic-gate indent_to_level(int ilev)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	(void) printf("%*s", INDENT_LENGTH * ilev, "");
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static void
847c478bd9Sstevel@tonic-gate cleanup_path(const char *input_path, char *path)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	char	*ptr, *ptr2;
877c478bd9Sstevel@tonic-gate 	size_t	len;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if ((input_path == NULL) || (path == NULL))
907c478bd9Sstevel@tonic-gate 		return;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	(void) strcpy(path, input_path);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	/*LINTED*/
957c478bd9Sstevel@tonic-gate 	while (1) {
967c478bd9Sstevel@tonic-gate 		len = strlen(path);
977c478bd9Sstevel@tonic-gate 		if (len == 0)
987c478bd9Sstevel@tonic-gate 			break;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		/* change substring "//" into "/" */
1017c478bd9Sstevel@tonic-gate 		if (ptr = strstr(path, "//")) {
1027c478bd9Sstevel@tonic-gate 			len = strlen(ptr + 1);
1037c478bd9Sstevel@tonic-gate 			(void) memmove(ptr, ptr + 1, len + 1);
1047c478bd9Sstevel@tonic-gate 			continue;
1057c478bd9Sstevel@tonic-gate 		}
1067c478bd9Sstevel@tonic-gate 		/* change substring "/./" into "/" */
1077c478bd9Sstevel@tonic-gate 		if (ptr = strstr(path, "/./")) {
1087c478bd9Sstevel@tonic-gate 			len = strlen(ptr + 2);
1097c478bd9Sstevel@tonic-gate 			(void) memmove(ptr, ptr + 2, len + 1);
1107c478bd9Sstevel@tonic-gate 			continue;
1117c478bd9Sstevel@tonic-gate 		}
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 		/* change substring "/<foo>/../" into "/" */
1147c478bd9Sstevel@tonic-gate 		if (ptr = strstr(path, "/../")) {
1157c478bd9Sstevel@tonic-gate 			len = strlen(ptr + 3);
1167c478bd9Sstevel@tonic-gate 			*ptr = '\0';
1177c478bd9Sstevel@tonic-gate 			ptr2 = strrchr(path, (int)'/');
1187c478bd9Sstevel@tonic-gate 			if (ptr2 == NULL) {
1197c478bd9Sstevel@tonic-gate 				/* path had a leading "/../" */
1207c478bd9Sstevel@tonic-gate 				ptr2 = path;
1217c478bd9Sstevel@tonic-gate 			}
1227c478bd9Sstevel@tonic-gate 			(void) memmove(ptr2, ptr + 3, len + 1);
1237c478bd9Sstevel@tonic-gate 			continue;
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 		/* change trailing "/<foo>/.." into "/" */
1277c478bd9Sstevel@tonic-gate 		if ((len >= 3) &&
1287c478bd9Sstevel@tonic-gate 		    (path[len - 3] == '/') &&
1297c478bd9Sstevel@tonic-gate 		    (path[len - 2] == '.') &&
1307c478bd9Sstevel@tonic-gate 		    (path[len - 1] == '.')) {
1317c478bd9Sstevel@tonic-gate 			path[len - 3] = '\0';
1327c478bd9Sstevel@tonic-gate 			ptr2 = strrchr(path, (int)'/');
1337c478bd9Sstevel@tonic-gate 			if (ptr2 != NULL) {
1347c478bd9Sstevel@tonic-gate 				ptr2[1] = '\0';
1357c478bd9Sstevel@tonic-gate 			} else {
1367c478bd9Sstevel@tonic-gate 				/* path was "/.." */
1377c478bd9Sstevel@tonic-gate 				path[0] = '/';
1387c478bd9Sstevel@tonic-gate 				path[1] = '\0';
1397c478bd9Sstevel@tonic-gate 			}
1407c478bd9Sstevel@tonic-gate 			continue;
1417c478bd9Sstevel@tonic-gate 		}
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 		/* change trailing "/." into "/" */
1447c478bd9Sstevel@tonic-gate 		if ((len >= 2) &&
1457c478bd9Sstevel@tonic-gate 		    (path[len - 2] == '/') &&
1467c478bd9Sstevel@tonic-gate 		    (path[len - 1] == '.')) {
1477c478bd9Sstevel@tonic-gate 			path[len - 1] = '\0';
1487c478bd9Sstevel@tonic-gate 			continue;
1497c478bd9Sstevel@tonic-gate 		}
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 		/* remove trailing "/" unless it's the root */
1527c478bd9Sstevel@tonic-gate 		if ((len > 1) && (path[len - 1] == '/')) {
1537c478bd9Sstevel@tonic-gate 			path[len - 1] = '\0';
1547c478bd9Sstevel@tonic-gate 			continue;
1557c478bd9Sstevel@tonic-gate 		}
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 		break;
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * debug version has two more flags:
1647c478bd9Sstevel@tonic-gate  *	-L force load driver
1657c478bd9Sstevel@tonic-gate  *	-M: print per driver list
1667c478bd9Sstevel@tonic-gate  */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #ifdef	DEBUG
1697c478bd9Sstevel@tonic-gate static const char *optstring = "abcDvVxpPFf:M:dLuC";
1707c478bd9Sstevel@tonic-gate #else
1717c478bd9Sstevel@tonic-gate static const char *optstring = "abcDvVxpPFf:uC";
1727c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate int
1757c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1767c478bd9Sstevel@tonic-gate {
1777c478bd9Sstevel@tonic-gate 	long pagesize, npages;
1787c478bd9Sstevel@tonic-gate 	int c, ret;
1797c478bd9Sstevel@tonic-gate 	char hw_provider[SYS_NMLN];
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	setprogname(argv[0]);
1827c478bd9Sstevel@tonic-gate 	opts.o_promdev = "/dev/openprom";
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, optstring)) != -1)  {
1857c478bd9Sstevel@tonic-gate 		switch (c)  {
1867c478bd9Sstevel@tonic-gate 		case 'a':
1877c478bd9Sstevel@tonic-gate 			++opts.o_ancestors;
1887c478bd9Sstevel@tonic-gate 			break;
1897c478bd9Sstevel@tonic-gate 		case 'b':
1907c478bd9Sstevel@tonic-gate 			++opts.o_productinfo;
1917c478bd9Sstevel@tonic-gate 			break;
1927c478bd9Sstevel@tonic-gate 		case 'c':
1937c478bd9Sstevel@tonic-gate 			++opts.o_children;
1947c478bd9Sstevel@tonic-gate 			break;
1957c478bd9Sstevel@tonic-gate 		case 'D':
1967c478bd9Sstevel@tonic-gate 			++opts.o_drv_name;
1977c478bd9Sstevel@tonic-gate 			break;
1987c478bd9Sstevel@tonic-gate 		case 'v':
1997c478bd9Sstevel@tonic-gate 			++opts.o_verbose;
2007c478bd9Sstevel@tonic-gate 			break;
2017c478bd9Sstevel@tonic-gate 		case 'p':
2027c478bd9Sstevel@tonic-gate 			++opts.o_prominfo;
2037c478bd9Sstevel@tonic-gate 			break;
2047c478bd9Sstevel@tonic-gate 		case 'f':
2057c478bd9Sstevel@tonic-gate 			opts.o_promdev = optarg;
2067c478bd9Sstevel@tonic-gate 			break;
2077c478bd9Sstevel@tonic-gate 		case 'V':
2087c478bd9Sstevel@tonic-gate 			++opts.o_promversion;
2097c478bd9Sstevel@tonic-gate 			break;
2107c478bd9Sstevel@tonic-gate 		case 'x':
2117c478bd9Sstevel@tonic-gate 			++opts.o_prom_ready64;
2127c478bd9Sstevel@tonic-gate 			break;
2137c478bd9Sstevel@tonic-gate 		case 'F':
2147c478bd9Sstevel@tonic-gate 			++opts.o_fbname;
2157c478bd9Sstevel@tonic-gate 			++opts.o_noheader;
2167c478bd9Sstevel@tonic-gate 			break;
2177c478bd9Sstevel@tonic-gate 		case 'P':
2187c478bd9Sstevel@tonic-gate 			++opts.o_pseudodevs;
2197c478bd9Sstevel@tonic-gate 			break;
2207c478bd9Sstevel@tonic-gate 		case 'C':
2217c478bd9Sstevel@tonic-gate 			++opts.o_forcecache;
2227c478bd9Sstevel@tonic-gate 			break;
2237c478bd9Sstevel@tonic-gate #ifdef	DEBUG
2247c478bd9Sstevel@tonic-gate 		case 'M':
2257c478bd9Sstevel@tonic-gate 			dbg.d_drivername = optarg;
2267c478bd9Sstevel@tonic-gate 			++dbg.d_bydriver;
2277c478bd9Sstevel@tonic-gate 			break;
2287c478bd9Sstevel@tonic-gate 		case 'L':
2297c478bd9Sstevel@tonic-gate 			++dbg.d_forceload;
2307c478bd9Sstevel@tonic-gate 			break;
2317c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 		default:
2347c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, usage, opts.o_progname);
2357c478bd9Sstevel@tonic-gate 			return (1);
2367c478bd9Sstevel@tonic-gate 		}
2377c478bd9Sstevel@tonic-gate 	}
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	(void) uname(&opts.o_uts);
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	if (opts.o_fbname)
2427c478bd9Sstevel@tonic-gate 		return (do_fbname());
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if (opts.o_promversion)
2457c478bd9Sstevel@tonic-gate 		return (do_promversion());
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	if (opts.o_prom_ready64)
2487c478bd9Sstevel@tonic-gate 		return (do_prom_version64());
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	if (opts.o_productinfo)
2517c478bd9Sstevel@tonic-gate 		return (do_productinfo());
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	opts.o_devices_path = NULL;
2547c478bd9Sstevel@tonic-gate 	opts.o_devt = DDI_DEV_T_NONE;
2557c478bd9Sstevel@tonic-gate 	opts.o_target = 0;
2567c478bd9Sstevel@tonic-gate 	if (optind < argc) {
2577c478bd9Sstevel@tonic-gate 		struct stat	sinfo;
2587c478bd9Sstevel@tonic-gate 		char		*path = argv[optind];
2597c478bd9Sstevel@tonic-gate 		int		error;
2607c478bd9Sstevel@tonic-gate 
261*c3a9724dSVikram Hegde 		if (opts.o_prominfo) {
262*c3a9724dSVikram Hegde 			/* PROM tree cannot be used with path */
263*c3a9724dSVikram Hegde 			(void) fprintf(stderr, "%s: path and -p option are "
264*c3a9724dSVikram Hegde 			    "mutually exclusive\n", opts.o_progname);
265*c3a9724dSVikram Hegde 			return (1);
266*c3a9724dSVikram Hegde 		}
267*c3a9724dSVikram Hegde 
2687c478bd9Sstevel@tonic-gate 		if (strlen(path) >= MAXPATHLEN) {
2697c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: "
2707c478bd9Sstevel@tonic-gate 			    "path specified is too long\n", opts.o_progname);
2717c478bd9Sstevel@tonic-gate 			return (1);
2727c478bd9Sstevel@tonic-gate 		}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 		if (error = stat(path, &sinfo)) {
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 			/* an invalid path was specified */
2777c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: invalid path specified\n",
2787c478bd9Sstevel@tonic-gate 			    opts.o_progname);
2797c478bd9Sstevel@tonic-gate 			return (1);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 		} else if (((sinfo.st_mode & S_IFMT) == S_IFCHR) ||
2827c478bd9Sstevel@tonic-gate 		    ((sinfo.st_mode & S_IFMT) == S_IFBLK)) {
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 			opts.o_devt = sinfo.st_rdev;
2857c478bd9Sstevel@tonic-gate 			error = 0;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 		} else if ((sinfo.st_mode & S_IFMT) == S_IFDIR) {
2887c478bd9Sstevel@tonic-gate 			size_t	len, plen;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 			/* clean up the path */
2917c478bd9Sstevel@tonic-gate 			cleanup_path(path, new_path);
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 			len = strlen(new_path);
2947c478bd9Sstevel@tonic-gate 			plen = strlen("/devices");
2957c478bd9Sstevel@tonic-gate 			if (len < plen) {
2967c478bd9Sstevel@tonic-gate 				/* This is not a valid /devices path */
2977c478bd9Sstevel@tonic-gate 				error = 1;
2987c478bd9Sstevel@tonic-gate 			} else if ((len == plen) &&
2997c478bd9Sstevel@tonic-gate 			    (strcmp(new_path, "/devices") == 0)) {
3007c478bd9Sstevel@tonic-gate 				/* /devices is the root nexus */
3017c478bd9Sstevel@tonic-gate 				opts.o_devices_path = "/";
3027c478bd9Sstevel@tonic-gate 				error = 0;
3037c478bd9Sstevel@tonic-gate 			} else if (strncmp(new_path, "/devices/", plen + 1)) {
3047c478bd9Sstevel@tonic-gate 				/* This is not a valid /devices path */
3057c478bd9Sstevel@tonic-gate 				error = 1;
3067c478bd9Sstevel@tonic-gate 			} else {
3077c478bd9Sstevel@tonic-gate 				/* a /devices/ path was specified */
3087c478bd9Sstevel@tonic-gate 				opts.o_devices_path = new_path + plen;
3097c478bd9Sstevel@tonic-gate 				error = 0;
3107c478bd9Sstevel@tonic-gate 			}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		} else {
3137c478bd9Sstevel@tonic-gate 			/* an invalid device path was specified */
3147c478bd9Sstevel@tonic-gate 			error = 1;
3157c478bd9Sstevel@tonic-gate 		}
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 		if (error) {
3187c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: "
3197c478bd9Sstevel@tonic-gate 			    "invalid device path specified\n",
3207c478bd9Sstevel@tonic-gate 			    opts.o_progname);
3217c478bd9Sstevel@tonic-gate 			return (1);
3227c478bd9Sstevel@tonic-gate 		}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 		opts.o_target = 1;
3257c478bd9Sstevel@tonic-gate 	}
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	if ((opts.o_ancestors || opts.o_children) && (!opts.o_target)) {
3287c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: options require a device path\n",
3297c478bd9Sstevel@tonic-gate 		    opts.o_progname);
3307c478bd9Sstevel@tonic-gate 		return (1);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	if (opts.o_target) {
3347c478bd9Sstevel@tonic-gate 		prtconf_devinfo();
3357c478bd9Sstevel@tonic-gate 		return (0);
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	ret = sysinfo(SI_HW_PROVIDER, hw_provider, sizeof (hw_provider));
3397c478bd9Sstevel@tonic-gate 	/*
3407c478bd9Sstevel@tonic-gate 	 * If 0 bytes are returned (the system returns '1', for the \0),
3417c478bd9Sstevel@tonic-gate 	 * we're probably on x86, and there has been no si-hw-provider
3427c478bd9Sstevel@tonic-gate 	 * set in /etc/bootrc, so just default to Sun.
3437c478bd9Sstevel@tonic-gate 	 */
3447c478bd9Sstevel@tonic-gate 	if (ret <= 1) {
3457c478bd9Sstevel@tonic-gate 		(void) strncpy(hw_provider, "Sun Microsystems",
3467c478bd9Sstevel@tonic-gate 		    sizeof (hw_provider));
3477c478bd9Sstevel@tonic-gate 	} else {
3487c478bd9Sstevel@tonic-gate 		/*
3497c478bd9Sstevel@tonic-gate 		 * Provide backward compatibility by stripping out the _.
3507c478bd9Sstevel@tonic-gate 		 */
3517c478bd9Sstevel@tonic-gate 		if (strcmp(hw_provider, "Sun_Microsystems") == 0)
3527c478bd9Sstevel@tonic-gate 			hw_provider[3] = ' ';
3537c478bd9Sstevel@tonic-gate 	}
3547c478bd9Sstevel@tonic-gate 	(void) printf("System Configuration:  %s  %s\n", hw_provider,
3557c478bd9Sstevel@tonic-gate 	    opts.o_uts.machine);
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	pagesize = sysconf(_SC_PAGESIZE);
3587c478bd9Sstevel@tonic-gate 	npages = sysconf(_SC_PHYS_PAGES);
3597c478bd9Sstevel@tonic-gate 	(void) printf("Memory size: ");
3607c478bd9Sstevel@tonic-gate 	if (pagesize == -1 || npages == -1)
3617c478bd9Sstevel@tonic-gate 		(void) printf("unable to determine\n");
3627c478bd9Sstevel@tonic-gate 	else {
3637c478bd9Sstevel@tonic-gate 		const int64_t kbyte = 1024;
3647c478bd9Sstevel@tonic-gate 		const int64_t mbyte = 1024 * 1024;
3657c478bd9Sstevel@tonic-gate 		int64_t ii = (int64_t)pagesize * npages;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 		if (ii >= mbyte)
3687c478bd9Sstevel@tonic-gate 			(void) printf("%ld Megabytes\n",
3697c478bd9Sstevel@tonic-gate 			    (long)((ii+mbyte-1) / mbyte));
3707c478bd9Sstevel@tonic-gate 		else
3717c478bd9Sstevel@tonic-gate 			(void) printf("%ld Kilobytes\n",
3727c478bd9Sstevel@tonic-gate 			    (long)((ii+kbyte-1) / kbyte));
3737c478bd9Sstevel@tonic-gate 	}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	if (opts.o_prominfo) {
3767c478bd9Sstevel@tonic-gate 		(void) printf("System Peripherals (PROM Nodes):\n\n");
3777c478bd9Sstevel@tonic-gate 		if (do_prominfo() == 0)
3787c478bd9Sstevel@tonic-gate 			return (0);
3797c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: Defaulting to non-PROM mode...\n",
3807c478bd9Sstevel@tonic-gate 		    opts.o_progname);
3817c478bd9Sstevel@tonic-gate 	}
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	(void) printf("System Peripherals (Software Nodes):\n\n");
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	(void) prtconf_devinfo();
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	return (0);
3887c478bd9Sstevel@tonic-gate }
389