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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include "HBANPIVPort.h"
28 #include "Exceptions.h"
34 #include <sys/types.h>
35 #include <sys/mkdev.h>
41 #include <libdevinfo.h>
47 * @memo Construct a new deafult HBA Port
50 HBANPIVPort::HBANPIVPort() {
54 * @memo Compare two HBA ports for equality
55 * @return TRUE if both ports are the same
56 * @return FALSE if the ports are different
59 * @doc Comparison is based on Node WWN, Port WWN and path
61 bool HBANPIVPort::operator==(HBANPIVPort
&comp
) {
62 return (this->getPortWWN() == comp
.getPortWWN() &&
63 this->getNodeWWN() == comp
.getNodeWWN());
67 * Finds controller path for a give device path.
69 * Return vale: controller path.
71 string
HBANPIVPort::lookupControllerPath(string path
) {
72 Trace
log("lookupControllerPath");
75 char node
[MAXPATHLEN
];
76 struct dirent
**dirpp
, *dirp
;
77 const char dir
[] = "/dev/cfg";
79 uchar_t
*dir_buf
= new uchar_t
[sizeof (struct dirent
) + MAXPATHLEN
];
81 if ((dp
= opendir(dir
)) == NULL
) {
82 string tmp
= "Unable to open ";
84 tmp
+= "to find controller number.";
89 dirp
= (struct dirent
*) dir_buf
;
91 while ((readdir_r(dp
, dirp
, dirpp
)) == 0 && dirp
!= NULL
) {
92 if (strcmp(dirp
->d_name
, ".") == 0 ||
93 strcmp(dirp
->d_name
, "..") == 0) {
96 sprintf(node
, "%s/%s", dir
, dirp
->d_name
);
97 if ((count
= readlink(node
,buf
,sizeof(buf
)))) {
99 if (strstr(buf
, path
.c_str())) {
100 string cfg_path
= dir
;
102 cfg_path
+= dirp
->d_name
;
112 throw InternalError("Unable to find controller path");