2N/A/*
2N/A *
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <errno.h>
2N/A#include <ctype.h>
2N/A#include <alloca.h>
2N/A#include <limits.h>
2N/A#include <fm/topo_mod.h>
2N/A#include <sys/param.h>
2N/A#include <sys/systeminfo.h>
2N/A#include <sys/fm/protocol.h>
2N/A#include <sys/stat.h>
2N/A
2N/A#include <topo_method.h>
2N/A#include <topo_subr.h>
2N/A#include <fmd.h>
2N/A
2N/Astatic int fmd_enum(topo_mod_t *, tnode_t *, const char *, topo_instance_t,
2N/A topo_instance_t, void *, void *);
2N/Astatic void fmd_release(topo_mod_t *, tnode_t *);
2N/Astatic int fmd_fmri_nvl2str(topo_mod_t *, tnode_t *, topo_version_t,
2N/A nvlist_t *, nvlist_t **);
2N/A
2N/Aconst topo_method_t fmd_methods[] = {
2N/A { TOPO_METH_NVL2STR, TOPO_METH_NVL2STR_DESC, TOPO_METH_NVL2STR_VERSION,
2N/A TOPO_STABILITY_INTERNAL, fmd_fmri_nvl2str },
2N/A { NULL }
2N/A};
2N/A
2N/Astatic const topo_modops_t fmd_ops =
2N/A { fmd_enum, fmd_release };
2N/Astatic const topo_modinfo_t fmd_info =
2N/A { FMD, FM_FMRI_SCHEME_FMD, FMD_VERSION, &fmd_ops };
2N/A
2N/Aint
2N/Afmd_init(topo_mod_t *mod, topo_version_t version)
2N/A{
2N/A /*
2N/A * Turn on module debugging output
2N/A */
2N/A if (getenv("TOPOFMDDEBUG"))
2N/A topo_mod_setdebug(mod);
2N/A
2N/A topo_mod_dprintf(mod, "initializing fmd builtin\n");
2N/A
2N/A if (version != FMD_VERSION)
2N/A return (topo_mod_seterrno(mod, EMOD_VER_NEW));
2N/A
2N/A if (topo_mod_register(mod, &fmd_info, TOPO_VERSION) != 0) {
2N/A topo_mod_dprintf(mod, "failed to register fmd: "
2N/A "%s\n", topo_mod_errmsg(mod));
2N/A return (-1); /* mod errno already set */
2N/A }
2N/A
2N/A return (0);
2N/A}
2N/A
2N/Avoid
2N/Afmd_fini(topo_mod_t *mod)
2N/A{
2N/A topo_mod_unregister(mod);
2N/A}
2N/A
2N/A
2N/A/*ARGSUSED*/
2N/Aint
2N/Afmd_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, topo_instance_t min,
2N/A topo_instance_t max, void *notused1, void *notused2)
2N/A{
2N/A /*
2N/A * Methods are registered, but there is no enumeration. Should
2N/A * enumeration be added be sure to cater for global vs non-global
2N/A * zones.
2N/A */
2N/A (void) topo_method_register(mod, pnode, fmd_methods);
2N/A return (0);
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic void
2N/Afmd_release(topo_mod_t *mp, tnode_t *node)
2N/A{
2N/A topo_method_unregister_all(mp, node);
2N/A}
2N/A
2N/Astatic ssize_t
2N/Afmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
2N/A{
2N/A char *name;
2N/A
2N/A if (nvlist_lookup_string(nvl, FM_FMRI_FMD_NAME, &name) != 0)
2N/A return (0);
2N/A
2N/A return (snprintf(buf, buflen,
2N/A "%s:///module/%s", FM_FMRI_SCHEME_FMD, name));
2N/A}
2N/A
2N/A/*ARGSUSED*/
2N/Astatic int
2N/Afmd_fmri_nvl2str(topo_mod_t *mod, tnode_t *node, topo_version_t version,
2N/A nvlist_t *nvl, nvlist_t **out)
2N/A{
2N/A ssize_t len;
2N/A char *name = NULL;
2N/A nvlist_t *fmristr;
2N/A
2N/A if (version > TOPO_METH_NVL2STR_VERSION)
2N/A return (topo_mod_seterrno(mod, EMOD_VER_NEW));
2N/A
2N/A if ((len = fmri_nvl2str(nvl, NULL, 0)) == 0 ||
2N/A (name = topo_mod_alloc(mod, len + 1)) == NULL ||
2N/A fmri_nvl2str(nvl, name, len + 1) == 0) {
2N/A if (name != NULL)
2N/A topo_mod_free(mod, name, len + 1);
2N/A return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
2N/A }
2N/A
2N/A if (topo_mod_nvalloc(mod, &fmristr, NV_UNIQUE_NAME) != 0) {
2N/A topo_mod_free(mod, name, len + 1);
2N/A return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
2N/A }
2N/A if (nvlist_add_string(fmristr, "fmri-string", name) != 0) {
2N/A topo_mod_free(mod, name, len + 1);
2N/A nvlist_free(fmristr);
2N/A return (topo_mod_seterrno(mod, EMOD_FMRI_NVL));
2N/A }
2N/A topo_mod_free(mod, name, len + 1);
2N/A *out = fmristr;
2N/A
2N/A return (0);
2N/A}