4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011, Joyent, Inc. All rights reserved.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
35 #include <sys/systeminfo.h>
36 #include <sys/types.h>
42 static char new_path
[MAXPATHLEN
];
44 #define INDENT_LENGTH 4
47 static const char *usage
= "%s [ -V | -x | -abcdvpPD ] [ <device_path > ]\n";
49 static const char *usage
=
50 "%s [ -F | -V | -x | -abcdvpPD ][ <device_path > ]\n";
54 setpname(const char *name
)
59 opts
.o_progname
= "prtconf";
60 else if (p
= strrchr(name
, '/'))
61 opts
.o_progname
= (const char *) p
+ 1;
63 opts
.o_progname
= name
;
68 dprintf(const char *fmt
, ...)
73 (void) vfprintf(stderr
, fmt
, ap
);
79 indent_to_level(int ilev
)
81 (void) printf("%*s", INDENT_LENGTH
* ilev
, "");
85 cleanup_path(const char *input_path
, char *path
)
90 if ((input_path
== NULL
) || (path
== NULL
))
93 (void) strcpy(path
, input_path
);
101 /* change substring "//" into "/" */
102 if (ptr
= strstr(path
, "//")) {
103 len
= strlen(ptr
+ 1);
104 (void) memmove(ptr
, ptr
+ 1, len
+ 1);
107 /* change substring "/./" into "/" */
108 if (ptr
= strstr(path
, "/./")) {
109 len
= strlen(ptr
+ 2);
110 (void) memmove(ptr
, ptr
+ 2, len
+ 1);
114 /* change substring "/<foo>/../" into "/" */
115 if (ptr
= strstr(path
, "/../")) {
116 len
= strlen(ptr
+ 3);
118 ptr2
= strrchr(path
, (int)'/');
120 /* path had a leading "/../" */
123 (void) memmove(ptr2
, ptr
+ 3, len
+ 1);
127 /* change trailing "/<foo>/.." into "/" */
129 (path
[len
- 3] == '/') &&
130 (path
[len
- 2] == '.') &&
131 (path
[len
- 1] == '.')) {
132 path
[len
- 3] = '\0';
133 ptr2
= strrchr(path
, (int)'/');
144 /* change trailing "/." into "/" */
146 (path
[len
- 2] == '/') &&
147 (path
[len
- 1] == '.')) {
148 path
[len
- 1] = '\0';
152 /* remove trailing "/" unless it's the root */
153 if ((len
> 1) && (path
[len
- 1] == '/')) {
154 path
[len
- 1] = '\0';
164 * debug version has two more flags:
165 * -L force load driver
166 * -M: print per driver list
170 static const char *optstring
= "abcdDvVxmpPFf:M:dLuC";
172 static const char *optstring
= "abcdDvVxmpPFf:uC";
176 main(int argc
, char *argv
[])
178 long pagesize
, npages
;
180 char hw_provider
[SYS_NMLN
];
183 opts
.o_promdev
= "/dev/openprom";
185 while ((c
= getopt(argc
, argv
, optstring
)) != -1) {
191 ++opts
.o_productinfo
;
212 opts
.o_promdev
= optarg
;
215 ++opts
.o_promversion
;
218 ++opts
.o_prom_ready64
;
232 dbg
.d_drivername
= optarg
;
241 (void) fprintf(stderr
, usage
, opts
.o_progname
);
246 (void) uname(&opts
.o_uts
);
249 return (do_fbname());
251 if (opts
.o_promversion
)
252 return (do_promversion());
254 if (opts
.o_prom_ready64
)
255 return (do_prom_version64());
257 if (opts
.o_productinfo
)
258 return (do_productinfo());
260 opts
.o_devices_path
= NULL
;
261 opts
.o_devt
= DDI_DEV_T_NONE
;
265 char *path
= argv
[optind
];
268 if (opts
.o_prominfo
) {
269 /* PROM tree cannot be used with path */
270 (void) fprintf(stderr
, "%s: path and -p option are "
271 "mutually exclusive\n", opts
.o_progname
);
275 if (strlen(path
) >= MAXPATHLEN
) {
276 (void) fprintf(stderr
, "%s: "
277 "path specified is too long\n", opts
.o_progname
);
281 if (error
= stat(path
, &sinfo
)) {
283 /* an invalid path was specified */
284 (void) fprintf(stderr
, "%s: invalid path specified\n",
288 } else if (((sinfo
.st_mode
& S_IFMT
) == S_IFCHR
) ||
289 ((sinfo
.st_mode
& S_IFMT
) == S_IFBLK
)) {
291 opts
.o_devt
= sinfo
.st_rdev
;
294 } else if ((sinfo
.st_mode
& S_IFMT
) == S_IFDIR
) {
297 /* clean up the path */
298 cleanup_path(path
, new_path
);
300 len
= strlen(new_path
);
301 plen
= strlen("/devices");
303 /* This is not a valid /devices path */
305 } else if ((len
== plen
) &&
306 (strcmp(new_path
, "/devices") == 0)) {
307 /* /devices is the root nexus */
308 opts
.o_devices_path
= "/";
310 } else if (strncmp(new_path
, "/devices/", plen
+ 1)) {
311 /* This is not a valid /devices path */
314 /* a /devices/ path was specified */
315 opts
.o_devices_path
= new_path
+ plen
;
320 /* an invalid device path was specified */
325 (void) fprintf(stderr
, "%s: "
326 "invalid device path specified\n",
334 if ((opts
.o_ancestors
|| opts
.o_children
) && (!opts
.o_target
)) {
335 (void) fprintf(stderr
, "%s: options require a device path\n",
345 if (!opts
.o_memory
) {
346 ret
= sysinfo(SI_HW_PROVIDER
, hw_provider
,
347 sizeof (hw_provider
));
349 * If 0 bytes are returned (the system returns '1', for the \0),
350 * we're probably on x86, default to "Unknown Hardware Vendor".
353 (void) strncpy(hw_provider
, "Unknown Hardware Vendor",
354 sizeof (hw_provider
));
356 (void) printf("System Configuration: %s %s\n", hw_provider
,
360 pagesize
= sysconf(_SC_PAGESIZE
);
361 npages
= sysconf(_SC_PHYS_PAGES
);
362 if (pagesize
== -1 || npages
== -1) {
364 (void) printf("0\n");
367 (void) printf("Memory size: unable to determine\n");
370 const int64_t mbyte
= 1024 * 1024;
371 int64_t ii
= (int64_t)pagesize
* npages
;
374 (void) printf("%ld\n", (long)((ii
+mbyte
-1) / mbyte
));
377 (void) printf("Memory size: %ld Megabytes\n",
378 (long)((ii
+mbyte
-1) / mbyte
));
382 if (opts
.o_prominfo
) {
383 (void) printf("System Peripherals (PROM Nodes):\n\n");
384 if (do_prominfo() == 0)
386 (void) fprintf(stderr
, "%s: Defaulting to non-PROM mode...\n",
390 (void) printf("System Peripherals (Software Nodes):\n\n");
392 (void) prtconf_devinfo();