VirtualBox

Changeset 26608 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 17, 2010 12:48:33 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: linux implementation of RTSystemQueryDmiString.

Location:
trunk/src/VBox/Runtime
Files:
1 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r26600 r26608  
    471471        generic/RTFileMove-generic.cpp \
    472472        generic/RTLogWriteDebugger-generic.cpp \
    473         generic/RTSystemQueryDmiString-generic.cpp \
    474473        generic/RTTimeLocalNow-generic.cpp \
    475474        generic/RTTimerCreate-generic.cpp \
     
    485484        r3/linux/time-linux.cpp \
    486485        r3/linux/RTProcIsRunningByName-linux.cpp \
     486        r3/linux/RTSystemQueryDmiString-linux.cpp \
    487487        r3/posix/RTFileQueryFsSizes-posix.cpp \
    488488        r3/posix/RTSystemQueryOSInfo-posix.cpp \
  • trunk/src/VBox/Runtime/generic/RTSystemQueryDmiString-generic.cpp

    r26600 r26608  
    4242RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
    4343{
    44     AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
    4544    AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
    4645    AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
     46    *pszBuf = '\0';
     47    AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);
    4748    return VERR_NOT_SUPPORTED;
    4849}
  • trunk/src/VBox/Runtime/r3/linux/sysfs.cpp

    r26253 r26608  
    208208    pszBuf[cchRead >= 0 ? cchRead : 0] = '\0';
    209209    return cchRead;
     210}
     211
     212
     213RTDECL(int) RTLinuxSysFsReadFile(int fd, void *pvBuf, size_t cbBuf, size_t *pcbRead)
     214{
     215    int     rc;
     216    ssize_t cbRead = read(fd, pvBuf, cbBuf);
     217    if (cbRead >= 0)
     218    {
     219        if (pcbRead)
     220            *pcbRead = cbRead;
     221        if ((size_t)cbRead < cbBuf)
     222            rc = VINF_SUCCESS;
     223        else
     224        {
     225            /* Check for EOF */
     226            char    ch;
     227            off_t   off     = lseek(fd, 0, SEEK_CUR);
     228            ssize_t cbRead2 = read(fd, &ch, 1);
     229            if (cbRead2 == 0)
     230                rc = VINF_SUCCESS;
     231            else if (cbRead2 > 0)
     232            {
     233                lseek(fd, off, SEEK_SET);
     234                rc = VERR_BUFFER_OVERFLOW;
     235            }
     236            else
     237                rc = RTErrConvertFromErrno(errno);
     238        }
     239    }
     240    else
     241        rc = RTErrConvertFromErrno(errno);
     242    return rc;
    210243}
    211244
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r26605 r26608  
    104104        tstStrToNum \
    105105        tstRTStrVersion \
     106        tstRTSystemQueryDmi \
    106107        tstRTSystemQueryOsInfo \
    107108        tstRTTemp \
     
    408409tstRTStrVersion_SOURCES = tstRTStrVersion.cpp
    409410
     411tstRTSystemQueryDmi_TEMPLATE = VBOXR3TSTEXE
     412tstRTSystemQueryDmi_SOURCES = tstRTSystemQueryDmi.cpp
     413
    410414tstRTSystemQueryOsInfo_TEMPLATE = VBOXR3TSTEXE
    411415tstRTSystemQueryOsInfo_SOURCES = tstRTSystemQueryOsInfo.cpp
  • trunk/src/VBox/Runtime/testcase/tstRTSystemQueryDmi.cpp

    r26605 r26608  
    11/* $Id$ */
    22/** @file
    3  * IPRT Testcase - RTSystemQueryOSInfo.
     3 * IPRT Testcase - RTSystemQueryDmi*.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333*******************************************************************************/
    3434#include <iprt/system.h>
     35
     36#include <iprt/assert.h>
    3537#include <iprt/string.h>
    3638#include <iprt/test.h>
    37 
    38 
    39 /*******************************************************************************
    40 *   Global Variables                                                           *
    41 *******************************************************************************/
    42 static int g_cErrors = 0;
    4339
    4440
     
    4642{
    4743    RTTEST hTest;
    48     int rc = RTTestInitAndCreate("tstRTSystemQueryOsInfo", &hTest);
     44    int rc = RTTestInitAndCreate("tstRTSystemQueryDmi", &hTest);
    4945    if (rc)
    5046        return rc;
     
    5652    char szInfo[256];
    5753
    58     rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szInfo, sizeof(szInfo));
    59     RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT: \"%s\", rc=%Rrc\n", szInfo, rc);
     54    rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szInfo, sizeof(szInfo));
     55    RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_NAME: \"%s\", rc=%Rrc\n", szInfo, rc);
    6056
    61     rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szInfo, sizeof(szInfo));
    62     RTTestIPrintf(RTTESTLVL_ALWAYS, "RELEASE: \"%s\", rc=%Rrc\n", szInfo, rc);
     57    rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_VERSION, szInfo, sizeof(szInfo));
     58    RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_VERSION: \"%s\", rc=%Rrc\n", szInfo, rc);
    6359
    64     rc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szInfo, sizeof(szInfo));
    65     RTTestIPrintf(RTTESTLVL_ALWAYS, "VERSION: \"%s\", rc=%Rrc\n", szInfo, rc);
     60    rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_UUID, szInfo, sizeof(szInfo));
     61    RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_UUID: \"%s\", rc=%Rrc\n", szInfo, rc);
    6662
    67     rc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szInfo, sizeof(szInfo));
    68     RTTestIPrintf(RTTESTLVL_ALWAYS, "SERVICE_PACK: \"%s\", rc=%Rrc\n", szInfo, rc);
     63    rc = RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_SERIAL, szInfo, sizeof(szInfo));
     64    RTTestIPrintf(RTTESTLVL_ALWAYS, "PRODUCT_SERIAL: \"%s\", rc=%Rrc\n", szInfo, rc);
    6965
    7066    /*
    7167     * Check that unsupported stuff is terminated correctly.
    7268     */
    73     for (int i = RTSYSOSINFO_INVALID + 1; i < RTSYSOSINFO_END; i++)
     69    for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++)
    7470    {
    7571        memset(szInfo, ' ', sizeof(szInfo));
    76         rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, sizeof(szInfo));
     72        rc = RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, sizeof(szInfo));
    7773        if (    rc == VERR_NOT_SUPPORTED
    7874            &&  szInfo[0] != '\0')
    7975            RTTestIFailed("level=%d; unterminated buffer on VERR_NOT_SUPPORTED\n", i);
    80         else if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW)
     76        else if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW || rc == VERR_ACCESS_DENIED)
    8177            RTTESTI_CHECK(memchr(szInfo, '\0', sizeof(szInfo)) != NULL);
    8278        else if (rc != VERR_NOT_SUPPORTED)
     
    8783     * Check buffer overflow
    8884     */
    89     for (int i = RTSYSOSINFO_INVALID + 1; i < RTSYSOSINFO_END; i++)
     85    RTAssertSetQuiet(true);
     86    RTAssertSetMayPanic(false);
     87    for (int i = RTSYSDMISTR_INVALID + 1; i < RTSYSDMISTR_END; i++)
    9088    {
    9189        rc = VERR_BUFFER_OVERFLOW;
     
    9391        {
    9492            memset(szInfo, 0x7f, sizeof(szInfo));
    95             rc = RTSystemQueryOSInfo((RTSYSOSINFO)i, szInfo, cch);
     93            rc = RTSystemQueryDmiString((RTSYSDMISTR)i, szInfo, cch);
    9694
    9795            /* check the padding. */
     
    109107                &&  cch > 0
    110108                &&  !memchr(szInfo, '\0', cch))
    111             {
    112 
    113109                RTTestIFailed("level=%d, rc=%Rrc, cch=%zu: Buffer not terminated!\n", i, rc, cch);
    114                 g_cErrors++;
    115             }
    116110        }
    117111    }
Note: See TracChangeset for help on using the changeset viewer.

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