/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <syslog.h>
#include <libdevice.h>
#include "common.h"
static char ctoi(char c);
/*
* Simple wrapper for syslog error messages.
* Allows easy addition of syserr output if desired.
*/
static void
{
/*
* First %s for msg_id in merged msg.
* Second %s is for input merged_msg
*/
char *merged_msg;
/* insert caller's args */
if (merged_msg == NULL) {
"ID[luxadm.create_fabric_device.2317] "
} else {
/* first insert msg_id */
}
}
/*
* Routines for reading tapestry repository file
*/
int
{
int fd;
char *line;
int ret;
unsigned int filesize;
unsigned int bytes_read;
log_error("2310",
"filename missing for -f option of "
"luxadm -e create_fabric_device");
return (-1);
}
if (fd == -1) {
log_error("2311",
"fopen failed: cannot open repository file %s. %d",
return (-1);
}
log_error("2312",
"stat failed on file %s. %s",
return (-1);
}
if (mmap_ptr == MAP_FAILED) {
log_error("2315",
"Failed to mmap file %s. %s",
return (-1);
}
bytes_read = 0;
while (bytes_read < filesize) {
bytes_read++;
tmp_ptr++;
}
if (*tmp_ptr == '\n') {
tmp_ptr++;
bytes_read++;
}
/* If the line is a comment, read another line */
if (*line == COMMENT_CHAR) {
continue;
}
if (ret == 0) {
}
}
return (ret);
}
/*
* Input is paramater 1 - a line from repository
* Output is other parameters, the path to the attachment point,
* and the port wwn are parsed from the repository
* Format is
* If controller name is missing, that's okay. Other fields
* must be present
*
* Return 0 on success or -1 on failure; all failures logged to syslog.
*/
static int
{
char *line_copy;
log_error("2317",
}
log_error("2313",
return (-1);
}
log_error("2318",
return (-1);
}
/*
* Now look for the blank delimiter before the controller
*
* This is just the case when there may be a controller #
* after the attachment point and WWN. For example -
*/
/* now p_delim points to blank */
} else {
char *p_last_char;
if (*p_last_char == '\n') {
*p_last_char = NULL;
}
}
return (0);
}
static char
ctoi(char c)
{
if ((c >= '0') && (c <= '9'))
c -= '0';
else if ((c >= 'A') && (c <= 'F'))
c = c - 'A' + 10;
else if ((c >= 'a') && (c <= 'f'))
c = c - 'a' + 10;
else
c = -1;
return (c);
}
/*
* "string" is Input and "port_wwn" has the output
*
* This function converts a string to WWN.
* For example a string like
* "220000203707F4F1" gets converted to 0x220000203707F4F1 ...
* where
* port_wwn[0] = 0x22,
* port_wwn[1] = 0x00,
* port_wwn[2] = 0x00,
* port_wwn[3] = 0x20,
* port_wwn[4] = 0x37,
* port_wwn[5] = 0x07,
* port_wwn[6] = 0xF4, and
* port_wwn[7] = 0xF1
*/
static int
{
int i;
char c, c1;
return (-1);
}
return (0);
}
static int
{
int ret;
if (ddef_handle == NULL) {
log_error("2314",
"Internal error to process line (%s) "
"in file: %s. %s",
return (-1);
}
/*
* g_string_to_wwn() has not been used here because it
* prepends 2 NULLs.
*/
log_error("2314",
"Internal error to process line (%s) "
"in file: %s. %s",
return (-1);
}
(void) devctl_ddef_byte_array(ddef_handle,
log_error("2314",
"Internal error to process line (%s) "
"in file: %s. %s",
return (-1);
}
if (ret =
log_error("2316",
"configuration failed for line (%s) "
"in file: %s. %s",
return (-1);
}
return (ret);
}