예제 #1
0
파일: uname.c 프로젝트: myaut/tsload
PLATAPI const char* hi_get_sys_name() {
	smbios_hdl_t* shp;
	smbios_system_t sys;
	smbios_info_t info;
	id_t id;

	int err;

	if(hi_sol_sysname_found)
		return hi_sol_sys_name;

	/* FIXME: smbios is x86-specific, should implement SPARC's "banner-name" from PICL root */
#ifdef HAVE_SMBIOS_OPEN

	shp = smbios_open(NULL, SMB_VERSION, 0, &err);
	if(shp == NULL)
		goto end;

	id = smbios_info_system(shp, &sys);
	if(id != SMB_ERR) {
		err = smbios_info_common(shp, id, &info);

		if(err != SMB_ERR) {
			snprintf(hi_sol_sys_name, SYSNAMELEN, "%s %s", info.smbi_manufacturer, info.smbi_product);
		}
	}

	smbios_close(shp);
#endif

end:
	hi_sol_sysname_found = B_TRUE;
	return hi_sol_sys_name;
}
예제 #2
0
/*
 * Strip out identification information for you privacy weenies.  This is quite
 * simple using our smbios_info_common() abstraction: we just locate any serial
 * numbers and asset tags for each record, and then zero out those strings.
 * Then we must handle two special cases: SMB_TYPE_SYSTEM holds a 16-byte UUID
 * and SMB_TYPE_BATTERY stores a Smart Battery Data Spec 16-bit serial number.
 * We use a literal '0' rather than '\0' for zeroing strings because \0\0 in
 * the SMBIOS string table has a special meaning (denotes end-of-record).
 */
static void
smb_strip(smbios_hdl_t *shp)
{
	uint_t i;

	for (i = 0; i < shp->sh_nstructs; i++) {
		const smb_header_t *hp = shp->sh_structs[i].smbst_hdr;
		smbios_info_t info;
		char *p;

		if (hp->smbh_type == SMB_TYPE_SYSTEM &&
		    hp->smbh_len >= offsetof(smb_system_t, smbsi_wakeup)) {
			smb_system_t *sp = (smb_system_t *)(uintptr_t)hp;
			bzero(sp->smbsi_uuid, sizeof (sp->smbsi_uuid));
		}

		if (hp->smbh_type == SMB_TYPE_BATTERY &&
		    hp->smbh_len >= offsetof(smb_battery_t, smbbat_sdate)) {
			smb_battery_t *bp = (smb_battery_t *)(uintptr_t)hp;
			bp->smbbat_ssn = 0;
		}

		if (smbios_info_common(shp, hp->smbh_hdl, &info) != SMB_ERR) {
			for (p = (char *)info.smbi_serial; *p != '\0'; p++)
				*p = '0';
			for (p = (char *)info.smbi_asset; *p != '\0'; p++)
				*p = '0';
		}
	}
}
예제 #3
0
static void
find_system_model(char **system_model) {

  /* the .h file will be there even on a SPARC system, so we have to
     check for both the .h and the libarary... */
#if defined(HAVE_SYS_SMBIOS_H) && defined(HAVE_LIBSMBIOS)
#include <sys/smbios.h>
  smbios_hdl_t *smbios_handle;
  smbios_info_t info;

  int error;
  int  ret;
  id_t ret_id_t;

  /* much of this is wild guessing based on web searches, sys/smbios.h, and
     experimentation.  my thanks to a helpful person familiar with libsmbios
     who got me started.  feel free to make yourself known as you see fit :)
     rick jones 2008-03-12 */
  smbios_handle = smbios_open(NULL,SMB_VERSION,0,&error);
  if (NULL == smbios_handle) {
    /* fall-back on sysinfo for the system model info, we don't really
       care why we didn't get a handle, just that we didn't get one */
#if defined(NETPERF_STANDALONE_DEBUG)
    printf("smbios_open returned NULL, error %d errno %d %s\n",
	   error,errno,strerror(errno));
#endif
    find_system_model_sysinfo(system_model);
    return;
  }
  ret = smbios_info_common(smbios_handle,256,&info);
  if (0 == ret)
    *system_model = strdup(info.smbi_product);
  else {
    /* we ass-u-me that while there was smbios on the system it didn't
       have the smbi_product information we seek, so once again we
       fallback to sysinfo.  this is getting tiresome isn't it?-) raj
       2008-03-12 */
#if defined(NETPERF_STANDALONE_DEBUG)
    printf("smbios_info_common returned %d errno %d %s\n",
	   ret,errno,strerror(errno));
#endif
    find_system_model_sysinfo(system_model);
  }
  smbios_close(smbios_handle);

#else

  find_system_model_sysinfo(system_model);

#endif

  return;
}
예제 #4
0
파일: smbios.c 프로젝트: bahamas10/openzfs
/*ARGSUSED*/
static int
do_procs(smbios_hdl_t *shp, const smbios_struct_t *sp, void *arg)
{
	smbios_processor_t p;
	smbios_info_t info;
	const char *v;
	char *s;
	size_t n;

	if (sp->smbstr_type == SMB_TYPE_PROCESSOR &&
	    smbios_info_processor(shp, sp->smbstr_id, &p) != SMB_ERR &&
	    smbios_info_common(shp, sp->smbstr_id, &info) != SMB_ERR &&
	    SMB_PRSTATUS_PRESENT(p.smbp_status)) {

		/*
		 * Obtaining a decent string for the type of processor is
		 * messy: the BIOS has hopefully filled in the SMBIOS record.
		 * If so, strip trailing spaces and \r (seen in some BIOSes).
		 * If not, fall back to the family name for p.smbp_family.
		 */
		if (info.smbi_version != NULL && *info.smbi_version != '\0') {
			n = strlen(info.smbi_version);
			v = s = alloca(n + 1);
			(void) strcpy(s, info.smbi_version);

			if (s[n - 1] == '\r')
				s[--n] = '\0';

			while (n != 0 && isspace(s[n - 1]))
				s[--n] = '\0';

		} else if ((v = smbios_processor_family_desc(
		    p.smbp_family)) == NULL) {
			v = gettext("Unknown");
		}

		(void) printf(gettext("%-32s %s\n"), v, info.smbi_location);
	}

	return (0);
}
RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
{
    AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
    AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
    *pszBuf = '\0';
    AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);

    int rc = VERR_NOT_SUPPORTED;
    int err = 0;
    smbios_hdl_t *pSMB = smbios_open(NULL /* default fd */, SMB_VERSION, 0 /* flags */, &err);
    if (pSMB)
    {
        smbios_system_t hSMBSys;
        id_t hSMBId = smbios_info_system(pSMB, &hSMBSys);
        if (hSMBId != SMB_ERR)
        {
            /* Don't need the common bits for the product UUID. */
            if (enmString == RTSYSDMISTR_PRODUCT_UUID)
            {
                static char const s_szHex[17] = "0123456789ABCDEF";
                char     szData[64];
                char    *pszData = szData;
                unsigned cchUuid = RT_MIN(hSMBSys.smbs_uuidlen, sizeof(szData) - 1);
                for (unsigned i = 0; i < cchUuid; i++)
                {
                    *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] >> 4];
                    *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] & 0xf];
                    if (i == 3 || i == 5 || i == 7 || i == 9)
                        *pszData++ = '-';
                }
                *pszData = '\0';
                rc = RTStrCopy(pszBuf, cbBuf, szData);
                smbios_close(pSMB);
                return rc;
            }

            smbios_info_t hSMBInfo;
            id_t hSMBInfoId = smbios_info_common(pSMB, hSMBId, &hSMBInfo);
            if (hSMBInfoId != SMB_ERR)
            {
                switch (enmString)
                {
                    case RTSYSDMISTR_PRODUCT_NAME:      rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_product); break;
                    case RTSYSDMISTR_PRODUCT_VERSION:   rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_version); break;
                    case RTSYSDMISTR_PRODUCT_SERIAL:    rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_serial);  break;
                    case RTSYSDMISTR_MANUFACTURER:      rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_manufacturer);  break;

                    default:  /* make gcc happy */
                        rc = VERR_NOT_SUPPORTED;
                }
                smbios_close(pSMB);
                return rc;
            }
        }

        /* smbios_* error path. */
        err = smbios_errno(pSMB);
        smbios_close(pSMB);
    }

    /* Do some error conversion.  */
    if (err == EPERM || err == EACCES)
        rc = VERR_ACCESS_DENIED;
    return rc;
}
예제 #6
0
파일: fmd.c 프로젝트: andreiw/polaris
void
fmd_create(fmd_t *dp, const char *arg0, const char *root, const char *conf)
{
	fmd_conf_path_t *pap;
	char file[PATH_MAX];
	const char *name;
	fmd_stat_t *sp;
	int i;

	smbios_hdl_t *shp;
	smbios_system_t s1;
	smbios_info_t s2;
	id_t id;

	di_prom_handle_t promh = DI_PROM_HANDLE_NIL;
	di_node_t rooth = DI_NODE_NIL;
	char *bufp;

	(void) sysinfo(SI_PLATFORM, _fmd_plat, sizeof (_fmd_plat));
	(void) sysinfo(SI_ARCHITECTURE, _fmd_isa, sizeof (_fmd_isa));
	(void) uname(&_fmd_uts);

	if ((shp = smbios_open(NULL, SMB_VERSION, 0, NULL)) != NULL) {
		if ((id = smbios_info_system(shp, &s1)) != SMB_ERR &&
		    smbios_info_common(shp, id, &s2) != SMB_ERR) {
			(void) strlcpy(_fmd_prod, s2.smbi_product, MAXNAMELEN);
			(void) strlcpy(_fmd_csn, s2.smbi_serial, MAXNAMELEN);
		}
		smbios_close(shp);
	} else if ((rooth = di_init("/", DINFOPROP)) != DI_NODE_NIL &&
	    (promh = di_prom_init()) != DI_PROM_HANDLE_NIL) {
		if (di_prom_prop_lookup_bytes(promh, rooth, "chassis-sn",
		    (unsigned char **)&bufp) != -1) {
			(void) strlcpy(_fmd_csn, bufp, MAXNAMELEN);
		}
	}

	if (promh != DI_PROM_HANDLE_NIL)
		di_prom_fini(promh);
	if (rooth != DI_NODE_NIL)
		di_fini(rooth);

	bzero(dp, sizeof (fmd_t));

	dp->d_version = _fmd_version;
	dp->d_pname = fmd_strbasename(arg0);
	dp->d_pid = getpid();

	if (pthread_key_create(&dp->d_key, NULL) != 0)
		fmd_error(EFMD_EXIT, "failed to create pthread key");

	(void) pthread_mutex_init(&dp->d_xprt_lock, NULL);
	(void) pthread_mutex_init(&dp->d_err_lock, NULL);
	(void) pthread_mutex_init(&dp->d_thr_lock, NULL);
	(void) pthread_mutex_init(&dp->d_mod_lock, NULL);
	(void) pthread_mutex_init(&dp->d_stats_lock, NULL);
	(void) pthread_rwlock_init(&dp->d_log_lock, NULL);

	/*
	 * A small number of properties must be set manually before we open
	 * the root configuration file.  These include any settings for our
	 * memory allocator and path expansion token values, because these
	 * values are needed by the routines in fmd_conf.c itself.  After
	 * the root configuration file is processed, we reset these properties
	 * based upon the latest values from the configuration file.
	 */
	dp->d_alloc_msecs = 10;
	dp->d_alloc_tries = 3;
	dp->d_str_buckets = 211;

	dp->d_rootdir = root ? root : "";
	dp->d_platform = _fmd_plat;
	dp->d_machine = _fmd_uts.machine;
	dp->d_isaname = _fmd_isa;

	dp->d_conf = fmd_conf_open(conf, sizeof (_fmd_conf) /
	    sizeof (_fmd_conf[0]), _fmd_conf, FMD_CONF_DEFER);

	if (dp->d_conf == NULL) {
		fmd_error(EFMD_EXIT,
		    "failed to load required configuration properties\n");
	}

	(void) fmd_conf_getprop(dp->d_conf, "alloc.msecs", &dp->d_alloc_msecs);
	(void) fmd_conf_getprop(dp->d_conf, "alloc.tries", &dp->d_alloc_tries);
	(void) fmd_conf_getprop(dp->d_conf, "strbuckets", &dp->d_str_buckets);

	(void) fmd_conf_getprop(dp->d_conf, "platform", &dp->d_platform);
	(void) fmd_conf_getprop(dp->d_conf, "machine", &dp->d_machine);
	(void) fmd_conf_getprop(dp->d_conf, "isaname", &dp->d_isaname);

	/*
	 * Manually specified rootdirs override config files, so only update
	 * d_rootdir based on the config files we parsed if no 'root' was set.
	 */
	if (root == NULL)
		(void) fmd_conf_getprop(dp->d_conf, "rootdir", &dp->d_rootdir);
	else
		(void) fmd_conf_setprop(dp->d_conf, "rootdir", dp->d_rootdir);

	/*
	 * Once the base conf file properties are loaded, lookup the values
	 * of $conf_path and $conf_file and merge in any other conf files.
	 */
	(void) fmd_conf_getprop(dp->d_conf, "conf_path", &pap);
	(void) fmd_conf_getprop(dp->d_conf, "conf_file", &name);

	for (i = 0; i < pap->cpa_argc; i++) {
		(void) snprintf(file, sizeof (file),
		    "%s/%s", pap->cpa_argv[i], name);
		if (access(file, F_OK) == 0)
			fmd_conf_merge(dp->d_conf, file);
	}

	/*
	 * Update the value of fmd.d_fg based on "fg".  We cache this property
	 * because it must be accessed deep within fmd at fmd_verror() time.
	 * Update any other properties that must be cached for performance.
	 */
	(void) fmd_conf_getprop(fmd.d_conf, "fg", &fmd.d_fg);
	(void) fmd_conf_getprop(fmd.d_conf, "xprt.ttl", &fmd.d_xprt_ttl);

	/*
	 * Initialize our custom libnvpair allocator and create an nvlist for
	 * authority elements corresponding to this instance of the daemon.
	 */
	(void) nv_alloc_init(&dp->d_nva, &fmd_nv_alloc_ops);
	dp->d_auth = fmd_protocol_authority();

	/*
	 * The fmd_module_t for the root module must be created manually.  Most
	 * of it remains unused and zero, except for the few things we fill in.
	 */
	dp->d_rmod = fmd_zalloc(sizeof (fmd_module_t), FMD_SLEEP);
	dp->d_rmod->mod_name = fmd_strdup(dp->d_pname, FMD_SLEEP);
	dp->d_rmod->mod_fmri = fmd_protocol_fmri_module(dp->d_rmod);

	fmd_list_append(&dp->d_mod_list, dp->d_rmod);
	fmd_module_hold(dp->d_rmod);

	(void) pthread_mutex_init(&dp->d_rmod->mod_lock, NULL);
	(void) pthread_cond_init(&dp->d_rmod->mod_cv, NULL);
	(void) pthread_mutex_init(&dp->d_rmod->mod_stats_lock, NULL);

	dp->d_rmod->mod_thread = fmd_thread_xcreate(dp->d_rmod, pthread_self());
	dp->d_rmod->mod_stats = fmd_zalloc(sizeof (fmd_modstat_t), FMD_SLEEP);
	dp->d_rmod->mod_ustat = fmd_ustat_create();

	if (pthread_setspecific(dp->d_key, dp->d_rmod->mod_thread) != 0)
		fmd_error(EFMD_EXIT, "failed to attach main thread key");

	if ((dp->d_stats = (fmd_statistics_t *)fmd_ustat_insert(
	    dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC, sizeof (_fmd_stats) /
	    sizeof (fmd_stat_t), (fmd_stat_t *)&_fmd_stats, NULL)) == NULL)
		fmd_error(EFMD_EXIT, "failed to initialize statistics");

	(void) pthread_mutex_lock(&dp->d_rmod->mod_lock);
	dp->d_rmod->mod_flags |= FMD_MOD_INIT;
	(void) pthread_mutex_unlock(&dp->d_rmod->mod_lock);

	/*
	 * In addition to inserting the _fmd_stats collection of program-wide
	 * statistics, we also insert a statistic named after each of our
	 * errors and update these counts in fmd_verror() (see fmd_subr.c).
	 */
	dp->d_errstats = sp = fmd_zalloc(sizeof (fmd_stat_t) *
	    (EFMD_END - EFMD_UNKNOWN), FMD_SLEEP);

	for (i = 0; i < EFMD_END - EFMD_UNKNOWN; i++, sp++) {
		(void) snprintf(sp->fmds_name, sizeof (sp->fmds_name), "err.%s",
		    strrchr(fmd_errclass(EFMD_UNKNOWN + i), '.') + 1);
		sp->fmds_type = FMD_TYPE_UINT64;
	}

	(void) fmd_ustat_insert(dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC,
	    EFMD_END - EFMD_UNKNOWN, dp->d_errstats, NULL);
}
예제 #7
0
static int
print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
{
	smbios_info_t info;
	int hex = opt_x;
	const char *s;

	if (opt_t != -1 && opt_t != sp->smbstr_type)
		return (0); /* skip struct if type doesn't match -t */

	if (!opt_O && (sp->smbstr_type == SMB_TYPE_MEMCTL ||
	    sp->smbstr_type == SMB_TYPE_MEMMOD))
		return (0); /* skip struct if type is obsolete */

	if (g_hdr++ == 0 || !opt_s)
		oprintf(fp, "%-5s %-4s %s\n", "ID", "SIZE", "TYPE");

	oprintf(fp, "%-5u %-4lu",
	    (uint_t)sp->smbstr_id, (ulong_t)sp->smbstr_size);

	if ((s = smbios_type_name(sp->smbstr_type)) != NULL)
		oprintf(fp, " %s (type %u)", s, sp->smbstr_type);
	else if (sp->smbstr_type > SMB_TYPE_OEM_LO &&
	    sp->smbstr_type < SMB_TYPE_OEM_HI)
		oprintf(fp, " %s+%u (type %u)", "SMB_TYPE_OEM_LO",
		    sp->smbstr_type - SMB_TYPE_OEM_LO, sp->smbstr_type);
	else
		oprintf(fp, " %u", sp->smbstr_type);

	if ((s = smbios_type_desc(sp->smbstr_type)) != NULL)
		oprintf(fp, " (%s)\n", s);
	else
		oprintf(fp, "\n");

	if (opt_s)
		return (0); /* only print header line if -s specified */

	if (smbios_info_common(shp, sp->smbstr_id, &info) == 0) {
		oprintf(fp, "\n");
		print_common(&info, fp);
	}

	switch (sp->smbstr_type) {
	case SMB_TYPE_BIOS:
		oprintf(fp, "\n");
		print_bios(shp, fp);
		break;
	case SMB_TYPE_SYSTEM:
		oprintf(fp, "\n");
		print_system(shp, fp);
		break;
	case SMB_TYPE_BASEBOARD:
		oprintf(fp, "\n");
		print_bboard(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_CHASSIS:
		oprintf(fp, "\n");
		print_chassis(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_PROCESSOR:
		oprintf(fp, "\n");
		print_processor(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_CACHE:
		oprintf(fp, "\n");
		print_cache(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_PORT:
		oprintf(fp, "\n");
		print_port(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_SLOT:
		oprintf(fp, "\n");
		print_slot(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_OBDEVS:
		oprintf(fp, "\n");
		print_obdevs(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_OEMSTR:
	case SMB_TYPE_SYSCONFSTR:
		oprintf(fp, "\n");
		print_strtab(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_LANG:
		oprintf(fp, "\n");
		print_lang(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_EVENTLOG:
		oprintf(fp, "\n");
		print_evlog(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_MEMARRAY:
		oprintf(fp, "\n");
		print_memarray(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_MEMDEVICE:
		oprintf(fp, "\n");
		print_memdevice(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_MEMARRAYMAP:
		oprintf(fp, "\n");
		print_memarrmap(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_MEMDEVICEMAP:
		oprintf(fp, "\n");
		print_memdevmap(shp, sp->smbstr_id, fp);
		break;
	case SMB_TYPE_SECURITY:
		oprintf(fp, "\n");
		print_hwsec(shp, fp);
		break;
	case SMB_TYPE_BOOT:
		oprintf(fp, "\n");
		print_boot(shp, fp);
		break;
	case SMB_TYPE_IPMIDEV:
		oprintf(fp, "\n");
		print_ipmi(shp, fp);
		break;
	case SMB_TYPE_OBDEVEXT:
		oprintf(fp, "\n");
		print_obdevs_ext(shp, sp->smbstr_id, fp);
		break;
	case SUN_OEM_EXT_PROCESSOR:
		oprintf(fp, "\n");
		print_extprocessor(shp, sp->smbstr_id, fp);
		break;
	case SUN_OEM_EXT_PORT:
		oprintf(fp, "\n");
		print_extport(shp, sp->smbstr_id, fp);
		break;
	case SUN_OEM_PCIEXRC:
		oprintf(fp, "\n");
		print_pciexrc(shp, sp->smbstr_id, fp);
		break;
	case SUN_OEM_EXT_MEMARRAY:
		oprintf(fp, "\n");
		print_extmemarray(shp, sp->smbstr_id, fp);
		break;
	case SUN_OEM_EXT_MEMDEVICE:
		oprintf(fp, "\n");
		print_extmemdevice(shp, sp->smbstr_id, fp);
		break;
	default:
		hex++;
	}

	if (hex)
		print_bytes(sp->smbstr_data, sp->smbstr_size, fp);
	else
		oprintf(fp, "\n");

	return (0);
}
예제 #8
0
파일: smbios.c 프로젝트: bahamas10/openzfs
/*ARGSUSED*/
int
do_prominfo(int opt_v, char *progname, int opt_l, int opt_p)
{
	smbios_hdl_t *shp;
	smbios_system_t sys;
	smbios_bios_t bios;
	smbios_ipmi_t ipmi;
	smbios_info_t info;
	topo_hdl_t *thp;
	char *uuid;

	const char *s;
	id_t id;
	int err;

	if ((shp = smbios_open(NULL, SMB_VERSION, 0, &err)) == NULL) {
		(void) fprintf(stderr,
		    gettext("%s: failed to open SMBIOS: %s\n"),
		    progname, smbios_errmsg(err));
		return (1);
	}

	if ((id = smbios_info_system(shp, &sys)) != SMB_ERR &&
	    smbios_info_common(shp, id, &info) != SMB_ERR) {
		(void) printf(gettext("System Configuration: %s %s\n"),
		    info.smbi_manufacturer, info.smbi_product);
	} else {
		(void) fprintf(stderr,
		    gettext("%s: failed to get system info: %s\n"),
		    progname, smbios_errmsg(smbios_errno(shp)));
	}

	if (smbios_info_bios(shp, &bios) != SMB_ERR) {
		(void) printf(gettext("BIOS Configuration: %s %s %s\n"),
		    bios.smbb_vendor, bios.smbb_version, bios.smbb_reldate);
	} else {
		(void) fprintf(stderr,
		    gettext("%s: failed to get bios info: %s\n"),
		    progname, smbios_errmsg(smbios_errno(shp)));
	}

	if (smbios_info_ipmi(shp, &ipmi) != SMB_ERR) {
		if ((s = smbios_ipmi_type_desc(ipmi.smbip_type)) == NULL)
			s = gettext("Unknown");

		(void) printf(gettext("BMC Configuration: IPMI %u.%u (%s)\n"),
		    ipmi.smbip_vers.smbv_major, ipmi.smbip_vers.smbv_minor, s);
	}

	/*
	 * Silently swallow all libtopo and libpcidb related errors.
	 */
	uuid = NULL;
	if ((thp = topo_open(TOPO_VERSION, NULL, &err)) != NULL) {
		if ((uuid = topo_snap_hold(thp, NULL, &err)) == NULL) {
			topo_close(thp);
			thp = NULL;
		}
	}

	prt_php = pcidb_open(PCIDB_VERSION);

	(void) printf(gettext(
	    "\n==== Processor Sockets ====================================\n"));

	(void) printf(gettext("\n%-32s %s"), "Version", "Location Tag");

	(void) printf(gettext(
	    "\n-------------------------------- --------------------------\n"));
	(void) smbios_iter(shp, do_procs, NULL);

	(void) printf(gettext(
	    "\n==== Memory Device Sockets ================================\n"));

	(void) printf(gettext("\n%-11s %-6s %-3s %-19s %s"),
	    "Type", "Status", "Set", "Device Locator", "Bank Locator");

	(void) printf(gettext(
	    "\n----------- ------ --- ------------------- ----------------\n"));
	(void) smbios_iter(shp, do_memdevs, NULL);

	(void) printf(gettext(
	    "\n==== On-Board Devices =====================================\n"));
	(void) smbios_iter(shp, do_obdevs, NULL);

	(void) printf(gettext(
	    "\n==== Upgradeable Slots ====================================\n"));

	(void) printf(gettext("\n%-3s %-9s %-16s %s"),
	    "ID", "Status", "Type", "Description");

	(void) printf(gettext(
	    "\n--- --------- ---------------- ----------------------------\n"));
	(void) smbios_iter(shp, do_slots, thp);

	smbios_close(shp);

	topo_hdl_strfree(thp, uuid);
	if (thp != NULL) {
		topo_snap_release(thp);
		topo_close(thp);
	}
	pcidb_close(prt_php);

	return (0);
}
예제 #9
0
int
S3_helper(char *whitelist, char *blacklist, int yes, int no, char *keyword,
	char *behavior, int *didyes, int suppress)
{
	int oflags = SMB_O_NOCKSUM | SMB_O_NOVERS;
	smbios_hdl_t *shp;
	smbios_system_t sys;
	id_t id;
	int ret;
	kstat_ctl_t *kc;
	kstat_t *ksp;
	kstat_named_t *dp;
	smbios_info_t info;
	int preferred_pm_profile = 0;
	char yesstr[32], nostr[32];	/* DEBUG */

	*didyes = 0;

	(void) strncpy(yesstr, pm_map(yes), sizeof (yesstr));
	(void) strncpy(nostr, pm_map(no), sizeof (nostr));
	mesg(MDEBUG, "S3_helper(%s, %s, %s, %s, %s, %s)\n", whitelist,
	    blacklist, yesstr, nostr, keyword, behavior);
	if ((kc = kstat_open()) == NULL) {
		mesg(MDEBUG, "kstat_open failed\n");
		return (OKUP);
	}
	ksp = kstat_lookup(kc, "acpi", -1, "acpi");
	if (ksp == NULL) {
		mesg(MDEBUG, "kstat_lookup 'acpi', -1, 'acpi' failed\n");
		(void) kstat_close(kc);
		return (OKUP);
	}
	(void) kstat_read(kc, ksp,  NULL);
	dp = kstat_data_lookup(ksp, "S3");
	if (dp == NULL || dp->value.l == 0) {
		mesg(MDEBUG, "kstat_data_lookup 'S3' fails\n");
		if (dp != NULL)
			mesg(MDEBUG, "value.l %lx\n", dp->value.l);
		(void) kstat_close(kc);
		return (do_ioctl(no, keyword, behavior, suppress));
	}
	mesg(MDEBUG, "kstat indicates S3 support (%lx)\n", dp->value.l);

	if (!whitelist_only) {
		/*
		 * We still have an ACPI ksp, search it again for
		 * 'preferred_pm_profile' (needs to be valid if we don't
		 * aren't only using a whitelist).
		 */
		dp = kstat_data_lookup(ksp, "preferred_pm_profile");
		if (dp == NULL) {
			mesg(MDEBUG, "kstat_data_lookup 'ppmp fails\n");
			(void) kstat_close(kc);
			return (do_ioctl(no, keyword, behavior, suppress));
		}
		mesg(MDEBUG, "kstat indicates preferred_pm_profile is %lx\n",
		    dp->value.l);
		preferred_pm_profile = dp->value.l;
	}
	(void) kstat_close(kc);

	if ((shp = smbios_open(NULL,
	    SMB_VERSION, oflags, &ret)) == NULL) {
		/* we promised not to complain */
		/* we bail leaving it to the kernel default */
		mesg(MDEBUG, "smbios_open failed %d\n", errno);
		return (OKUP);
	}
	if ((id = smbios_info_system(shp, &sys)) == SMB_ERR) {
		mesg(MDEBUG, "smbios_info_system failed %d\n", errno);
		smbios_close(shp);
		return (OKUP);
	}
	if (smbios_info_common(shp, id, &info) == SMB_ERR) {
		mesg(MDEBUG, "smbios_info_common failed %d\n", errno);
		smbios_close(shp);
		return (OKUP);
	}
	mesg(MDEBUG, "Manufacturer: %s\n", info.smbi_manufacturer);
	mesg(MDEBUG, "Product: %s\n", info.smbi_product);
	smbios_close(shp);

	if (!whitelist_only) {
#define	PPP_DESKTOP 1
#define	PPP_WORKSTATION 3
		if (strcmp(info.smbi_manufacturer, "Sun Microsystems") == 0 &&
		    (preferred_pm_profile == PPP_DESKTOP ||
		    preferred_pm_profile == PPP_WORKSTATION)) {
			if (isonlist(blacklist,
			    info.smbi_manufacturer, info.smbi_product)) {
				return (do_ioctl(no, keyword, behavior,
				    suppress));
			} else {
				ret = do_ioctl(yes, keyword, behavior,
				    suppress);
				*didyes = (ret == OKUP);
				return (ret);
			}
		}
	}
	if (isonlist(whitelist,
	    info.smbi_manufacturer, info.smbi_product)) {
		ret = do_ioctl(yes, keyword, behavior, suppress);
		*didyes = (ret == OKUP);
		return (ret);
	} else {
		return (do_ioctl(no, keyword, behavior, suppress));
	}
}
예제 #10
0
topo_hdl_t *
topo_open(int version, const char *rootdir, int *errp)
{
	topo_hdl_t *thp = NULL;
	topo_alloc_t *tap;

	char platform[MAXNAMELEN];
	char isa[MAXNAMELEN];
	struct utsname uts;
	struct stat st;

	smbios_hdl_t *shp;
	smbios_system_t s1;
	smbios_info_t s2;
	id_t id;

	char *dbflags, *dbout;

	if (version != TOPO_VERSION)
		return (set_open_errno(thp, errp, ETOPO_HDL_ABIVER));

	if (rootdir != NULL && stat(rootdir, &st) < 0)
		return (set_open_errno(thp, errp, ETOPO_HDL_INVAL));

	if ((thp = topo_zalloc(sizeof (topo_hdl_t), 0)) == NULL)
		return (set_open_errno(thp, errp, ETOPO_NOMEM));

	(void) pthread_mutex_init(&thp->th_lock, NULL);

	if ((tap = topo_zalloc(sizeof (topo_alloc_t), 0)) == NULL)
		return (set_open_errno(thp, errp, ETOPO_NOMEM));

	/*
	 * Install default allocators
	 */
	tap->ta_flags = 0;
	tap->ta_alloc = topo_alloc;
	tap->ta_zalloc = topo_zalloc;
	tap->ta_free = topo_free;
	tap->ta_nvops.nv_ao_alloc = topo_nv_alloc;
	tap->ta_nvops.nv_ao_free = topo_nv_free;
	(void) nv_alloc_init(&tap->ta_nva, &tap->ta_nvops);
	thp->th_alloc = tap;

	if ((thp->th_modhash = topo_modhash_create(thp)) == NULL)
		return (set_open_errno(thp, errp, ETOPO_NOMEM));

	/*
	 * Set-up system information and search paths for modules
	 * and topology map files
	 */
	if (rootdir == NULL) {
		rootdir = topo_hdl_strdup(thp, "/");
		thp->th_rootdir = (char *)rootdir;
	} else {
		int len;
		char *rpath;

		len = strlen(rootdir);
		if (len >= PATH_MAX)
			return (set_open_errno(thp, errp, EINVAL));

		if (rootdir[len - 1] != '/') {
			rpath = alloca(len + 2);
			(void) snprintf(rpath, len + 2, "%s/", rootdir);
		} else {
			rpath = (char *)rootdir;
		}
		thp->th_rootdir = topo_hdl_strdup(thp, rpath);
	}

	platform[0] = '\0';
	isa[0] = '\0';
	(void) sysinfo(SI_PLATFORM, platform, sizeof (platform));
	(void) sysinfo(SI_ARCHITECTURE, isa, sizeof (isa));
	(void) uname(&uts);
	thp->th_platform = topo_hdl_strdup(thp, platform);
	thp->th_isa = topo_hdl_strdup(thp, isa);
	thp->th_machine = topo_hdl_strdup(thp, uts.machine);
	if ((shp = smbios_open(NULL, SMB_VERSION, 0, NULL)) != NULL) {
		if ((id = smbios_info_system(shp, &s1)) != SMB_ERR &&
		    smbios_info_common(shp, id, &s2) != SMB_ERR) {

			if (strcmp(s2.smbi_product, SMB_DEFAULT1) != 0 &&
			    strcmp(s2.smbi_product, SMB_DEFAULT2) != 0) {
				thp->th_product = topo_cleanup_auth_str(thp,
				    (char *)s2.smbi_product);
			}
		}
		smbios_close(shp);
	} else {
		thp->th_product = topo_hdl_strdup(thp, thp->th_platform);
	}

	if (thp->th_rootdir == NULL || thp->th_platform == NULL ||
	    thp->th_machine == NULL)
		return (set_open_errno(thp, errp, ETOPO_NOMEM));

	dbflags	 = getenv("TOPO_DEBUG");
	dbout = getenv("TOPO_DEBUG_OUT");
	if (dbflags != NULL)
		topo_debug_set(thp, dbflags, dbout);

	if (topo_builtin_create(thp, thp->th_rootdir) != 0) {
		topo_dprintf(thp, TOPO_DBG_ERR,
		    "failed to load builtin modules: %s\n",
		    topo_hdl_errmsg(thp));
		return (set_open_errno(thp, errp, topo_hdl_errno(thp)));
	}

	return (thp);
}
예제 #11
0
tnode_t *
x86pi_gen_chassis(topo_mod_t *mod, tnode_t *t_parent, int smb_id, int instance)
{
	int			rv;
	smbios_info_t		ip;
	smbios_chassis_t	ch;
	x86pi_hcfmri_t		ch_hcfmri;
	tnode_t			*ch_node;
	char			*f = "x86pi_gen_chassis";
	smbios_hdl_t		*shp;

	shp = topo_mod_smbios(mod);
	if (shp == NULL) {
		topo_mod_dprintf(mod, "%s: failed to load SMBIOS\n", f);
		return (NULL);
	}

	/* init fmri struct */
	bzero(&ch_hcfmri, sizeof (x86pi_hcfmri_t));

	/* grab SMBIOS strings */
	rv = smbios_info_common(shp, smb_id, &ip);
	if (rv != 0) {
		return (NULL);
	}

	/* grab SMBIOS type 3 struct */
	rv = smbios_info_chassis(shp, smb_id, &ch);
	if (rv != 0) {
		return (NULL);
	}

	/* populate string entries */
	ch_hcfmri.serial_number = x86pi_cleanup_smbios_str(mod,
	    ip.smbi_serial, 0);
	ch_hcfmri.version = x86pi_cleanup_smbios_str(mod, ip.smbi_version, 0);
	ch_hcfmri.manufacturer = x86pi_cleanup_smbios_str(mod,
	    ip.smbi_manufacturer, 0);

	/* set hc_name and instance */
	ch_hcfmri.hc_name = topo_mod_strdup(mod, "chassis");
	ch_hcfmri.instance = instance;

	topo_mod_dprintf(mod, "%s: instance (%d)\n", f, ch_hcfmri.instance);
	topo_mod_dprintf(mod, "%s: hc name (%s)\n", f, ch_hcfmri.hc_name);
	topo_mod_dprintf(mod, "%s: Serial Number (%s)\n",
	    f, ch_hcfmri.serial_number);
	topo_mod_dprintf(mod, "%s: Version (%s)\n", f, ch_hcfmri.version);
	topo_mod_dprintf(mod, "%s: Manufacturer (%s)\n",
	    f, ch_hcfmri.manufacturer);

	/* create topo node */
	if (!instance) {
		/* First Chassis SMBIOS Record is Chassis topo instance 0 */
		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, NULL,
		    &ch_node, 0);
	} else {
		rv = x86pi_enum_generic(mod, &ch_hcfmri, t_parent, t_parent,
		    &ch_node, 0);
	}
	if (rv != 0) {
		topo_mod_dprintf(mod, "%s: failed to create %d tnode\n", f,
		    instance);
		return (NULL);
	}

	/* free up strings */
	if (ch_hcfmri.serial_number != NULL) {
		topo_mod_strfree(mod, (char *)ch_hcfmri.serial_number);
	}
	if (ch_hcfmri.version != NULL) {
		topo_mod_strfree(mod, (char *)ch_hcfmri.version);
	}
	if (ch_hcfmri.manufacturer != NULL) {
		topo_mod_strfree(mod, (char *)ch_hcfmri.manufacturer);
	}
	if (ch_hcfmri.hc_name != NULL) {
		topo_mod_strfree(mod, (char *)ch_hcfmri.hc_name);
	}

	return (ch_node);
}