VirtualBox

忽略:
時間撮記:
2016-4-7 下午02:21:30 (9 年 以前)
作者:
vboxsync
訊息:

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

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • 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    }
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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