VirtualBox

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

Last change on this file since 27513 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: 3.7 KB
Line 
1/* $Id: RTSystemQueryDmiString-linux.cpp 27129 2010-03-06 00:16:08Z vboxsync $ */
2/** @file
3 * IPRT - RTSystemQueryDmiString, linux 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/linux/sysfs.h>
41
42#include <errno.h>
43
44
45RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
46{
47 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
48 AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
49 *pszBuf = '\0';
50 AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
51
52 const char *pszSysFsName;
53 switch (enmString)
54 {
55 case RTSYSDMISTR_PRODUCT_NAME: pszSysFsName = "id/product_name"; break;
56 case RTSYSDMISTR_PRODUCT_VERSION: pszSysFsName = "id/product_version"; break;
57 case RTSYSDMISTR_PRODUCT_UUID: pszSysFsName = "id/product_uuid"; break;
58 case RTSYSDMISTR_PRODUCT_SERIAL: pszSysFsName = "id/product_serial"; break;
59 default:
60 return VERR_NOT_SUPPORTED;
61 }
62
63 int rc;
64 int fd = RTLinuxSysFsOpen("devices/virtual/dmi/%s", pszSysFsName);
65 if (fd < 0)
66 fd = RTLinuxSysFsOpen("class/dmi/%s", pszSysFsName);
67 if (fd >= 0)
68 {
69 size_t cbRead;
70 rc = RTLinuxSysFsReadFile(fd, pszBuf, cbBuf, &cbRead);
71 if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW)
72 {
73 /* The file we're reading may end with a newline, remove it. */
74 if (cbRead == cbBuf)
75 pszBuf[cbRead - 1] = '\0';
76 else
77 {
78 AssertRC(rc);
79 pszBuf[cbRead] = '\0';
80 if (cbRead > 0 && pszBuf[cbRead - 1] == '\n')
81 pszBuf[cbRead - 1] = '\0';
82 }
83 }
84 RTLinuxSysFsClose(fd);
85 }
86 else
87 {
88 rc = RTErrConvertFromErrno(errno);
89 switch (rc)
90 {
91 case VINF_SUCCESS:
92 AssertFailed();
93 case VERR_FILE_NOT_FOUND:
94 case VERR_PATH_NOT_FOUND:
95 case VERR_IS_A_DIRECTORY:
96 rc = VERR_NOT_SUPPORTED;
97 break;
98 case VERR_PERMISSION_DENIED:
99 case VERR_ACCESS_DENIED:
100 rc = VERR_ACCESS_DENIED;
101 break;
102 }
103 }
104
105 return rc;
106}
107RT_EXPORT_SYMBOL(RTSystemQueryDmiString);
108
Note: See TracBrowser for help on using the repository browser.

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