fmtopo.c revision a38fc4ea2efaea64cc89ed7a1ac251ae94199ae9
/*
* 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 <ctype.h>
#include <fnmatch.h>
#include <limits.h>
#include <strings.h>
#include <stdio.h>
#include <errno.h>
#include <umem.h>
#define FMTOPO_EXIT_SUCCESS 0
#define FMTOPO_EXIT_ERROR 1
#define FMTOPO_EXIT_USAGE 2
#define STDERR "stderr"
#define DOTS "..."
#define ALL "all"
static const char *g_pname;
static const char *opt_R = "/";
static const char *opt_s = FM_FMRI_SCHEME_HC;
static const char optstr[] = "bCdeP:pR:s:StVx";
static int opt_b = 0;
static int opt_d = 0;
static int opt_e = 0;
static int opt_p = 0;
static int opt_S = 0;
static int opt_t = 0;
static int opt_V = 0;
static int opt_x = 0;
static int opt_all = 0;
struct prop_args {
const char *group;
const char *prop;
const char *type;
const char *value;
};
static int pcnt = 0;
static int
{
"Usage: %s [-bCedpSVx] [-P group.property[=type:value]] "
"[-R root] [-s scheme] [fmri]\n", g_pname);
"\t-b walk in sibling-first order (default is child-first)\n"
"\t-C dump core after completing execution\n"
"\t-d set debug mode for libtopo modules\n"
"\t-p display of FMRI protocol properties\n"
"\t-R set root directory for libtopo plug-ins and other files\n"
"\t-s display topology for the specified FMRI scheme\n"
"\t-V set verbose mode\n"
"\t-x display a xml formatted topology\n");
return (FMTOPO_EXIT_USAGE);
}
static topo_type_t
{
return (TOPO_TYPE_INVALID);
else {
}
return (type);
}
static void
{
} else {
(void) printf("\tASRU: -\n");
}
} else {
(void) printf("\tFRU: -\n");
}
} else {
(void) printf("\tLabel: -\n");
}
}
if (opt_S) {
(void) printf("\tPresent: -\n");
else
(void) printf("\tPresent: %s\n",
(void) printf("\tUnusable: -\n");
else
(void) printf("\tUnusable: %s\n",
}
}
static void
{
int i, err;
uint_t n;
return;
}
return;
}
buf[0] = '\0';
for (i = 0; i < n; i++) {
"name-instance for %s=%d\n", g_pname,
return;
}
errno = 0;
}
}
}
static void
{
int err;
int i;
return;
/* Print property name */
g_pname);
return;
} else {
}
return;
} else {
}
switch (type) {
default: tstr = "unknown type";
}
/*
* Get property value
*/
g_pname);
return;
}
switch (nvpair_type(pv_nvp)) {
case DATA_TYPE_INT32: {
break;
}
case DATA_TYPE_UINT32: {
char val_str[49];
goto uint32_def;
goto uint32_def;
goto uint32_def;
&factype) != 0)
goto uint32_def;
/*
* Special case code to do friendlier printing of
* facility node properties
*/
break;
break;
break;
break;
if (topo_prop_get_uint32(node,
goto uint32_def;
}
break;
}
break;
}
case DATA_TYPE_INT64: {
break;
}
case DATA_TYPE_UINT64: {
break;
}
case DATA_TYPE_DOUBLE: {
double val;
break;
}
case DATA_TYPE_STRING: {
char *val;
} else {
}
break;
}
case DATA_TYPE_NVLIST: {
char *fmri;
if (opt_V)
break;
}
} else {
}
break;
}
case DATA_TYPE_UINT32_ARRAY: {
(void) printf(" [ ");
for (i = 0; i < nelem; i++)
(void) printf("]");
break;
}
case DATA_TYPE_INT64_ARRAY: {
(void) printf(" [ ");
for (i = 0; i < nelem; i++)
(void) printf("]");
break;
}
case DATA_TYPE_STRING_ARRAY: {
char **val;
(void) printf(" [ ");
for (i = 0; i < nelem; i++)
(void) printf("]");
break;
}
default:
break;
}
(void) printf("\n");
}
static void
{
int err;
char buf[30];
return;
}
}
printf(" group: %-30s version: %-3d stability: %s/%s\n",
} else {
printf(" group: %-30s version: %-3d stability: %s/%s\n",
}
}
}
static void
const char *group)
{
continue;
version = -1;
/*
* Print property group name and stability levels
*/
continue;
}
nvpair_name(pg_nvp)) == 0 &&
continue;
}
nvpair_name(pg_nvp)) == 0 &&
continue;
}
nvpair_name(pg_nvp)) == 0 &&
continue;
}
version);
pg_done++;
}
/*
* Print property group and property name-value pair
*/
}
}
}
return;
}
}
static void
{
char *end;
return;
return;
}
return;
}
if (ret != 0) {
return;
}
errno = 0;
switch (type) {
case TOPO_TYPE_INT32:
{
ret = -1;
break;
}
break;
}
case TOPO_TYPE_UINT32:
{
ret = -1;
break;
}
break;
}
case TOPO_TYPE_INT64:
{
ret = -1;
break;
}
break;
}
case TOPO_TYPE_UINT64:
{
ret = -1;
break;
}
break;
}
case TOPO_TYPE_STRING:
{
break;
}
case TOPO_TYPE_FMRI:
{
< 0)
break;
f)) != 0)
break;
}
default:
ret = -1;
}
if (ret != 0) {
return;
}
f, &ret) < 0) {
nvlist_free(f);
return;
}
} else {
TOPO_PROP_MUTABLE, f, &ret) < 0) {
nvlist_free(f);
return;
}
}
/*
* Now, get the property back for printing
*/
&err) < 0) {
nvlist_free(f);
return;
}
} else {
nvlist_free(f);
return;
}
}
nvlist_free(f);
}
static void
{
int i, err;
if (pcnt == 0)
return;
for (i = 0; i < pcnt; ++i) {
continue;
/*
* If we have a valid value, this is a request to
* set a property. Otherwise, just print the property
* group and any specified properties.
*/
/*
* Print all properties in this group
*/
== NULL) {
"get %s: %s\n", g_pname,
topo_strerror(err));
continue;
} else {
continue;
}
}
"%s.%s: %s\n", g_pname,
topo_strerror(err));
continue;
} else {
NULL, 0);
}
} else {
}
}
}
/*ARGSUSED*/
static int
{
int err;
char *s;
return (TOPO_WALK_NEXT);
}
return (TOPO_WALK_NEXT);
}
"resource to FMRI string: %s", g_pname,
topo_strerror(err));
return (TOPO_WALK_NEXT);
}
topo_hdl_strfree(thp, s);
return (TOPO_WALK_NEXT);
}
topo_hdl_strfree(thp, s);
"properties for %s=%d: %s\n", g_pname,
topo_strerror(err));
} else {
}
} else if (pcnt > 0)
printf("\n");
return (TOPO_WALK_NEXT);
}
static void
{
char c, *s, *p;
int i = 0;
"arguments\n", g_pname);
return;
}
if (c == 'P') {
opt_all++;
break;
}
== NULL) {
"allocate propertyarguments\n", g_pname);
return;
}
++i;
p = optarg;
*s++ = '\0'; /* strike out delimiter */
p = s;
*s++ = '\0'; /* strike out delimiter */
p = s;
*s++ = '\0';
} else {
"property type not "
"specified for assignment "
" of %s.%s\n", g_pname,
break;
}
} else {
}
} else {
}
if (i >= pcnt)
break;
}
}
if (opt_all > 0) {
int j;
for (j = 0; j < i; ++j)
}
}
static int
{
int err;
int flag;
== NULL) {
return (-1);
}
/*
* Print standard header
*/
if (!opt_e) {
char buf[32];
printf("TIME UUID\n");
(void) printf("\n");
}
g_pname);
return (-1);
}
return (0);
}
static void
{
/*
* Print property group and property name-value pair
*/
}
}
}
static void
{
int i, err;
for (i = 0; i < pcnt; ++i) {
continue;
/*
* If we have a valid value, this is a request to
* set a property. Otherwise, just print the property
* group and any specified properties.
*/
/*
* Print all properties in this group
*/
"get group %s: %s\n", g_pname,
continue;
} else {
pnvl);
continue;
}
}
"%s.%s: %s\n", g_pname,
topo_strerror(err));
continue;
} else {
}
} else {
}
}
}
void
{
char buf[32];
return;
}
printf("TIME UUID\n");
(void) printf("\n");
} else {
(void) printf("\tASRU: -\n");
}
} else {
(void) printf("\tFRU: -\n");
}
} else {
(void) printf("\tLabel: -\n");
}
}
if (opt_S) {
(void) printf("\tPresent: -\n");
(void) printf("\tUnusable: -\n");
return;
}
(void) printf("\tPresent: -\n");
else
(void) printf("\tPresent: %s\n",
(void) printf("\tUnusable: -\n");
else
(void) printf("\tUnusable: %s\n",
}
}
int
{
}
if (pargs) {
int i;
for (i = 0; i < pcnt; ++i)
}
return (err);
}
int
{
int c, err = 0;
switch (c) {
case 'b':
opt_b++;
break;
case 'C':
break;
case 'd':
opt_d++;
break;
case 'e':
opt_e++;
break;
case 'P':
pcnt++;
break;
case 'p':
opt_p++;
break;
case 'V':
opt_V++;
break;
case 'R':
break;
case 's':
break;
case 'S':
opt_S++;
break;
case 't':
opt_t++;
break;
case 'x':
opt_x++;
break;
default:
}
}
return (FMTOPO_EXIT_USAGE);
} else {
}
}
}
if (pcnt > 0)
}
if (opt_d)
} else if (err != 0) {
g_pname);
}
if (opt_x) {
if (opt_b) {
"%s: -b and -x cannot be specified together\n",
g_pname);
}
err = 0;
"formatted topology:%s", g_pname,
topo_strerror(err));
}
/*
* Try getting some useful information
*/
}
}