- Timestamp:
- Jul 9, 2009 11:34:26 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 49820
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r19094 r21432 143 143 // this is a good guess usually 144 144 if (validateDevice("/dev/cdrom", true)) 145 try 146 { 147 mDVDList.push_back (DriveInfo ("/dev/cdrom")); 148 } 149 catch (std::bad_alloc) 150 { 151 rc = VERR_NO_MEMORY; 152 } 145 mDVDList.push_back(DriveInfo ("/dev/cdrom")); 153 146 154 147 // check the mounted drives … … 161 154 #endif 162 155 } 163 catch (std::bad_alloc)156 catch(std::bad_alloc &e) 164 157 { 165 158 rc = VERR_NO_MEMORY; … … 200 193 RTStrPrintf(devName, sizeof(devName), "/dev/fd%d", i); 201 194 if (validateDevice(devName, false)) 202 try 203 { 204 mFloppyList.push_back (DriveInfo (devName)); 205 } 206 catch (std::bad_alloc) 207 { 208 rc = VERR_NO_MEMORY; 209 } 195 mFloppyList.push_back (DriveInfo (devName)); 210 196 } 211 197 } 212 198 #endif 213 199 } 214 catch (std::bad_alloc)200 catch(std::bad_alloc &e) 215 201 { 216 202 rc = VERR_NO_MEMORY; … … 244 230 #endif /* RT_OS_LINUX */ 245 231 } 246 catch (std::bad_alloc)232 catch(std::bad_alloc &e) 247 233 { 248 234 rc = VERR_NO_MEMORY; … … 442 428 int rc = VINF_SUCCESS; 443 429 bool success = false; 444 RTMemAutoPtr<char, RTStrFree> drive; 445 const char *pszValue = RTEnvGet (pszVar); 446 if (pszValue != NULL) 447 { 448 drive = RTStrDup (pszValue); 449 if (!drive) 450 rc = VERR_NO_MEMORY; 451 } 452 if (pszValue != NULL && RT_SUCCESS (rc)) 453 { 454 char *pDrive = drive.get(); 455 char *pDriveNext = strchr (pDrive, ':'); 456 while (pDrive != NULL && *pDrive != '\0') 457 { 458 if (pDriveNext != NULL) 459 *pDriveNext = '\0'; 460 if (validateDevice(pDrive, isDVD)) 430 431 try 432 { 433 RTMemAutoPtr<char, RTStrFree> drive; 434 const char *pszValue = RTEnvGet (pszVar); 435 if (pszValue != NULL) 436 { 437 drive = RTStrDup (pszValue); 438 if (!drive) 439 rc = VERR_NO_MEMORY; 440 } 441 if (pszValue != NULL && RT_SUCCESS (rc)) 442 { 443 char *pDrive = drive.get(); 444 char *pDriveNext = strchr (pDrive, ':'); 445 while (pDrive != NULL && *pDrive != '\0') 461 446 { 462 try 447 if (pDriveNext != NULL) 448 *pDriveNext = '\0'; 449 if (validateDevice(pDrive, isDVD)) 463 450 { 464 451 pList->push_back (DriveInfo (pDrive)); 452 success = true; 465 453 } 466 catch (std::bad_alloc)454 if (pDriveNext != NULL) 467 455 { 468 rc = VERR_NO_MEMORY; 456 pDrive = pDriveNext + 1; 457 pDriveNext = strchr (pDrive, ':'); 469 458 } 470 success = true; 459 else 460 pDrive = NULL; 471 461 } 472 if (pDriveNext != NULL)473 {474 pDrive = pDriveNext + 1;475 pDriveNext = strchr (pDrive, ':');476 }477 else478 pDrive = NULL;479 462 } 480 } 481 if (pfSuccess != NULL) 482 *pfSuccess = success; 463 if (pfSuccess != NULL) 464 *pfSuccess = success; 465 } 466 catch(std::bad_alloc &e) 467 { 468 rc = VERR_NO_MEMORY; 469 } 483 470 LogFlowFunc (("rc=%Rrc, success=%d\n", rc, success)); 484 471 return rc; … … 500 487 if (mtab) 501 488 { 502 struct mntent *mntent; 503 RTMemAutoPtr <char, RTStrFree> mnt_type, mnt_dev; 504 char *tmp; 505 while (RT_SUCCESS (rc) && (mntent = getmntent(mtab))) 506 { 507 mnt_type = RTStrDup (mntent->mnt_type); 508 mnt_dev = RTStrDup (mntent->mnt_fsname); 509 if (!mnt_type || !mnt_dev) 510 rc = VERR_NO_MEMORY; 511 // supermount fs case 512 if (RT_SUCCESS (rc) && strcmp(mnt_type.get(), "supermount") == 0) 489 try 490 { 491 struct mntent *mntent; 492 RTMemAutoPtr <char, RTStrFree> mnt_type, mnt_dev; 493 char *tmp; 494 while (RT_SUCCESS (rc) && (mntent = getmntent(mtab))) 513 495 { 514 tmp = strstr(mntent->mnt_opts, "fs="); 515 if (tmp) 496 mnt_type = RTStrDup (mntent->mnt_type); 497 mnt_dev = RTStrDup (mntent->mnt_fsname); 498 if (!mnt_type || !mnt_dev) 499 rc = VERR_NO_MEMORY; 500 // supermount fs case 501 if (RT_SUCCESS (rc) && strcmp(mnt_type.get(), "supermount") == 0) 516 502 { 517 mnt_type = RTStrDup(tmp + strlen("fs=")); 518 if (!mnt_type) 519 rc = VERR_NO_MEMORY; 520 else 503 tmp = strstr(mntent->mnt_opts, "fs="); 504 if (tmp) 521 505 { 522 tmp = strchr(mnt_type.get(), ','); 523 if (tmp) 524 *tmp = '\0'; 506 mnt_type = RTStrDup(tmp + strlen("fs=")); 507 if (!mnt_type) 508 rc = VERR_NO_MEMORY; 509 else 510 { 511 tmp = strchr(mnt_type.get(), ','); 512 if (tmp) 513 *tmp = '\0'; 514 } 515 } 516 tmp = strstr(mntent->mnt_opts, "dev="); 517 if (tmp) 518 { 519 mnt_dev = RTStrDup(tmp + strlen("dev=")); 520 if (!mnt_dev) 521 rc = VERR_NO_MEMORY; 522 else 523 { 524 tmp = strchr(mnt_dev.get(), ','); 525 if (tmp) 526 *tmp = '\0'; 527 } 525 528 } 526 529 } 527 tmp = strstr(mntent->mnt_opts, "dev=");528 if ( tmp)530 // use strstr here to cover things fs types like "udf,iso9660" 531 if (RT_SUCCESS (rc) && strstr(mnt_type.get(), "iso9660") == 0) 529 532 { 530 mnt_dev = RTStrDup(tmp + strlen("dev=")); 531 if (!mnt_dev) 532 rc = VERR_NO_MEMORY; 533 else 533 if (validateDevice(mnt_dev.get(), true)) 534 534 { 535 tmp = strchr(mnt_dev.get(), ','); 536 if (tmp) 537 *tmp = '\0'; 535 bool insert = true; 536 struct stat srcInfo; 537 if (stat (mnt_dev.get(), &srcInfo) < 0) 538 insert = false; 539 for (DriveInfoList::const_iterator it = pList->begin(); 540 insert && it != pList->end(); ++it) 541 { 542 struct stat destInfo; 543 if ( (stat (it->mDevice.c_str(), &destInfo) == 0) 544 && (srcInfo.st_rdev == destInfo.st_rdev)) 545 insert = false; 546 } 547 if (insert) 548 pList->push_back (DriveInfo (mnt_dev.get())); 538 549 } 539 550 } 540 551 } 541 // use strstr here to cover things fs types like "udf,iso9660" 542 if (RT_SUCCESS (rc) && strstr(mnt_type.get(), "iso9660") == 0) 543 { 544 if (validateDevice(mnt_dev.get(), true)) 545 { 546 bool insert = true; 547 struct stat srcInfo; 548 if (stat (mnt_dev.get(), &srcInfo) < 0) 549 insert = false; 550 for (DriveInfoList::const_iterator it = pList->begin(); 551 insert && it != pList->end(); ++it) 552 { 553 struct stat destInfo; 554 if ( (stat (it->mDevice.c_str(), &destInfo) == 0) 555 && (srcInfo.st_rdev == destInfo.st_rdev)) 556 insert = false; 557 } 558 if (insert) 559 try 560 { 561 pList->push_back (DriveInfo (mnt_dev.get())); 562 } 563 catch (std::bad_alloc) 564 { 565 rc = VERR_NO_MEMORY; 566 } 567 } 568 } 552 } 553 catch(std::bad_alloc &e) 554 { 555 rc = VERR_NO_MEMORY; 569 556 } 570 557 endmntent(mtab); … … 882 869 pMatches->push_back(pszUdi); 883 870 } 884 catch (std::bad_alloc)871 catch(std::bad_alloc &e) 885 872 { 886 873 rc = VERR_NO_MEMORY; … … 1040 1027 pMatches->push_back(fMatches ? values[i] : ""); 1041 1028 } 1042 catch (std::bad_alloc)1029 catch(std::bad_alloc &e) 1043 1030 { 1044 1031 rc = VERR_NO_MEMORY; … … 1128 1115 pList->push_back (DriveInfo (pszDevice, pszUdi, description)); 1129 1116 } 1130 catch (std::bad_alloc)1117 catch(std::bad_alloc &e) 1131 1118 { 1132 1119 rc = VERR_NO_MEMORY; … … 1213 1200 pList->push_back (info); 1214 1201 } 1215 catch (std::bad_alloc)1202 catch(std::bad_alloc &e) 1216 1203 { 1217 1204 rc = VERR_NO_MEMORY; … … 1299 1286 pList->push_back (info); 1300 1287 } 1301 catch (std::bad_alloc)1288 catch(std::bad_alloc &e) 1302 1289 { 1303 1290 rc = VERR_NO_MEMORY; … … 1388 1375 pList->push_back (pszSysfsPath); 1389 1376 } 1390 catch (std::bad_alloc)1377 catch(std::bad_alloc &e) 1391 1378 { 1392 1379 rc = VERR_NO_MEMORY;
Note:
See TracChangeset
for help on using the changeset viewer.