4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
24 * Copyright (c) 2018, Joyent, Inc.
25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 /*
30 * SMBIOS Information Routines
31 *
32 * The routines in this file are used to convert from the SMBIOS data format to
33 * a more reasonable and stable set of structures offered as part of our ABI.
34 * These functions take the general form:
35 *
36 * stp = smb_lookup_type(shp, foo);
37 * smb_foo_t foo;
38 *
39 * smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
40 * bzero(caller's struct);
41 *
42 * copy/convert foo members into caller's struct
43 *
44 * We copy the internal structure on to an automatic variable so as to avoid
681
682 void
683 smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers,
684 smbios_slot_peer_t *peer)
685 {
686 size_t sz = npeers * sizeof (smbios_slot_peer_t);
687
688 if (npeers == 0) {
689 ASSERT3P(peer, ==, NULL);
690 return;
691 }
692
693 smb_free(peer, sz);
694 }
695
696 int
697 smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers,
698 smbios_slot_peer_t **peerp)
699 {
700 const smb_struct_t *stp = smb_lookup_id(shp, id);
701 const smb_slot_t *slotp = (const smb_slot_t *)stp->smbst_hdr;
702 smbios_slot_peer_t *peer;
703 size_t minlen;
704 uint_t i;
705
706 if (stp == NULL)
707 return (-1); /* errno is set for us */
708
709 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
710 return (smb_set_errno(shp, ESMB_TYPE));
711
712 if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) ||
713 slotp->smbsl_npeers == 0) {
714 *npeers = 0;
715 *peerp = NULL;
716 return (0);
717 }
718
719 /*
720 * Make sure that the size of the structure makes sense for the number
721 * of peers reported.
722 */
723 minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) +
724 offsetof(smb_slot_t, smbsl_npeers);
725 if (stp->smbst_hdr->smbh_len < minlen) {
726 return (smb_set_errno(shp, ESMB_SHORT));
727 }
728
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
24 * Copyright 2019 Joyent, Inc.
25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 /*
30 * SMBIOS Information Routines
31 *
32 * The routines in this file are used to convert from the SMBIOS data format to
33 * a more reasonable and stable set of structures offered as part of our ABI.
34 * These functions take the general form:
35 *
36 * stp = smb_lookup_type(shp, foo);
37 * smb_foo_t foo;
38 *
39 * smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
40 * bzero(caller's struct);
41 *
42 * copy/convert foo members into caller's struct
43 *
44 * We copy the internal structure on to an automatic variable so as to avoid
681
682 void
683 smbios_info_slot_peers_free(smbios_hdl_t *shp, uint_t npeers,
684 smbios_slot_peer_t *peer)
685 {
686 size_t sz = npeers * sizeof (smbios_slot_peer_t);
687
688 if (npeers == 0) {
689 ASSERT3P(peer, ==, NULL);
690 return;
691 }
692
693 smb_free(peer, sz);
694 }
695
696 int
697 smbios_info_slot_peers(smbios_hdl_t *shp, id_t id, uint_t *npeers,
698 smbios_slot_peer_t **peerp)
699 {
700 const smb_struct_t *stp = smb_lookup_id(shp, id);
701 const smb_slot_t *slotp;
702 smbios_slot_peer_t *peer;
703 size_t minlen;
704 uint_t i;
705
706 if (stp == NULL)
707 return (-1); /* errno is set for us */
708
709 slotp = (const smb_slot_t *)stp->smbst_hdr;
710
711 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
712 return (smb_set_errno(shp, ESMB_TYPE));
713
714 if (stp->smbst_hdr->smbh_len <= offsetof(smb_slot_t, smbsl_npeers) ||
715 slotp->smbsl_npeers == 0) {
716 *npeers = 0;
717 *peerp = NULL;
718 return (0);
719 }
720
721 /*
722 * Make sure that the size of the structure makes sense for the number
723 * of peers reported.
724 */
725 minlen = slotp->smbsl_npeers * sizeof (smb_slot_peer_t) +
726 offsetof(smb_slot_t, smbsl_npeers);
727 if (stp->smbst_hdr->smbh_len < minlen) {
728 return (smb_set_errno(shp, ESMB_SHORT));
729 }
730
|