xref: /titanic_50/usr/src/psm/promif/ieee1275/common/prom_devname.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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) 1991-1994, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
31 
32 int
33 prom_devname_from_pathname(register char *pathname, register char *buffer)
34 {
35 	register char *p;
36 
37 	if ((pathname == (char *)0) || (*pathname == (char)0))
38 		return (-1);
39 
40 	p = prom_strrchr(pathname, '/');
41 	if (p == 0)
42 		return (-1);
43 
44 	p++;
45 	while (*p != 0)  {
46 		*buffer++ = *p++;
47 		if ((*p == '@') || (*p == ':'))
48 			break;
49 	}
50 	*buffer = (char)0;
51 
52 	return (0);
53 }
54 
55 /*
56  * Get base device name of stdin/stdout device into callers buffer.
57  * Return 0 if successful; -1 otherwise.
58  */
59 
60 int
61 prom_stdin_devname(char *buffer)
62 {
63 	return (prom_devname_from_pathname(prom_stdinpath(), buffer));
64 }
65 
66 int
67 prom_stdout_devname(char *buffer)
68 {
69 	return (prom_devname_from_pathname(prom_stdoutpath(), buffer));
70 }
71 
72 /*
73  * Return 1 if stdin/stdout are on the same device and subdevice.
74  * Return 0, otherwise.
75  */
76 
77 int
78 prom_stdin_stdout_equivalence(void)
79 {
80 	register char *s, *p;
81 
82 	s = prom_stdinpath();
83 	p = prom_stdoutpath();
84 
85 	if ((s != (char *)0) && (p != (char *)0))  {
86 		return (prom_strcmp(s, p) == 0 ? 1:0);
87 	}
88 
89 	return (0);
90 }
91 
92 /*
93  *	This just returns a pointer to the option's part of the
94  *	last part of the string.  Useful for determining which is
95  *	the boot partition, tape file or channel of the DUART.
96  */
97 char *
98 prom_path_options(register char *path)
99 {
100 	register char *p, *s;
101 
102 	s = prom_strrchr(path, '/');
103 	if (s == (char *)0)
104 		return ((char *)0);
105 	p = prom_strrchr(s, ':');
106 	if (p == (char *)0)
107 		return ((char *)0);
108 	return (p+1);
109 }
110