xref: /onnv-gate/usr/src/lib/sun_sas/common/Sun_sasGetAdapterName.c (revision 10652:9d0aff74d6fd)
1*10652SHyon.Kim@Sun.COM /*
2*10652SHyon.Kim@Sun.COM  * CDDL HEADER START
3*10652SHyon.Kim@Sun.COM  *
4*10652SHyon.Kim@Sun.COM  * The contents of this file are subject to the terms of the
5*10652SHyon.Kim@Sun.COM  * Common Development and Distribution License (the "License").
6*10652SHyon.Kim@Sun.COM  * You may not use this file except in compliance with the License.
7*10652SHyon.Kim@Sun.COM  *
8*10652SHyon.Kim@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10652SHyon.Kim@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*10652SHyon.Kim@Sun.COM  * See the License for the specific language governing permissions
11*10652SHyon.Kim@Sun.COM  * and limitations under the License.
12*10652SHyon.Kim@Sun.COM  *
13*10652SHyon.Kim@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*10652SHyon.Kim@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10652SHyon.Kim@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*10652SHyon.Kim@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*10652SHyon.Kim@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10652SHyon.Kim@Sun.COM  *
19*10652SHyon.Kim@Sun.COM  * CDDL HEADER END
20*10652SHyon.Kim@Sun.COM  */
21*10652SHyon.Kim@Sun.COM 
22*10652SHyon.Kim@Sun.COM /*
23*10652SHyon.Kim@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*10652SHyon.Kim@Sun.COM  * Use is subject to license terms.
25*10652SHyon.Kim@Sun.COM  */
26*10652SHyon.Kim@Sun.COM 
27*10652SHyon.Kim@Sun.COM #include    "sun_sas.h"
28*10652SHyon.Kim@Sun.COM 
29*10652SHyon.Kim@Sun.COM /*
30*10652SHyon.Kim@Sun.COM  * Returns the text string which describes this adapter and which is used to
31*10652SHyon.Kim@Sun.COM  * open the adapter with the library.
32*10652SHyon.Kim@Sun.COM  *
33*10652SHyon.Kim@Sun.COM  * Arguments:
34*10652SHyon.Kim@Sun.COM  *	    index	the index to which adapter to retrive the name
35*10652SHyon.Kim@Sun.COM  *	    name	buffer to which the adapter name will be placed
36*10652SHyon.Kim@Sun.COM  */
Sun_sasGetAdapterName(HBA_UINT32 index,char * name)37*10652SHyon.Kim@Sun.COM HBA_STATUS Sun_sasGetAdapterName(HBA_UINT32 index, char *name) {
38*10652SHyon.Kim@Sun.COM 	const char		ROUTINE[] = "Sun_sasGetAdapterName";
39*10652SHyon.Kim@Sun.COM 	struct sun_sas_hba	*hba_ptr;
40*10652SHyon.Kim@Sun.COM 
41*10652SHyon.Kim@Sun.COM 	if (name == NULL) {
42*10652SHyon.Kim@Sun.COM 	    log(LOG_DEBUG, ROUTINE, "NULL adapter name");
43*10652SHyon.Kim@Sun.COM 	    return (HBA_STATUS_ERROR_ARG);
44*10652SHyon.Kim@Sun.COM 	}
45*10652SHyon.Kim@Sun.COM 	lock(&all_hbas_lock);
46*10652SHyon.Kim@Sun.COM 	for (hba_ptr = global_hba_head; hba_ptr != NULL;
47*10652SHyon.Kim@Sun.COM 		hba_ptr = hba_ptr->next) {
48*10652SHyon.Kim@Sun.COM 	    if (hba_ptr->index == index) {
49*10652SHyon.Kim@Sun.COM 		    if (hba_ptr->handle_name == NULL) {
50*10652SHyon.Kim@Sun.COM 			hba_ptr = NULL;
51*10652SHyon.Kim@Sun.COM 			break;
52*10652SHyon.Kim@Sun.COM 		    }
53*10652SHyon.Kim@Sun.COM 		    /* Flaw in the spec!  How do we know the size of name? */
54*10652SHyon.Kim@Sun.COM 		    (void) strlcpy(name, hba_ptr->handle_name,
55*10652SHyon.Kim@Sun.COM 			strlen(hba_ptr->handle_name)+1);
56*10652SHyon.Kim@Sun.COM 		    break;
57*10652SHyon.Kim@Sun.COM 	    }
58*10652SHyon.Kim@Sun.COM 	}
59*10652SHyon.Kim@Sun.COM 	unlock(&all_hbas_lock);
60*10652SHyon.Kim@Sun.COM 	if (hba_ptr == NULL) {
61*10652SHyon.Kim@Sun.COM 	    log(LOG_DEBUG, ROUTINE,
62*10652SHyon.Kim@Sun.COM 		"Unable to find adapter index %d.", index);
63*10652SHyon.Kim@Sun.COM 	    return (HBA_STATUS_ERROR_ILLEGAL_INDEX);
64*10652SHyon.Kim@Sun.COM 	}
65*10652SHyon.Kim@Sun.COM 
66*10652SHyon.Kim@Sun.COM 	return (HBA_STATUS_OK);
67*10652SHyon.Kim@Sun.COM }
68