VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/linux/RTSystemQueryDmiString-linux.cpp@ 100315

Last change on this file since 100315 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: RTSystemQueryDmiString-linux.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryDmiString, linux ring-3.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/system.h>
42#include "internal/iprt.h"
43
44#include <iprt/err.h>
45#include <iprt/assert.h>
46#include <iprt/linux/sysfs.h>
47
48#include <errno.h>
49
50
51RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
52{
53 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
54 AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
55 *pszBuf = '\0';
56 AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
57
58 const char *pszSysFsName;
59 switch (enmString)
60 {
61 case RTSYSDMISTR_PRODUCT_NAME: pszSysFsName = "id/product_name"; break;
62 case RTSYSDMISTR_PRODUCT_VERSION: pszSysFsName = "id/product_version"; break;
63 case RTSYSDMISTR_PRODUCT_UUID: pszSysFsName = "id/product_uuid"; break;
64 case RTSYSDMISTR_PRODUCT_SERIAL: pszSysFsName = "id/product_serial"; break;
65 case RTSYSDMISTR_MANUFACTURER: pszSysFsName = "id/sys_vendor"; break;
66 default:
67 return VERR_NOT_SUPPORTED;
68 }
69
70 size_t cbRead = 0;
71 int rc = RTLinuxSysFsReadStrFile(pszBuf, cbBuf, &cbRead, "devices/virtual/dmi/%s", pszSysFsName);
72 if (RT_FAILURE(rc) && rc != VERR_BUFFER_OVERFLOW)
73 rc = RTLinuxSysFsReadStrFile(pszBuf, cbBuf, &cbRead, "class/dmi/%s", pszSysFsName);
74 if (RT_FAILURE(rc) && rc != VERR_BUFFER_OVERFLOW)
75 {
76 switch (rc)
77 {
78 case VINF_SUCCESS:
79 AssertFailed();
80 break;
81 case VERR_FILE_NOT_FOUND:
82 case VERR_PATH_NOT_FOUND:
83 case VERR_IS_A_DIRECTORY:
84 rc = VERR_NOT_SUPPORTED;
85 break;
86 case VERR_PERMISSION_DENIED:
87 case VERR_ACCESS_DENIED:
88 rc = VERR_ACCESS_DENIED;
89 break;
90 }
91 }
92
93 return rc;
94}
95RT_EXPORT_SYMBOL(RTSystemQueryDmiString);
96
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