VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/solaris/RTSystemQueryDmiString-solaris.cpp@ 27787

Last change on this file since 27787 was 27129, checked in by vboxsync, 15 years ago

scm cleaned up some whitespace.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: RTSystemQueryDmiString-solaris.cpp 27129 2010-03-06 00:16:08Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryDmiString, solaris ring-3.
4 */
5
6/*
7 * Copyright (C) 2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/system.h>
36#include "internal/iprt.h"
37
38#include <iprt/err.h>
39#include <iprt/assert.h>
40#include <iprt/string.h>
41
42#include <smbios.h>
43#include <errno.h>
44
45
46RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
47{
48 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
49 AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
50 *pszBuf = '\0';
51 AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
52
53 int rc = VERR_NOT_SUPPORTED;
54 int err = 0;
55 smbios_hdl_t *pSMB = smbios_open(NULL /* default fd */, SMB_VERSION, 0 /* flags */, &err);
56 if (pSMB)
57 {
58 smbios_system_t hSMBSys;
59 id_t hSMBId = smbios_info_system(pSMB, &hSMBSys);
60 if (hSMBId != SMB_ERR)
61 {
62 /* Don't need the common bits for the product UUID. */
63 if (enmString == RTSYSDMISTR_PRODUCT_UUID)
64 {
65 static char const s_szHex[17] = "0123456789ABCDEF";
66 char szData[64];
67 char *pszData = szData;
68 unsigned cchUuid = RT_MIN(hSMBSys.smbs_uuidlen, sizeof(szData) - 1);
69 for (unsigned i = 0; i < cchUuid; i++)
70 {
71 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] >> 4];
72 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] & 0xf];
73 if (i == 3 || i == 5 || i == 7 || i == 9)
74 *pszData++ = '-';
75 }
76 *pszData = '\0';
77 rc = RTStrCopy(pszBuf, cbBuf, szData);
78 smbios_close(pSMB);
79 return rc;
80 }
81
82 smbios_info_t hSMBInfo;
83 id_t hSMBInfoId = smbios_info_common(pSMB, hSMBId, &hSMBInfo);
84 if (hSMBInfoId != SMB_ERR)
85 {
86 switch (enmString)
87 {
88 case RTSYSDMISTR_PRODUCT_NAME: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_product); break;
89 case RTSYSDMISTR_PRODUCT_VERSION: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_version); break;
90 case RTSYSDMISTR_PRODUCT_SERIAL: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_serial); break;
91
92 default: /* make gcc happy */
93 rc = VERR_NOT_SUPPORTED;
94 }
95 smbios_close(pSMB);
96 return rc;
97 }
98 }
99
100 /* smbios_* error path. */
101 err = smbios_errno(pSMB);
102 smbios_close(pSMB);
103 }
104
105 /* Do some error conversion. */
106 if (err == EPERM || err == EACCES)
107 rc = VERR_ACCESS_DENIED;
108 return rc;
109}
110
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette