hc.c revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe
/*
*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <alloca.h>
#include <limits.h>
#include <fm/topo_mod.h>
#include <sys/systeminfo.h>
#include <topo_parse.h>
#include <hc_canon.h>
#define HC "hc"
#define HC_VERSION TOPO_VERSION
topo_instance_t, void *);
nvlist_t **);
nvlist_t **);
nvlist_t **);
nvlist_t **);
const char *);
const topo_method_t hc_methods[] = {
{ NULL }
};
const topo_modinfo_t hc_info =
void
{
/*
* Turn on module debugging output
*/
}
}
void
{
}
/*ARGSUSED*/
int
{
int err;
/*
* Register root node methods
*/
return (0);
}
"Request to enumerate %s component with an "
"ambiguous instance number, min (%d) != max (%d).\n",
}
return (-1);
return (-1);
}
return (0);
}
/*ARGSUSED*/
static void
{
}
/*ARGSUSED*/
static int
{
}
/*ARGSUSED*/
static int
{
}
/*ARGSUSED*/
static int
{
}
/*ARGSUSED*/
static int
{
int err, i;
if (version > TOPO_METH_COMPARE_VERSION)
if (err != 0)
return (0);
for (i = 0; i < nhcp1; i++) {
continue;
return (0);
}
return (1);
}
/*
* buf_append -- Append str to buf (if it's non-NULL). Place prepend
* in buf in front of str and append behind it (if they're non-NULL).
* Continue to update size even if we run out of space to actually
* stuff characters in the buffer.
*/
static void
{
return;
left = 0;
else
}
static ssize_t
{
int more_auth = 0;
int err, i;
return (-1);
/* Get authority, if present */
return (-1);
return (-1);
return (-1);
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
(void) nvlist_lookup_string(anvl,
more_auth++;
more_auth++;
more_auth++;
more_auth++;
more_auth++;
}
/* hc:// */
/* authority, if any */
NULL);
/* separating slash */
/* hardware-id part */
NULL);
/* separating slash */
/* hc-root */
/* all the pairs */
for (i = 0; i < hcnprs; i++) {
if (i > 0)
return (0);
}
return (size);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_NVL2STR_VERSION)
}
}
return (0);
}
static nvlist_t *
{
int err = 0;
/*
* Create base HC nvlist
*/
return (NULL);
if (err != 0) {
return (NULL);
}
/*
* Add optional payload members
*/
return (fmri);
}
static nvlist_t **
{
char *cname;
char *find;
char *cid;
int nslashes = 0;
int npairs = 0;
int i, e;
/*
* Count equal signs and slashes to determine how many
* hc-pairs will be present in the final FMRI. There should
* be at least as many slashes as equal signs. There can be
* more, though if the string after an = includes them.
*/
npairs++;
}
nslashes++;
}
/*
* Do we appear to have a well-formed string version of the FMRI?
*/
return (NULL);
/*
* We go through a pretty complicated procedure to find the
* name and id for each pair. That's because, unfortunately,
* we have some ids that can have slashes within them. So
* we can't just search for the next slash after the equal sign
* and decide that starts a new pair. Instead we have to find
* an equal sign for the next pair and work our way back to the
* slash from there.
*/
for (i = 0; i < npairs; i++) {
break;
startn++;
break;
*starti = '\0';
*starti++ = '=';
*endi = '\0';
break;
*endi = '=';
*endi2 = '\0';
*endi2 = '/';
} else {
}
break;
}
if (e != 0) {
break;
}
}
if (i < npairs) {
while (i >= 0)
return (NULL);
}
return (pa);
}
/*ARGSUSED*/
static int
{
int npairs;
int i, e;
if (version > TOPO_METH_STR2NVL_VERSION)
/* We're expecting a string version of an hc scheme FMRI */
}
goto hcfmbail;
if (e != 0) {
goto hcfmbail;
}
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
return (0);
for (i = 0; i < npairs; i++)
nvlist_free(pa[i]);
}
static nvlist_t *
{
int err;
return (NULL);
if (err != 0) {
return (NULL);
}
return (hc);
}
static nvlist_t *
int err)
{
int i;
for (i = 0; i < n + 1; ++i)
nvlist_free(hcl[i]);
}
return (NULL);
}
static int
hc_name_canonical(const char *name)
{
int i;
/*
* Only enumerate elements with correct canonical names
*/
for (i = 0; i < Hc_ncanon; i++) {
break;
}
if (i >= Hc_ncanon)
return (0);
else
return (1);
}
static nvlist_t *
{
int i;
if (version > FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
else if (version < FM_HC_SCHEME_VERSION)
return (hc_create_seterror(mod,
/*
* Check that the requested name is in our canonical list
*/
if (hc_name_canonical(name) == 0)
return (hc_create_seterror(mod,
/*
* Copy the parent's HC_LIST
*/
return (hc_create_seterror(mod,
}
EMOD_NOMEM));
for (i = 0; i < pelems; ++i)
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
return (hc_create_seterror(mod,
!= 0)
return (hc_create_seterror(mod,
for (i = 0; i < pelems + 1; ++i) {
nvlist_free(hcl[i]);
}
}
return (fmri);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_FMRI_VERSION)
/* First the must-have fields */
/* And then optional arguments */
return (-1);
return (0);
}