VirtualBox

Ignore:
Timestamp:
Aug 28, 2020 2:40:55 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140122
Message:

Main: bugref:9224: Main+VBoxManageDisk+doc part

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/freebsd/HostHardwareFreeBSD.cpp

    r82968 r85929  
    11/* $Id$ */
    22/** @file
    3  * Classes for handling hardware detection under FreeBSD.
     3 * VirtualBox Main - Code for handling hardware detection under FreeBSD, VBoxSVC.
    44 */
    55
     
    1616 */
    1717
    18 #define LOG_GROUP LOG_GROUP_MAIN
    19 
    2018
    2119/*********************************************************************************************************************************
    2220*   Header Files                                                                                                                 *
    2321*********************************************************************************************************************************/
    24 
    25 #include <HostHardwareLinux.h>
     22#define LOG_GROUP LOG_GROUP_MAIN
     23#include "HostHardwareLinux.h"
    2624
    2725#include <VBox/log.h>
     
    3533#include <iprt/string.h>
    3634
    37 #ifdef RT_OS_FREEBSD
    38 # include <sys/param.h>
    39 # include <sys/types.h>
    40 # include <sys/stat.h>
    41 # include <unistd.h>
    42 # include <stdio.h>
    43 # include <sys/ioctl.h>
    44 # include <fcntl.h>
    45 # include <cam/cam.h>
    46 # include <cam/cam_ccb.h>
    47 # include <cam/scsi/scsi_pass.h>
    48 #endif /* RT_OS_FREEBSD */
     35#include <sys/param.h>
     36#include <sys/types.h>
     37#include <sys/stat.h>
     38#include <unistd.h>
     39#include <stdio.h>
     40#include <sys/ioctl.h>
     41#include <fcntl.h>
     42#include <cam/cam.h>
     43#include <cam/cam_ccb.h>
     44#include <camlib.h>
     45#include <cam/scsi/scsi_pass.h>
     46
    4947#include <vector>
    5048
     
    5351*   Typedefs and Defines                                                                                                         *
    5452*********************************************************************************************************************************/
    55 
    56 static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList,
    57                                bool isDVD, bool *pfSuccess);
    58 static int getDVDInfoFromCAM(DriveInfoList *pList, bool *pfSuccess);
     53typedef enum DriveType_T
     54{
     55    Fixed,
     56    DVD,
     57    Any
     58} DriveType_T;
     59
     60
     61/*********************************************************************************************************************************
     62*   Internal Functions                                                                                                           *
     63*********************************************************************************************************************************/
     64static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList, bool isDVD, bool *pfSuccess) RT_NOTHROW_PROTP;
     65static int getDriveInfoFromCAM(DriveInfoList *pList, DriveType_T enmDriveType, bool *pfSuccess) RT_NOTHROW_PROTP;
     66
    5967
    6068/** Find the length of a string, ignoring trailing non-ascii or control
    61  * characters */
    62 static size_t strLenStripped(const char *pcsz)
     69 * characters
     70 * @note Code duplicated in HostHardwareLinux.cpp  */
     71static size_t strLenStripped(const char *pcsz) RT_NOTHROW_DEF
    6372{
    6473    size_t cch = 0;
    6574    for (size_t i = 0; pcsz[i] != '\0'; ++i)
    66         if (pcsz[i] > 32 && pcsz[i] < 127)
     75        if (pcsz[i] > 32 /*space*/ && pcsz[i] < 127 /*delete*/)
    6776            cch = i;
    6877    return cch + 1;
    6978}
    7079
    71 static void strLenRemoveTrailingWhiteSpace(char *psz, size_t cchStr)
    72 {
    73     while (   (cchStr > 0)
    74            && (psz[cchStr -1] == ' '))
    75         psz[--cchStr] = '\0';
    76 }
    7780
    7881/**
    79  * Initialise the device description for a DVD drive based on
    80  * vendor and model name strings.
    81  * @param pcszVendor  the vendor ID string
    82  * @param pcszModel   the product ID string
    83  * @param pszDesc    where to store the description string (optional)
    84  * @param cchDesc    the size of the buffer in @pszDesc
     82 * Initialize the device description for a drive based on vendor and model name
     83 * strings.
     84 *
     85 * @param   pcszVendor  The raw vendor ID string.
     86 * @param   pcszModel   The raw product ID string.
     87 * @param   pszDesc     Where to store the description string (optional)
     88 * @param   cbDesc      The size of the buffer in @pszDesc
     89 *
     90 * @note    Used for disks as well as DVDs.
    8591 */
    8692/* static */
    87 void dvdCreateDeviceString(const char *pcszVendor, const char *pcszModel,
    88                             char *pszDesc, size_t cchDesc)
     93void dvdCreateDeviceString(const char *pcszVendor, const char *pcszModel, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
    8994{
    9095    AssertPtrReturnVoid(pcszVendor);
    9196    AssertPtrReturnVoid(pcszModel);
    9297    AssertPtrNullReturnVoid(pszDesc);
    93     AssertReturnVoid(!pszDesc || cchDesc > 0);
     98    AssertReturnVoid(!pszDesc || cbDesc > 0);
    9499    size_t cchVendor = strLenStripped(pcszVendor);
    95100    size_t cchModel = strLenStripped(pcszModel);
     
    99104    {
    100105        if (cchVendor > 0)
    101             RTStrPrintf(pszDesc, cchDesc, "%.*s %s", cchVendor, pcszVendor,
     106            RTStrPrintf(pszDesc, cbDesc, "%.*s %s", cchVendor, pcszVendor,
    102107                        cchModel > 0 ? pcszModel : "(unknown drive model)");
    103108        else
    104             RTStrPrintf(pszDesc, cchDesc, "%s", pcszModel);
    105     }
    106 }
    107 
    108 
    109 int VBoxMainDriveInfo::updateDVDs ()
     109            RTStrPrintf(pszDesc, cbDesc, "%s", pcszModel);
     110        RTStrPurgeEncoding(pszDesc);
     111    }
     112}
     113
     114
     115int VBoxMainDriveInfo::updateDVDs() RT_NOEXCEPT
    110116{
    111117    LogFlowThisFunc(("entered\n"));
    112     int rc = VINF_SUCCESS;
    113     bool fSuccess = false;  /* Have we succeeded in finding anything yet? */
    114 
     118    int rc;
    115119    try
    116120    {
    117         mDVDList.clear ();
     121        mDVDList.clear();
    118122        /* Always allow the user to override our auto-detection using an
    119123         * environment variable. */
     124        bool fSuccess = false;  /* Have we succeeded in finding anything yet? */
     125        rc = getDriveInfoFromEnv("VBOX_CDROM", &mDVDList, true /* isDVD */, &fSuccess);
    120126        if (RT_SUCCESS(rc) && !fSuccess)
    121             rc = getDriveInfoFromEnv("VBOX_CDROM", &mDVDList, true /* isDVD */,
    122                                      &fSuccess);
    123         if (RT_SUCCESS(rc) && !fSuccess)
    124             rc = getDVDInfoFromCAM(&mDVDList, &fSuccess);
    125     }
    126     catch(std::bad_alloc &e)
     127            rc = getDriveInfoFromCAM(&mDVDList, DVD, &fSuccess);
     128    }
     129    catch (std::bad_alloc &)
    127130    {
    128131        rc = VERR_NO_MEMORY;
     
    132135}
    133136
    134 int VBoxMainDriveInfo::updateFloppies ()
     137int VBoxMainDriveInfo::updateFloppies() RT_NOEXCEPT
    135138{
    136139    LogFlowThisFunc(("entered\n"));
    137     int rc = VINF_SUCCESS;
    138     bool fSuccess = false;  /* Have we succeeded in finding anything yet? */
    139 
     140    int rc;
    140141    try
    141142    {
    142         mFloppyList.clear ();
    143         /* Always allow the user to override our auto-detection using an
    144          * environment variable. */
    145         if (RT_SUCCESS(rc) && !fSuccess)
    146             rc = getDriveInfoFromEnv("VBOX_FLOPPY", &mFloppyList, false /* isDVD */,
    147                                      &fSuccess);
    148     }
    149     catch(std::bad_alloc &e)
     143        /* Only got the enviornment variable here... */
     144        mFloppyList.clear();
     145        bool fSuccess = false;  /* ignored */
     146        rc = getDriveInfoFromEnv("VBOX_FLOPPY", &mFloppyList, false /* isDVD */, &fSuccess);
     147    }
     148    catch (std::bad_alloc &)
    150149    {
    151150        rc = VERR_NO_MEMORY;
     
    155154}
    156155
     156int VBoxMainDriveInfo::updateFixedDrives() RT_NOEXCEPT
     157{
     158    LogFlowThisFunc(("entered\n"));
     159    int rc;
     160    try
     161    {
     162        mFixedDriveList.clear();
     163        bool fSuccess = false;  /* ignored */
     164        rc = getDriveInfoFromCAM(&mFixedDriveList, Fixed, &fSuccess);
     165    }
     166    catch (std::bad_alloc &)
     167    {
     168        rc = VERR_NO_MEMORY;
     169    }
     170    LogFlowThisFunc(("rc=%Rrc\n", rc));
     171    return rc;
     172}
     173
     174static void strDeviceStringSCSI(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
     175{
     176    char szVendor[128];
     177    cam_strvis((uint8_t *)szVendor, (const uint8_t *)pDevResult->inq_data.vendor,
     178               sizeof(pDevResult->inq_data.vendor), sizeof(szVendor));
     179    char szProduct[128];
     180    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pDevResult->inq_data.product,
     181               sizeof(pDevResult->inq_data.product), sizeof(szProduct));
     182    dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
     183}
     184
     185static void strDeviceStringATA(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
     186{
     187    char szProduct[256];
     188    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pDevResult->ident_data.model,
     189               sizeof(pDevResult->ident_data.model), sizeof(szProduct));
     190    dvdCreateDeviceString("", szProduct, pszDesc, cbDesc);
     191}
     192
     193static void strDeviceStringSEMB(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
     194{
     195    sep_identify_data *pSid = (sep_identify_data *)&pDevResult->ident_data;
     196
     197    char szVendor[128];
     198    cam_strvis((uint8_t *)szVendor, (const uint8_t *)pSid->vendor_id,
     199               sizeof(pSid->vendor_id), sizeof(szVendor));
     200    char szProduct[128];
     201    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pSid->product_id,
     202               sizeof(pSid->product_id), sizeof(szProduct));
     203    dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
     204}
     205
     206static void strDeviceStringMMCSD(device_match_result *pDevResult, char *pszDesc, size_t cbDesc)  RT_NOTHROW_DEF
     207{
     208    struct cam_device *pDev = cam_open_btl(pDevResult->path_id, pDevResult->target_id,
     209                                           pDevResult->target_lun, O_RDWR, NULL);
     210    if (pDev == NULL)
     211    {
     212        Log(("Error while opening drive device. Error: %s\n", cam_errbuf));
     213        return;
     214    }
     215
     216    union ccb *pCcb = cam_getccb(pDev);
     217    if (pCcb != NULL)
     218    {
     219        struct mmc_params mmcIdentData;
     220        RT_ZERO(mmcIdentData);
     221
     222        struct ccb_dev_advinfo *pAdvi = &pCcb->cdai;
     223        pAdvi->ccb_h.flags = CAM_DIR_IN;
     224        pAdvi->ccb_h.func_code = XPT_DEV_ADVINFO;
     225        pAdvi->flags = CDAI_FLAG_NONE;
     226        pAdvi->buftype = CDAI_TYPE_MMC_PARAMS;
     227        pAdvi->bufsiz = sizeof(mmcIdentData);
     228        pAdvi->buf = (uint8_t *)&mmcIdentData;
     229
     230        if (cam_send_ccb(pDev, pCcb) >= 0)
     231        {
     232            if (strlen((char *)mmcIdentData.model) > 0)
     233                dvdCreateDeviceString("", (const char *)mmcIdentData.model, pszDesc, cbDesc);
     234            else
     235                dvdCreateDeviceString("", mmcIdentData.card_features & CARD_FEATURE_SDIO ? "SDIO card" : "Unknown card",
     236                                      pszDesc, cbDesc);
     237        }
     238        else
     239            Log(("error sending XPT_DEV_ADVINFO CCB\n"));
     240
     241        cam_freeccb(pCcb);
     242    }
     243    else
     244        Log(("Could not allocate CCB\n"));
     245    cam_close_device(pDev);
     246}
     247
     248/** @returns boolean success indicator (true/false). */
     249static int nvmeGetCData(struct cam_device *pDev, struct nvme_controller_data *pCData) RT_NOTHROW_DEF
     250{
     251    bool fSuccess = false;
     252    union ccb *pCcb = cam_getccb(pDev);
     253    if (pCcb != NULL)
     254    {
     255        struct ccb_dev_advinfo *pAdvi = &pCcb->cdai;
     256        pAdvi->ccb_h.flags = CAM_DIR_IN;
     257        pAdvi->ccb_h.func_code = XPT_DEV_ADVINFO;
     258        pAdvi->flags = CDAI_FLAG_NONE;
     259        pAdvi->buftype = CDAI_TYPE_NVME_CNTRL;
     260        pAdvi->bufsiz = sizeof(struct nvme_controller_data);
     261        pAdvi->buf = (uint8_t *)pCData;
     262        RT_BZERO(pAdvi->buf, pAdvi->bufsiz);
     263
     264        if (cam_send_ccb(pDev, pCcb) >= 0)
     265        {
     266            if (pAdvi->ccb_h.status == CAM_REQ_CMP)
     267                fSuccess = true;
     268            else
     269                Log(("Got CAM error %#x\n", pAdvi->ccb_h.status));
     270        }
     271        else
     272            Log(("Error sending XPT_DEV_ADVINFO CC\n"));
     273        cam_freeccb(pCcb);
     274    }
     275    else
     276        Log(("Could not allocate CCB\n"));
     277    return fSuccess;
     278}
     279
     280static void strDeviceStringNVME(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
     281{
     282    struct cam_device *pDev = cam_open_btl(pDevResult->path_id, pDevResult->target_id,
     283                                           pDevResult->target_lun, O_RDWR, NULL);
     284    if (pDev)
     285    {
     286        struct nvme_controller_data CData;
     287        if (nvmeGetCData(pDev, &CData))
     288        {
     289            char szVendor[128];
     290            cam_strvis((uint8_t *)szVendor, CData.mn, sizeof(CData.mn), sizeof(szVendor));
     291            char szProduct[128];
     292            cam_strvis((uint8_t *)szProduct, CData.fr, sizeof(CData.fr), sizeof(szProduct));
     293            dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
     294        }
     295        else
     296            Log(("Error while getting NVME drive info\n"));
     297        cam_close_device(pDev);
     298    }
     299    else
     300        Log(("Error while opening drive device. Error: %s\n", cam_errbuf));
     301}
     302
     303
    157304/**
    158  * Search for available CD/DVD drives using the CAM layer.
     305 * Search for available drives using the CAM layer.
    159306 *
    160307 * @returns iprt status code
    161  * @param   pList      the list to append the drives found to
    162  * @param   pfSuccess  this will be set to true if we found at least one drive
    163  *                     and to false otherwise.  Optional.
     308 * @param   pList         the list to append the drives found to
     309 * @param   enmDriveType  search drives of specified type
     310 * @param   pfSuccess     this will be set to true if we found at least one drive
     311 *                        and to false otherwise.  Optional.
    164312 */
    165 static int getDVDInfoFromCAM(DriveInfoList *pList, bool *pfSuccess)
    166 {
    167     int rc = VINF_SUCCESS;
    168     RTFILE FileXpt;
    169 
    170     rc = RTFileOpen(&FileXpt, "/dev/xpt0", RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
     313static int getDriveInfoFromCAM(DriveInfoList *pList, DriveType_T enmDriveType, bool *pfSuccess) RT_NOTHROW_DEF
     314{
     315    RTFILE hFileXpt = NIL_RTFILE;
     316    int rc = RTFileOpen(&hFileXpt, "/dev/xpt0", RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    171317    if (RT_SUCCESS(rc))
    172318    {
     
    196342 #define INQ_PAT inq_pat
    197343#endif
    198         DeviceMatchPattern.pattern.device_pattern.INQ_PAT.type = T_CDROM;
     344        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.type = enmDriveType == Fixed ? T_DIRECT
     345                                                               : enmDriveType == DVD   ? T_CDROM : T_ANY;
    199346        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.media_type  = SIP_MEDIA_REMOVABLE | SIP_MEDIA_FIXED;
    200347        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.vendor[0]   = '*'; /* Matches anything */
     
    220367            do
    221368            {
    222                 rc = RTFileIoCtl(FileXpt, CAMIOCOMMAND, &DeviceCCB, sizeof(union ccb), NULL);
     369                rc = RTFileIoCtl(hFileXpt, CAMIOCOMMAND, &DeviceCCB, sizeof(union ccb), NULL);
    223370                if (RT_FAILURE(rc))
    224371                {
     
    231378                    if (paMatches[i].type == DEV_MATCH_DEVICE)
    232379                    {
     380                        /*
     381                         * The result list can contain some empty entries with DEV_RESULT_UNCONFIGURED
     382                         * flag set, e.g. in case of T_DIRECT. Ignore them.
     383                         */
     384                        if (   (paMatches[i].result.device_result.flags & DEV_RESULT_UNCONFIGURED)
     385                            == DEV_RESULT_UNCONFIGURED)
     386                            continue;
     387
    233388                        /* We have the drive now but need the appropriate device node */
    234389                        struct device_match_result *pDevResult = &paMatches[i].result.device_result;
     
    254409                        PeriphMatchPattern.pattern.periph_pattern.target_id  = paMatches[i].result.device_result.target_id;
    255410                        PeriphMatchPattern.pattern.periph_pattern.target_lun = paMatches[i].result.device_result.target_lun;
    256                         PeriphMatchPattern.pattern.periph_pattern.flags      = (periph_pattern_flags)(  PERIPH_MATCH_PATH | PERIPH_MATCH_TARGET
     411                        PeriphMatchPattern.pattern.periph_pattern.flags      = (periph_pattern_flags)(  PERIPH_MATCH_PATH
     412                                                                                                      | PERIPH_MATCH_TARGET
    257413                                                                                                      | PERIPH_MATCH_LUN);
    258414                        PeriphCCB.cdm.num_patterns    = 1;
     
    265421                        do
    266422                        {
    267                             rc = RTFileIoCtl(FileXpt, CAMIOCOMMAND, &PeriphCCB, sizeof(union ccb), NULL);
     423                            rc = RTFileIoCtl(hFileXpt, CAMIOCOMMAND, &PeriphCCB, sizeof(union ccb), NULL);
    268424                            if (RT_FAILURE(rc))
    269425                            {
     
    274430                            for (iPeriphMatch = 0; iPeriphMatch < PeriphCCB.cdm.num_matches; iPeriphMatch++)
    275431                            {
    276                                 if (   (aPeriphMatches[iPeriphMatch].type == DEV_MATCH_PERIPH)
    277                                     && (!strcmp(aPeriphMatches[iPeriphMatch].result.periph_result.periph_name, "cd")))
     432                                /* Ignore "passthrough mode" paths */
     433                                if (   aPeriphMatches[iPeriphMatch].type == DEV_MATCH_PERIPH
     434                                    && strcmp(aPeriphMatches[iPeriphMatch].result.periph_result.periph_name, "pass"))
    278435                                {
    279436                                    pPeriphResult = &aPeriphMatches[iPeriphMatch].result.periph_result;
     
    285442                                break;
    286443
    287                         } while (   (DeviceCCB.ccb_h.status == CAM_REQ_CMP)
    288                                  && (DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE));
     444                        } while (   DeviceCCB.ccb_h.status == CAM_REQ_CMP
     445                                 && DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE);
    289446
    290447                        if (pPeriphResult)
    291448                        {
    292449                            char szPath[RTPATH_MAX];
    293                             char szDesc[256];
    294 
    295450                            RTStrPrintf(szPath, sizeof(szPath), "/dev/%s%d",
    296451                                        pPeriphResult->periph_name, pPeriphResult->unit_number);
    297452
    298                             /* Remove trailing white space. */
    299                             strLenRemoveTrailingWhiteSpace(pDevResult->inq_data.vendor,
    300                                                             sizeof(pDevResult->inq_data.vendor));
    301                             strLenRemoveTrailingWhiteSpace(pDevResult->inq_data.product,
    302                                                             sizeof(pDevResult->inq_data.product));
    303 
    304                             dvdCreateDeviceString(pDevResult->inq_data.vendor,
    305                                                     pDevResult->inq_data.product,
    306                                                     szDesc, sizeof(szDesc));
    307 
    308                             pList->push_back(DriveInfo(szPath, "", szDesc));
     453                            char szDesc[256] = { 0 };
     454                            switch (pDevResult->protocol)
     455                            {
     456                                case PROTO_SCSI:  strDeviceStringSCSI( pDevResult, szDesc, sizeof(szDesc)); break;
     457                                case PROTO_ATA:   strDeviceStringATA(  pDevResult, szDesc, sizeof(szDesc)); break;
     458                                case PROTO_MMCSD: strDeviceStringMMCSD(pDevResult, szDesc, sizeof(szDesc)); break;
     459                                case PROTO_SEMB:  strDeviceStringSEMB( pDevResult, szDesc, sizeof(szDesc)); break;
     460                                case PROTO_NVME:  strDeviceStringNVME( pDevResult, szDesc, sizeof(szDesc)); break;
     461                                default: break;
     462                            }
     463
     464                            try
     465                            {
     466                                pList->push_back(DriveInfo(szPath, "", szDesc));
     467                            }
     468                            catch (std::bad_alloc &)
     469                            {
     470                                pList->clear();
     471                                rc = VERR_NO_MEMORY;
     472                                break;
     473                            }
    309474                            if (pfSuccess)
    310475                                *pfSuccess = true;
     
    312477                    }
    313478                }
    314             } while (   (DeviceCCB.ccb_h.status == CAM_REQ_CMP)
    315                      && (DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE));
     479            } while (   DeviceCCB.ccb_h.status == CAM_REQ_CMP
     480                     && DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE
     481                     && RT_SUCCESS(rc));
    316482
    317483            RTMemFree(paMatches);
     
    320486            rc = VERR_NO_MEMORY;
    321487
    322         RTFileClose(FileXpt);
     488        RTFileClose(hFileXpt);
    323489    }
    324490
    325491    return rc;
    326492}
     493
    327494
    328495/**
    329496 * Extract the names of drives from an environment variable and add them to a
    330497 * list if they are valid.
     498 *
    331499 * @returns iprt status code
    332500 * @param   pcszVar     the name of the environment variable.  The variable
     
    337505 * @param   pfSuccess  this will be set to true if we found at least one drive
    338506 *                     and to false otherwise.  Optional.
     507 *
     508 * @note    This is duplicated in HostHardwareLinux.cpp.
    339509 */
    340 static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList,
    341                                bool isDVD, bool *pfSuccess)
     510static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList, bool isDVD, bool *pfSuccess) RT_NOTHROW_DEF
    342511{
    343512    AssertPtrReturn(pcszVar, VERR_INVALID_POINTER);
    344513    AssertPtrReturn(pList, VERR_INVALID_POINTER);
    345514    AssertPtrNullReturn(pfSuccess, VERR_INVALID_POINTER);
    346     LogFlowFunc(("pcszVar=%s, pList=%p, isDVD=%d, pfSuccess=%p\n", pcszVar,
    347                  pList, isDVD, pfSuccess));
     515    LogFlowFunc(("pcszVar=%s, pList=%p, isDVD=%d, pfSuccess=%p\n", pcszVar, pList, isDVD, pfSuccess));
    348516    int rc = VINF_SUCCESS;
    349517    bool success = false;
     
    352520    try
    353521    {
    354         const char *pcszCurrent = pszFreeMe;
    355         while (pcszCurrent && *pcszCurrent != '\0')
     522        char *pszCurrent = pszFreeMe;
     523        while (pszCurrent && *pszCurrent != '\0')
    356524        {
    357             const char *pcszNext = strchr(pcszCurrent, ':');
    358             char szPath[RTPATH_MAX], szReal[RTPATH_MAX];
    359             char szDesc[256], szUdi[256];
    360             if (pcszNext)
    361                 RTStrPrintf(szPath, sizeof(szPath), "%.*s",
    362                             pcszNext - pcszCurrent - 1, pcszCurrent);
    363             else
    364                 RTStrPrintf(szPath, sizeof(szPath), "%s", pcszCurrent);
    365             if (RT_SUCCESS(RTPathReal(szPath, szReal, sizeof(szReal))))
     525            char *pszNext = strchr(pszCurrent, ':');
     526            if (pszNext)
     527                *pszNext++ = '\0';
     528
     529            char szReal[RTPATH_MAX];
     530            char szDesc[1] = "", szUdi[1] = ""; /* differs on freebsd because no devValidateDevice */
     531            if (   RT_SUCCESS(RTPathReal(pszCurrent, szReal, sizeof(szReal)))
     532                /*&& devValidateDevice(szReal, isDVD, NULL, szDesc, sizeof(szDesc), szUdi, sizeof(szUdi)) - linux only */)
    366533            {
    367                 szUdi[0] = '\0'; /** @todo r=bird: missing a call to devValidateDevice() here and szUdi wasn't
    368                                   *        initialized because of that.  Need proper fixing. */
    369534                pList->push_back(DriveInfo(szReal, szUdi, szDesc));
    370535                success = true;
    371536            }
    372             pcszCurrent = pcszNext ? pcszNext + 1 : NULL;
     537            pszCurrent = pszNext;
    373538        }
    374539        if (pfSuccess != NULL)
    375540            *pfSuccess = success;
    376541    }
    377     catch(std::bad_alloc &e)
     542    catch (std::bad_alloc &)
    378543    {
    379544        rc = VERR_NO_MEMORY;
     
    383548    return rc;
    384549}
     550
Note: See TracChangeset for help on using the changeset viewer.

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