VirtualBox

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

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

IPRT: linux implementation of RTSystemQueryDmiString.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: RTSystemQueryDmiString-linux.cpp 26608 2010-02-17 12:48:33Z 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 = "devices/virtual/dmi/id/product_name"; break;
56 case RTSYSDMISTR_PRODUCT_VERSION: pszSysFsName = "devices/virtual/dmi/id/product_version"; break;
57 case RTSYSDMISTR_PRODUCT_UUID: pszSysFsName = "devices/virtual/dmi/id/product_uuid"; break;
58 case RTSYSDMISTR_PRODUCT_SERIAL: pszSysFsName = "devices/virtual/dmi/id/product_serial"; break;
59 default:
60 return VERR_NOT_SUPPORTED;
61 }
62
63 int rc;
64 int fd = RTLinuxSysFsOpen(pszSysFsName);
65 if (fd >= 0)
66 {
67 /* Note! This will return VERR_BUFFER_OVERFLOW even if there is a
68 trailing newline that we don't care about. */
69 size_t cbRead;
70 rc = RTLinuxSysFsReadFile(fd, pszBuf, cbBuf - 1, &cbRead);
71 if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW)
72 {
73 pszBuf[cbRead] = '\0';
74 while (cbRead > 0 && pszBuf[cbRead - 1] == '\n')
75 pszBuf[--cbRead] = '\0';
76 }
77 RTLinuxSysFsClose(fd);
78 }
79 else
80 {
81 rc = RTErrConvertFromErrno(errno);
82 switch (rc)
83 {
84 case VINF_SUCCESS:
85 AssertFailed();
86 case VERR_FILE_NOT_FOUND:
87 case VERR_PATH_NOT_FOUND:
88 case VERR_IS_A_DIRECTORY:
89 rc = VERR_NOT_SUPPORTED;
90 break;
91 case VERR_PERMISSION_DENIED:
92 case VERR_ACCESS_DENIED:
93 rc = VERR_ACCESS_DENIED;
94 break;
95 }
96 }
97
98 return rc;
99}
100RT_EXPORT_SYMBOL(RTSystemQueryDmiString);
101
102
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