summaryrefslogtreecommitdiff
path: root/src/VBox/Main/src-server/freebsd/HostHardwareFreeBSD.cpp
blob: c2f3baa228fc700f2643365621112d97bcb4f784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/* $Id$ */
/** @file
 * VirtualBox Main - Code for handling hardware detection under FreeBSD, VBoxSVC.
 */

/*
 * Copyright (C) 2008-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */


/*********************************************************************************************************************************
*   Header Files                                                                                                                 *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_MAIN
#include "HostHardwareLinux.h"

#include <VBox/log.h>

#include <iprt/dir.h>
#include <iprt/env.h>
#include <iprt/file.h>
#include <iprt/mem.h>
#include <iprt/param.h>
#include <iprt/path.h>
#include <iprt/string.h>

#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <camlib.h>
#include <cam/scsi/scsi_pass.h>

#include <vector>


/*********************************************************************************************************************************
*   Typedefs and Defines                                                                                                         *
*********************************************************************************************************************************/
typedef enum DriveType_T
{
    Fixed,
    DVD,
    Any
} DriveType_T;


/*********************************************************************************************************************************
*   Internal Functions                                                                                                           *
*********************************************************************************************************************************/
static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList, bool isDVD, bool *pfSuccess) RT_NOTHROW_DEF;
static int getDriveInfoFromCAM(DriveInfoList *pList, DriveType_T enmDriveType, bool *pfSuccess) RT_NOTHROW_DEF;


/** Find the length of a string, ignoring trailing non-ascii or control
 * characters
 * @note Code duplicated in HostHardwareLinux.cpp  */
static size_t strLenStripped(const char *pcsz) RT_NOTHROW_DEF
{
    size_t cch = 0;
    for (size_t i = 0; pcsz[i] != '\0'; ++i)
        if (pcsz[i] > 32 /*space*/ && pcsz[i] < 127 /*delete*/)
            cch = i;
    return cch + 1;
}


/**
 * Initialize the device description for a drive based on vendor and model name
 * strings.
 *
 * @param   pcszVendor  The raw vendor ID string.
 * @param   pcszModel   The raw product ID string.
 * @param   pszDesc     Where to store the description string (optional)
 * @param   cbDesc      The size of the buffer in @pszDesc
 *
 * @note    Used for disks as well as DVDs.
 */
/* static */
void dvdCreateDeviceString(const char *pcszVendor, const char *pcszModel, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
{
    AssertPtrReturnVoid(pcszVendor);
    AssertPtrReturnVoid(pcszModel);
    AssertPtrNullReturnVoid(pszDesc);
    AssertReturnVoid(!pszDesc || cbDesc > 0);
    size_t cchVendor = strLenStripped(pcszVendor);
    size_t cchModel = strLenStripped(pcszModel);

    /* Construct the description string as "Vendor Product" */
    if (pszDesc)
    {
        if (cchVendor > 0)
            RTStrPrintf(pszDesc, cbDesc, "%.*s %s", cchVendor, pcszVendor,
                        cchModel > 0 ? pcszModel : "(unknown drive model)");
        else
            RTStrPrintf(pszDesc, cbDesc, "%s", pcszModel);
        RTStrPurgeEncoding(pszDesc);
    }
}


int VBoxMainDriveInfo::updateDVDs() RT_NOEXCEPT
{
    LogFlowThisFunc(("entered\n"));
    int rc;
    try
    {
        mDVDList.clear();
        /* Always allow the user to override our auto-detection using an
         * environment variable. */
        bool fSuccess = false;  /* Have we succeeded in finding anything yet? */
        rc = getDriveInfoFromEnv("VBOX_CDROM", &mDVDList, true /* isDVD */, &fSuccess);
        if (RT_SUCCESS(rc) && !fSuccess)
            rc = getDriveInfoFromCAM(&mDVDList, DVD, &fSuccess);
    }
    catch (std::bad_alloc &)
    {
        rc = VERR_NO_MEMORY;
    }
    LogFlowThisFunc(("rc=%Rrc\n", rc));
    return rc;
}

int VBoxMainDriveInfo::updateFloppies() RT_NOEXCEPT
{
    LogFlowThisFunc(("entered\n"));
    int rc;
    try
    {
        /* Only got the enviornment variable here... */
        mFloppyList.clear();
        bool fSuccess = false;  /* ignored */
        rc = getDriveInfoFromEnv("VBOX_FLOPPY", &mFloppyList, false /* isDVD */, &fSuccess);
    }
    catch (std::bad_alloc &)
    {
        rc = VERR_NO_MEMORY;
    }
    LogFlowThisFunc(("rc=%Rrc\n", rc));
    return rc;
}

int VBoxMainDriveInfo::updateFixedDrives() RT_NOEXCEPT
{
    LogFlowThisFunc(("entered\n"));
    int rc;
    try
    {
        mFixedDriveList.clear();
        bool fSuccess = false;  /* ignored */
        rc = getDriveInfoFromCAM(&mFixedDriveList, Fixed, &fSuccess);
    }
    catch (std::bad_alloc &)
    {
        rc = VERR_NO_MEMORY;
    }
    LogFlowThisFunc(("rc=%Rrc\n", rc));
    return rc;
}

static void strDeviceStringSCSI(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
{
    char szVendor[128];
    cam_strvis((uint8_t *)szVendor, (const uint8_t *)pDevResult->inq_data.vendor,
               sizeof(pDevResult->inq_data.vendor), sizeof(szVendor));
    char szProduct[128];
    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pDevResult->inq_data.product,
               sizeof(pDevResult->inq_data.product), sizeof(szProduct));
    dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
}

static void strDeviceStringATA(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
{
    char szProduct[256];
    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pDevResult->ident_data.model,
               sizeof(pDevResult->ident_data.model), sizeof(szProduct));
    dvdCreateDeviceString("", szProduct, pszDesc, cbDesc);
}

static void strDeviceStringSEMB(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
{
    sep_identify_data *pSid = (sep_identify_data *)&pDevResult->ident_data;

    char szVendor[128];
    cam_strvis((uint8_t *)szVendor, (const uint8_t *)pSid->vendor_id,
               sizeof(pSid->vendor_id), sizeof(szVendor));
    char szProduct[128];
    cam_strvis((uint8_t *)szProduct, (const uint8_t *)pSid->product_id,
               sizeof(pSid->product_id), sizeof(szProduct));
    dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
}

static void strDeviceStringMMCSD(device_match_result *pDevResult, char *pszDesc, size_t cbDesc)  RT_NOTHROW_DEF
{
    struct cam_device *pDev = cam_open_btl(pDevResult->path_id, pDevResult->target_id,
                                           pDevResult->target_lun, O_RDWR, NULL);
    if (pDev == NULL)
    {
        Log(("Error while opening drive device. Error: %s\n", cam_errbuf));
        return;
    }

    union ccb *pCcb = cam_getccb(pDev);
    if (pCcb != NULL)
    {
        struct mmc_params mmcIdentData;
        RT_ZERO(mmcIdentData);

        struct ccb_dev_advinfo *pAdvi = &pCcb->cdai;
        pAdvi->ccb_h.flags = CAM_DIR_IN;
        pAdvi->ccb_h.func_code = XPT_DEV_ADVINFO;
        pAdvi->flags = CDAI_FLAG_NONE;
        pAdvi->buftype = CDAI_TYPE_MMC_PARAMS;
        pAdvi->bufsiz = sizeof(mmcIdentData);
        pAdvi->buf = (uint8_t *)&mmcIdentData;

        if (cam_send_ccb(pDev, pCcb) >= 0)
        {
            if (strlen((char *)mmcIdentData.model) > 0)
                dvdCreateDeviceString("", (const char *)mmcIdentData.model, pszDesc, cbDesc);
            else
                dvdCreateDeviceString("", mmcIdentData.card_features & CARD_FEATURE_SDIO ? "SDIO card" : "Unknown card",
                                      pszDesc, cbDesc);
        }
        else
            Log(("error sending XPT_DEV_ADVINFO CCB\n"));

        cam_freeccb(pCcb);
    }
    else
        Log(("Could not allocate CCB\n"));
    cam_close_device(pDev);
}

/** @returns boolean success indicator (true/false). */
static int nvmeGetCData(struct cam_device *pDev, struct nvme_controller_data *pCData) RT_NOTHROW_DEF
{
    bool fSuccess = false;
    union ccb *pCcb = cam_getccb(pDev);
    if (pCcb != NULL)
    {
        struct ccb_dev_advinfo *pAdvi = &pCcb->cdai;
        pAdvi->ccb_h.flags = CAM_DIR_IN;
        pAdvi->ccb_h.func_code = XPT_DEV_ADVINFO;
        pAdvi->flags = CDAI_FLAG_NONE;
        pAdvi->buftype = CDAI_TYPE_NVME_CNTRL;
        pAdvi->bufsiz = sizeof(struct nvme_controller_data);
        pAdvi->buf = (uint8_t *)pCData;
        RT_BZERO(pAdvi->buf, pAdvi->bufsiz);

        if (cam_send_ccb(pDev, pCcb) >= 0)
        {
            if (pAdvi->ccb_h.status == CAM_REQ_CMP)
                fSuccess = true;
            else
                Log(("Got CAM error %#x\n", pAdvi->ccb_h.status));
        }
        else
            Log(("Error sending XPT_DEV_ADVINFO CC\n"));
        cam_freeccb(pCcb);
    }
    else
        Log(("Could not allocate CCB\n"));
    return fSuccess;
}

static void strDeviceStringNVME(device_match_result *pDevResult, char *pszDesc, size_t cbDesc) RT_NOTHROW_DEF
{
    struct cam_device *pDev = cam_open_btl(pDevResult->path_id, pDevResult->target_id,
                                           pDevResult->target_lun, O_RDWR, NULL);
    if (pDev)
    {
        struct nvme_controller_data CData;
        if (nvmeGetCData(pDev, &CData))
        {
            char szVendor[128];
            cam_strvis((uint8_t *)szVendor, CData.mn, sizeof(CData.mn), sizeof(szVendor));
            char szProduct[128];
            cam_strvis((uint8_t *)szProduct, CData.fr, sizeof(CData.fr), sizeof(szProduct));
            dvdCreateDeviceString(szVendor, szProduct, pszDesc, cbDesc);
        }
        else
            Log(("Error while getting NVME drive info\n"));
        cam_close_device(pDev);
    }
    else
        Log(("Error while opening drive device. Error: %s\n", cam_errbuf));
}


/**
 * Search for available drives using the CAM layer.
 *
 * @returns iprt status code
 * @param   pList         the list to append the drives found to
 * @param   enmDriveType  search drives of specified type
 * @param   pfSuccess     this will be set to true if we found at least one drive
 *                        and to false otherwise.  Optional.
 */
static int getDriveInfoFromCAM(DriveInfoList *pList, DriveType_T enmDriveType, bool *pfSuccess) RT_NOTHROW_DEF
{
    RTFILE hFileXpt = NIL_RTFILE;
    int rc = RTFileOpen(&hFileXpt, "/dev/xpt0", RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    if (RT_SUCCESS(rc))
    {
        union ccb DeviceCCB;
        struct dev_match_pattern DeviceMatchPattern;
        struct dev_match_result *paMatches = NULL;

        RT_ZERO(DeviceCCB);
        RT_ZERO(DeviceMatchPattern);

        /* We want to get all devices. */
        DeviceCCB.ccb_h.func_code  = XPT_DEV_MATCH;
        DeviceCCB.ccb_h.path_id    = CAM_XPT_PATH_ID;
        DeviceCCB.ccb_h.target_id  = CAM_TARGET_WILDCARD;
        DeviceCCB.ccb_h.target_lun = CAM_LUN_WILDCARD;

        /* Setup the pattern */
        DeviceMatchPattern.type = DEV_MATCH_DEVICE;
        DeviceMatchPattern.pattern.device_pattern.path_id    = CAM_XPT_PATH_ID;
        DeviceMatchPattern.pattern.device_pattern.target_id  = CAM_TARGET_WILDCARD;
        DeviceMatchPattern.pattern.device_pattern.target_lun = CAM_LUN_WILDCARD;
        DeviceMatchPattern.pattern.device_pattern.flags      = DEV_MATCH_INQUIRY;

#if __FreeBSD_version >= 900000
# define INQ_PAT data.inq_pat
#else
 #define INQ_PAT inq_pat
#endif
        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.type = enmDriveType == Fixed ? T_DIRECT
                                                               : enmDriveType == DVD   ? T_CDROM : T_ANY;
        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.media_type  = SIP_MEDIA_REMOVABLE | SIP_MEDIA_FIXED;
        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.vendor[0]   = '*'; /* Matches anything */
        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.product[0]  = '*'; /* Matches anything */
        DeviceMatchPattern.pattern.device_pattern.INQ_PAT.revision[0] = '*'; /* Matches anything */
#undef INQ_PAT
        DeviceCCB.cdm.num_patterns    = 1;
        DeviceCCB.cdm.pattern_buf_len = sizeof(struct dev_match_result);
        DeviceCCB.cdm.patterns        = &DeviceMatchPattern;

        /*
         * Allocate the buffer holding the matches.
         * We will allocate for 10 results and call
         * CAM multiple times if we have more results.
         */
        paMatches = (struct dev_match_result *)RTMemAllocZ(10 * sizeof(struct dev_match_result));
        if (paMatches)
        {
            DeviceCCB.cdm.num_matches   = 0;
            DeviceCCB.cdm.match_buf_len = 10 * sizeof(struct dev_match_result);
            DeviceCCB.cdm.matches       = paMatches;

            do
            {
                rc = RTFileIoCtl(hFileXpt, CAMIOCOMMAND, &DeviceCCB, sizeof(union ccb), NULL);
                if (RT_FAILURE(rc))
                {
                    Log(("Error while querying available CD/DVD devices rc=%Rrc\n", rc));
                    break;
                }

                for (unsigned i = 0; i < DeviceCCB.cdm.num_matches; i++)
                {
                    if (paMatches[i].type == DEV_MATCH_DEVICE)
                    {
                        /*
                         * The result list can contain some empty entries with DEV_RESULT_UNCONFIGURED
                         * flag set, e.g. in case of T_DIRECT. Ignore them.
                         */
                        if (   (paMatches[i].result.device_result.flags & DEV_RESULT_UNCONFIGURED)
                            == DEV_RESULT_UNCONFIGURED)
                            continue;

                        /* We have the drive now but need the appropriate device node */
                        struct device_match_result *pDevResult = &paMatches[i].result.device_result;
                        union ccb PeriphCCB;
                        struct dev_match_pattern PeriphMatchPattern;
                        struct dev_match_result aPeriphMatches[2];
                        struct periph_match_result *pPeriphResult = NULL;
                        unsigned iPeriphMatch = 0;

                        RT_ZERO(PeriphCCB);
                        RT_ZERO(PeriphMatchPattern);
                        RT_ZERO(aPeriphMatches);

                        /* This time we only want the specific nodes for the device. */
                        PeriphCCB.ccb_h.func_code  = XPT_DEV_MATCH;
                        PeriphCCB.ccb_h.path_id    = paMatches[i].result.device_result.path_id;
                        PeriphCCB.ccb_h.target_id  = paMatches[i].result.device_result.target_id;
                        PeriphCCB.ccb_h.target_lun = paMatches[i].result.device_result.target_lun;

                        /* Setup the pattern */
                        PeriphMatchPattern.type = DEV_MATCH_PERIPH;
                        PeriphMatchPattern.pattern.periph_pattern.path_id    = paMatches[i].result.device_result.path_id;
                        PeriphMatchPattern.pattern.periph_pattern.target_id  = paMatches[i].result.device_result.target_id;
                        PeriphMatchPattern.pattern.periph_pattern.target_lun = paMatches[i].result.device_result.target_lun;
                        PeriphMatchPattern.pattern.periph_pattern.flags      = (periph_pattern_flags)(  PERIPH_MATCH_PATH
                                                                                                      | PERIPH_MATCH_TARGET
                                                                                                      | PERIPH_MATCH_LUN);
                        PeriphCCB.cdm.num_patterns    = 1;
                        PeriphCCB.cdm.pattern_buf_len = sizeof(struct dev_match_result);
                        PeriphCCB.cdm.patterns        = &PeriphMatchPattern;
                        PeriphCCB.cdm.num_matches   = 0;
                        PeriphCCB.cdm.match_buf_len = sizeof(aPeriphMatches);
                        PeriphCCB.cdm.matches       = aPeriphMatches;

                        do
                        {
                            rc = RTFileIoCtl(hFileXpt, CAMIOCOMMAND, &PeriphCCB, sizeof(union ccb), NULL);
                            if (RT_FAILURE(rc))
                            {
                                Log(("Error while querying available periph devices rc=%Rrc\n", rc));
                                break;
                            }

                            for (iPeriphMatch = 0; iPeriphMatch < PeriphCCB.cdm.num_matches; iPeriphMatch++)
                            {
                                /* Ignore "passthrough mode" paths */
                                if (   aPeriphMatches[iPeriphMatch].type == DEV_MATCH_PERIPH
                                    && strcmp(aPeriphMatches[iPeriphMatch].result.periph_result.periph_name, "pass"))
                                {
                                    pPeriphResult = &aPeriphMatches[iPeriphMatch].result.periph_result;
                                    break; /* We found the periph device */
                                }
                            }

                            if (iPeriphMatch < PeriphCCB.cdm.num_matches)
                                break;

                        } while (   DeviceCCB.ccb_h.status == CAM_REQ_CMP
                                 && DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE);

                        if (pPeriphResult)
                        {
                            char szPath[RTPATH_MAX];
                            RTStrPrintf(szPath, sizeof(szPath), "/dev/%s%d",
                                        pPeriphResult->periph_name, pPeriphResult->unit_number);

                            char szDesc[256] = { 0 };
                            switch (pDevResult->protocol)
                            {
                                case PROTO_SCSI:  strDeviceStringSCSI( pDevResult, szDesc, sizeof(szDesc)); break;
                                case PROTO_ATA:   strDeviceStringATA(  pDevResult, szDesc, sizeof(szDesc)); break;
                                case PROTO_MMCSD: strDeviceStringMMCSD(pDevResult, szDesc, sizeof(szDesc)); break;
                                case PROTO_SEMB:  strDeviceStringSEMB( pDevResult, szDesc, sizeof(szDesc)); break;
                                case PROTO_NVME:  strDeviceStringNVME( pDevResult, szDesc, sizeof(szDesc)); break;
                                default: break;
                            }

                            try
                            {
                                pList->push_back(DriveInfo(szPath, "", szDesc));
                            }
                            catch (std::bad_alloc &)
                            {
                                pList->clear();
                                rc = VERR_NO_MEMORY;
                                break;
                            }
                            if (pfSuccess)
                                *pfSuccess = true;
                        }
                    }
                }
            } while (   DeviceCCB.ccb_h.status == CAM_REQ_CMP
                     && DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE
                     && RT_SUCCESS(rc));

            RTMemFree(paMatches);
        }
        else
            rc = VERR_NO_MEMORY;

        RTFileClose(hFileXpt);
    }

    return rc;
}


/**
 * Extract the names of drives from an environment variable and add them to a
 * list if they are valid.
 *
 * @returns iprt status code
 * @param   pcszVar     the name of the environment variable.  The variable
 *                     value should be a list of device node names, separated
 *                     by ':' characters.
 * @param   pList      the list to append the drives found to
 * @param   isDVD      are we looking for DVD drives or for floppies?
 * @param   pfSuccess  this will be set to true if we found at least one drive
 *                     and to false otherwise.  Optional.
 *
 * @note    This is duplicated in HostHardwareLinux.cpp.
 */
static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList, bool isDVD, bool *pfSuccess) RT_NOTHROW_DEF
{
    AssertPtrReturn(pcszVar, VERR_INVALID_POINTER);
    AssertPtrReturn(pList, VERR_INVALID_POINTER);
    AssertPtrNullReturn(pfSuccess, VERR_INVALID_POINTER);
    LogFlowFunc(("pcszVar=%s, pList=%p, isDVD=%d, pfSuccess=%p\n", pcszVar, pList, isDVD, pfSuccess));
    int rc = VINF_SUCCESS;
    bool success = false;
    char *pszFreeMe = RTEnvDupEx(RTENV_DEFAULT, pcszVar);

    try
    {
        char *pszCurrent = pszFreeMe;
        while (pszCurrent && *pszCurrent != '\0')
        {
            char *pszNext = strchr(pszCurrent, ':');
            if (pszNext)
                *pszNext++ = '\0';

            char szReal[RTPATH_MAX];
            char szDesc[1] = "", szUdi[1] = ""; /* differs on freebsd because no devValidateDevice */
            if (   RT_SUCCESS(RTPathReal(pszCurrent, szReal, sizeof(szReal)))
                /*&& devValidateDevice(szReal, isDVD, NULL, szDesc, sizeof(szDesc), szUdi, sizeof(szUdi)) - linux only */)
            {
                pList->push_back(DriveInfo(szReal, szUdi, szDesc));
                success = true;
            }
            pszCurrent = pszNext;
        }
        if (pfSuccess != NULL)
            *pfSuccess = success;
    }
    catch (std::bad_alloc &)
    {
        rc = VERR_NO_MEMORY;
    }
    RTStrFree(pszFreeMe);
    LogFlowFunc(("rc=%Rrc, success=%d\n", rc, success));
    return rc;
}