VirtualBox

Ignore:
Timestamp:
Apr 7, 2016 2:21:30 PM (9 years ago)
Author:
vboxsync
Message:

Runtime/linux/sysfs.cpp: Convert RTLinuxSysFs* API to always use IPRT status codes instead of using errno and adapt all of its users

Location:
trunk/src/VBox/Main/src-server/linux
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/HostHardwareLinux.cpp

    r59960 r60373  
    610610    bool findDeviceNode()
    611611    {
    612         dev_t dev = RTLinuxSysFsReadDevNumFile("block/%s/dev", mpcszName);
    613         if (dev == 0)
     612        dev_t dev = 0;
     613        int rc = RTLinuxSysFsReadDevNumFile(&dev, "block/%s/dev", mpcszName);
     614        if (RT_FAILURE(rc) || dev == 0)
    614615        {
    615616            misConsistent = false;
    616617            return false;
    617618        }
    618         if (RTLinuxCheckDevicePath(dev, RTFS_TYPE_DEV_BLOCK, mszNode,
    619                                    sizeof(mszNode), "%s", mpcszName) < 0)
     619        rc = RTLinuxCheckDevicePath(dev, RTFS_TYPE_DEV_BLOCK, mszNode,
     620                                    sizeof(mszNode), "%s", mpcszName);
     621        if (RT_FAILURE(rc))
    620622            return false;
    621623        return true;
     
    630632    {
    631633        char szVendor[128], szModel[128];
    632         ssize_t cchVendor, cchModel;
    633         int64_t type = RTLinuxSysFsReadIntFile(10, "block/%s/device/type",
    634                                                mpcszName);
    635         if (type >= 0 && type != TYPE_ROM)
     634        int64_t type = 0;
     635        int rc = RTLinuxSysFsReadIntFile(10, &type, "block/%s/device/type", mpcszName);
     636        if (RT_SUCCESS(rc) && type != TYPE_ROM)
    636637            return;
    637638        if (type == TYPE_ROM)
    638639        {
    639             cchVendor = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor),
    640                                                 "block/%s/device/vendor",
    641                                                 mpcszName);
    642             if (cchVendor >= 0)
     640            rc = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor), NULL,
     641                                         "block/%s/device/vendor", mpcszName);
     642            if (RT_SUCCESS(rc))
    643643            {
    644                 cchModel = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel),
    645                                                    "block/%s/device/model",
    646                                                    mpcszName);
    647                 if (cchModel >= 0)
     644                rc = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel), NULL,
     645                                             "block/%s/device/model", mpcszName);
     646                if (RT_SUCCESS(rc))
    648647                {
    649648                    misValid = true;
     
    697696        if (!noProbe())
    698697            haveName = floppyGetName(mszNode, mpcszName[2] - '0', szName);
    699         if (RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), "block/%s/%s",
    700                                     mpcszName, "device/driver") >= 0)
     698        int rc = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), NULL, "block/%s/%s",
     699                                         mpcszName, "device/driver");
     700        if (RT_SUCCESS(rc))
    701701        {
    702702            if (RTStrCmp(szDriver, "floppy"))
  • trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp

    r56030 r60373  
    253253    else
    254254    {
    255         int64_t cSize = RTLinuxSysFsReadIntFile(0, pszPath);
    256         if (cSize < 0)
    257             rc = VERR_ACCESS_DENIED;
    258         else
     255        int64_t cSize = 0;
     256        rc = RTLinuxSysFsReadIntFile(0, &cSize, pszPath);
     257        if (RT_SUCCESS(rc))
    259258            *size = cSize * 512;
    260259    }
     
    325324        return VERR_FILE_NOT_FOUND;
    326325
    327     int64_t cSize = RTLinuxSysFsReadIntFile(0, szIfName);
    328     if (cSize < 0)
    329         return VERR_ACCESS_DENIED;
     326    int64_t cSize = 0;
     327    int rc = RTLinuxSysFsReadIntFile(0, &cSize, szIfName);
     328    if (RT_FAILURE(rc))
     329        return rc;
    330330
    331331    *rx = cSize;
     
    335335        return VERR_FILE_NOT_FOUND;
    336336
    337     cSize = RTLinuxSysFsReadIntFile(0, szIfName);
    338     if (cSize < 0)
    339         return VERR_ACCESS_DENIED;
     337    rc = RTLinuxSysFsReadIntFile(0, &cSize, szIfName);
     338    if (RT_FAILURE(rc))
     339        return rc;
    340340
    341341    *tx = cSize;
  • trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp

    r60154 r60373  
    879879        return VINF_SUCCESS;
    880880
    881     int device = RTLinuxSysFsReadIntFile(10, "%s/devnum", pcszNode);
    882     if (device < 0)
     881    int64_t device;
     882    int rc = RTLinuxSysFsReadIntFile(10, &device, "%s/devnum", pcszNode);
     883    if (RT_FAILURE(rc))
    883884        return VINF_SUCCESS;
    884885
    885     dev_t devnum = usbsysfsMakeDevNum(bus, device);
     886    dev_t devnum = usbsysfsMakeDevNum(bus, (int)device);
    886887    if (!devnum)
    887888        return VINF_SUCCESS;
    888889
    889890    char szDevPath[RTPATH_MAX];
    890     ssize_t cchDevPath;
    891     cchDevPath = RTLinuxCheckDevicePath(devnum, RTFS_TYPE_DEV_CHAR,
    892                                         szDevPath, sizeof(szDevPath),
    893                                         "%s/%.3d/%.3d",
    894                                         pcszDevicesRoot, bus, device);
    895     if (cchDevPath < 0)
     891    rc = RTLinuxCheckDevicePath(devnum, RTFS_TYPE_DEV_CHAR,
     892                                szDevPath, sizeof(szDevPath),
     893                                "%s/%.3d/%.3d",
     894                                pcszDevicesRoot, bus, device);
     895    if (RT_FAILURE(rc))
    896896        return VINF_SUCCESS;
    897897
     
    899899    if (usbsysfsInitDevInfo(&info, szDevPath, pcszNode))
    900900    {
    901         int rc = VEC_PUSH_BACK_OBJ(pvecDevInfo, USBDeviceInfo, &info);
     901        rc = VEC_PUSH_BACK_OBJ(pvecDevInfo, USBDeviceInfo, &info);
    902902        if (RT_SUCCESS(rc))
    903903            return VINF_SUCCESS;
     
    12271227
    12281228
     1229/**
     1230 * Returns the byte value for the given device property or sets the given default if an
     1231 * error occurs while obtaining it.
     1232 *
     1233 * @returns uint8_t value of the given property.
     1234 * @param   uBase       The base of the number in the sysfs property.
     1235 * @param   bDef        The default to set on error.
     1236 * @param   pszFormat   The format string for the property.
     1237 * @param   ...         Arguments for the format string.
     1238 */
     1239static uint8_t usbsysfsReadDevicePropertyU8Def(unsigned uBase, uint8_t bDef, const char *pszFormat, ...)
     1240{
     1241    int64_t i64Tmp = 0;
     1242
     1243    va_list va;
     1244    va_start(va, pszFormat);
     1245    int rc = RTLinuxSysFsReadIntFileV(uBase, &i64Tmp, pszFormat, va);
     1246    va_end(va);
     1247    if (RT_SUCCESS(rc))
     1248        return (uint8_t)i64Tmp;
     1249    else
     1250        return bDef;
     1251}
     1252
     1253
     1254/**
     1255 * Returns the uint16_t value for the given device property or sets the given default if an
     1256 * error occurs while obtaining it.
     1257 *
     1258 * @returns uint16_t value of the given property.
     1259 * @param   uBase       The base of the number in the sysfs property.
     1260 * @param   u16Def      The default to set on error.
     1261 * @param   pszFormat   The format string for the property.
     1262 * @param   ...         Arguments for the format string.
     1263 */
     1264static uint8_t usbsysfsReadDevicePropertyU16Def(unsigned uBase, uint16_t u16Def, const char *pszFormat, ...)
     1265{
     1266    int64_t i64Tmp = 0;
     1267
     1268    va_list va;
     1269    va_start(va, pszFormat);
     1270    int rc = RTLinuxSysFsReadIntFileV(uBase, &i64Tmp, pszFormat, va);
     1271    va_end(va);
     1272    if (RT_SUCCESS(rc))
     1273        return (uint16_t)i64Tmp;
     1274    else
     1275        return u16Def;
     1276}
     1277
     1278
    12291279static void usbsysfsFillInDevice(USBDEVICE *pDev, USBDeviceInfo *pInfo)
    12301280{
     
    12351285    pDev->enmState           = USBDEVICESTATE_UNUSED;
    12361286    pDev->bBus               = usbsysfsGetBusFromPath(pszSysfsPath);
    1237     pDev->bDeviceClass       = RTLinuxSysFsReadIntFile(16, "%s/bDeviceClass", pszSysfsPath);
    1238     pDev->bDeviceSubClass    = RTLinuxSysFsReadIntFile(16, "%s/bDeviceSubClass", pszSysfsPath);
    1239     pDev->bDeviceProtocol    = RTLinuxSysFsReadIntFile(16, "%s/bDeviceProtocol", pszSysfsPath);
    1240     pDev->bNumConfigurations = RTLinuxSysFsReadIntFile(10, "%s/bNumConfigurations", pszSysfsPath);
    1241     pDev->idVendor           = RTLinuxSysFsReadIntFile(16, "%s/idVendor", pszSysfsPath);
    1242     pDev->idProduct          = RTLinuxSysFsReadIntFile(16, "%s/idProduct", pszSysfsPath);
    1243     pDev->bDevNum            = RTLinuxSysFsReadIntFile(10, "%s/devnum", pszSysfsPath);
     1287    pDev->bDeviceClass       = usbsysfsReadDevicePropertyU8Def(16, 0, "%s/bDeviceClass", pszSysfsPath);
     1288    pDev->bDeviceSubClass    = usbsysfsReadDevicePropertyU8Def(16, 0, "%s/bDeviceSubClass", pszSysfsPath);
     1289    pDev->bDeviceProtocol    = usbsysfsReadDevicePropertyU8Def(16, 0, "%s/bDeviceProtocol", pszSysfsPath);
     1290    pDev->bNumConfigurations = usbsysfsReadDevicePropertyU8Def(10, 0, "%s/bNumConfigurations", pszSysfsPath);
     1291    pDev->idVendor           = usbsysfsReadDevicePropertyU16Def(16, 0, "%s/idVendor", pszSysfsPath);
     1292    pDev->idProduct          = usbsysfsReadDevicePropertyU16Def(16, 0, "%s/idProduct", pszSysfsPath);
     1293    pDev->bDevNum            = usbsysfsReadDevicePropertyU8Def(10, 0, "%s/devnum", pszSysfsPath);
    12441294
    12451295    /* Now deal with the non-numeric bits. */
     
    12471297                        * will need, and insane devices can be unsupported
    12481298                        * until further notice. */
    1249     ssize_t cchRead;
     1299    size_t cchRead;
    12501300
    12511301    /* For simplicity, we just do strcmps on the next one. */
    1252     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/speed", pszSysfsPath);
    1253     if (cchRead <= 0 || (size_t) cchRead == sizeof(szBuf))
     1302    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/speed", pszSysfsPath);
     1303    if (RT_FAILURE(rc) || cchRead == sizeof(szBuf))
    12541304        pDev->enmState = USBDEVICESTATE_UNSUPPORTED;
    12551305    else
     
    12601310                       : USBDEVICESPEED_UNKNOWN;
    12611311
    1262     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/version", pszSysfsPath);
    1263     if (cchRead <= 0 || (size_t) cchRead == sizeof(szBuf))
     1312    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/version", pszSysfsPath);
     1313    if (RT_FAILURE(rc) || cchRead == sizeof(szBuf))
    12641314        pDev->enmState = USBDEVICESTATE_UNSUPPORTED;
    12651315    else
     
    12731323    }
    12741324
    1275     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/bcdDevice", pszSysfsPath);
    1276     if (cchRead <= 0 || (size_t) cchRead == sizeof(szBuf))
     1325    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/bcdDevice", pszSysfsPath);
     1326    if (RT_FAILURE(rc) || cchRead == sizeof(szBuf))
    12771327        pDev->bcdDevice = UINT16_MAX;
    12781328    else
     
    12841334
    12851335    /* Now do things that need string duplication */
    1286     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/product", pszSysfsPath);
    1287     if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf))
     1336    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/product", pszSysfsPath);
     1337    if (RT_SUCCESS(rc) && cchRead < sizeof(szBuf))
    12881338    {
    12891339        USBLibPurgeEncoding(szBuf);
     
    12911341    }
    12921342
    1293     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/serial", pszSysfsPath);
    1294     if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf))
     1343    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/serial", pszSysfsPath);
     1344    if (RT_SUCCESS(rc) && cchRead < sizeof(szBuf))
    12951345    {
    12961346        USBLibPurgeEncoding(szBuf);
     
    12991349    }
    13001350
    1301     cchRead = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), "%s/manufacturer", pszSysfsPath);
    1302     if (cchRead > 0 && (size_t) cchRead < sizeof(szBuf))
     1351    rc = RTLinuxSysFsReadStrFile(szBuf, sizeof(szBuf), &cchRead, "%s/manufacturer", pszSysfsPath);
     1352    if (RT_SUCCESS(rc) && cchRead < sizeof(szBuf))
    13031353    {
    13041354        USBLibPurgeEncoding(szBuf);
     
    13141364    VEC_FOR_EACH(&pInfo->mvecpszInterfaces, char *, ppszIf)
    13151365    {
    1316         ssize_t cb = RTLinuxSysFsGetLinkDest(szBuf, sizeof(szBuf), "%s/driver", *ppszIf);
    1317         if (cb > 0 && pDev->enmState != USBDEVICESTATE_UNSUPPORTED)
     1366        rc = RTLinuxSysFsGetLinkDest(szBuf, sizeof(szBuf), NULL, "%s/driver", *ppszIf);
     1367        if (RT_SUCCESS(rc) && pDev->enmState != USBDEVICESTATE_UNSUPPORTED)
    13181368            pDev->enmState = (strcmp(szBuf, "hub") == 0)
    13191369                           ? USBDEVICESTATE_UNSUPPORTED
    13201370                           : USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
    1321         if (RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass", *ppszIf) == 9 /* hub */)
     1371        if (usbsysfsReadDevicePropertyU8Def(16, 9 /* bDev */, "%s/bInterfaceClass", *ppszIf) == 9 /* hub */)
    13221372            pDev->enmState = USBDEVICESTATE_UNSUPPORTED;
    13231373    }
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