VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: RTSystemQueryDmiString-solaris.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryDmiString, solaris ring-3.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
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
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/system.h>
32#include "internal/iprt.h"
33
34#include <iprt/err.h>
35#include <iprt/assert.h>
36#include <iprt/string.h>
37
38#include <smbios.h>
39#include <errno.h>
40
41
42RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
43{
44 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
45 AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
46 *pszBuf = '\0';
47 AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
48
49 int rc = VERR_NOT_SUPPORTED;
50 int err = 0;
51 smbios_hdl_t *pSMB = smbios_open(NULL /* default fd */, SMB_VERSION, 0 /* flags */, &err);
52 if (pSMB)
53 {
54 smbios_system_t hSMBSys;
55 id_t hSMBId = smbios_info_system(pSMB, &hSMBSys);
56 if (hSMBId != SMB_ERR)
57 {
58 /* Don't need the common bits for the product UUID. */
59 if (enmString == RTSYSDMISTR_PRODUCT_UUID)
60 {
61 static char const s_szHex[17] = "0123456789ABCDEF";
62 char szData[64];
63 char *pszData = szData;
64 unsigned cchUuid = RT_MIN(hSMBSys.smbs_uuidlen, sizeof(szData) - 1);
65 for (unsigned i = 0; i < cchUuid; i++)
66 {
67 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] >> 4];
68 *pszData++ = s_szHex[hSMBSys.smbs_uuid[i] & 0xf];
69 if (i == 3 || i == 5 || i == 7 || i == 9)
70 *pszData++ = '-';
71 }
72 *pszData = '\0';
73 rc = RTStrCopy(pszBuf, cbBuf, szData);
74 smbios_close(pSMB);
75 return rc;
76 }
77
78 smbios_info_t hSMBInfo;
79 id_t hSMBInfoId = smbios_info_common(pSMB, hSMBId, &hSMBInfo);
80 if (hSMBInfoId != SMB_ERR)
81 {
82 switch (enmString)
83 {
84 case RTSYSDMISTR_PRODUCT_NAME: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_product); break;
85 case RTSYSDMISTR_PRODUCT_VERSION: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_version); break;
86 case RTSYSDMISTR_PRODUCT_SERIAL: rc = RTStrCopy(pszBuf, cbBuf, hSMBInfo.smbi_serial); break;
87
88 default: /* make gcc happy */
89 rc = VERR_NOT_SUPPORTED;
90 }
91 smbios_close(pSMB);
92 return rc;
93 }
94 }
95
96 /* smbios_* error path. */
97 err = smbios_errno(pSMB);
98 smbios_close(pSMB);
99 }
100
101 /* Do some error conversion. */
102 if (err == EPERM || err == EACCES)
103 rc = VERR_ACCESS_DENIED;
104 return rc;
105}
106
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