- 時間撮記:
- 2016-4-7 下午02:21:30 (9 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r60154 r60373 879 879 return VINF_SUCCESS; 880 880 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)) 883 884 return VINF_SUCCESS; 884 885 885 dev_t devnum = usbsysfsMakeDevNum(bus, device);886 dev_t devnum = usbsysfsMakeDevNum(bus, (int)device); 886 887 if (!devnum) 887 888 return VINF_SUCCESS; 888 889 889 890 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)) 896 896 return VINF_SUCCESS; 897 897 … … 899 899 if (usbsysfsInitDevInfo(&info, szDevPath, pcszNode)) 900 900 { 901 intrc = VEC_PUSH_BACK_OBJ(pvecDevInfo, USBDeviceInfo, &info);901 rc = VEC_PUSH_BACK_OBJ(pvecDevInfo, USBDeviceInfo, &info); 902 902 if (RT_SUCCESS(rc)) 903 903 return VINF_SUCCESS; … … 1227 1227 1228 1228 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 */ 1239 static 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 */ 1264 static 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 1229 1279 static void usbsysfsFillInDevice(USBDEVICE *pDev, USBDeviceInfo *pInfo) 1230 1280 { … … 1235 1285 pDev->enmState = USBDEVICESTATE_UNUSED; 1236 1286 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); 1244 1294 1245 1295 /* Now deal with the non-numeric bits. */ … … 1247 1297 * will need, and insane devices can be unsupported 1248 1298 * until further notice. */ 1249 s size_t cchRead;1299 size_t cchRead; 1250 1300 1251 1301 /* 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)) 1254 1304 pDev->enmState = USBDEVICESTATE_UNSUPPORTED; 1255 1305 else … … 1260 1310 : USBDEVICESPEED_UNKNOWN; 1261 1311 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)) 1264 1314 pDev->enmState = USBDEVICESTATE_UNSUPPORTED; 1265 1315 else … … 1273 1323 } 1274 1324 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)) 1277 1327 pDev->bcdDevice = UINT16_MAX; 1278 1328 else … … 1284 1334 1285 1335 /* 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)) 1288 1338 { 1289 1339 USBLibPurgeEncoding(szBuf); … … 1291 1341 } 1292 1342 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)) 1295 1345 { 1296 1346 USBLibPurgeEncoding(szBuf); … … 1299 1349 } 1300 1350 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)) 1303 1353 { 1304 1354 USBLibPurgeEncoding(szBuf); … … 1314 1364 VEC_FOR_EACH(&pInfo->mvecpszInterfaces, char *, ppszIf) 1315 1365 { 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) 1318 1368 pDev->enmState = (strcmp(szBuf, "hub") == 0) 1319 1369 ? USBDEVICESTATE_UNSUPPORTED 1320 1370 : 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 */) 1322 1372 pDev->enmState = USBDEVICESTATE_UNSUPPORTED; 1323 1373 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器