VirtualBox

Changeset 48852 in vbox for trunk


Ignore:
Timestamp:
Oct 3, 2013 8:06:54 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89521
Message:

DMG in XAR fun, part 1 (probably will everything burn as I had to change static linking).

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r48845 r48852  
    37513751TEMPLATE_VBOXR3STATIC                  = VBox Static Ring 3 EXE
    37523752TEMPLATE_VBOXR3STATIC_EXTENDS          = VBOXR3EXE
    3753 TEMPLATE_VBOXR3STATIC_DEFS             = IN_RT_STATIC $(TEMPLATE_VBOXR3EXE_DEFS)
     3753TEMPLATE_VBOXR3STATIC_DEFS             = IN_RT_STATIC IN_RT_R3 $(TEMPLATE_VBOXR3EXE_DEFS)
    37543754ifeq ($(KBUILD_TARGET),win)
    37553755 TEMPLATE_VBOXR3STATIC_CFLAGS          = $(filter-out -MD$(VBOX_VCC_CRT_TYPE), $(TEMPLATE_VBOXR3EXE_CFLAGS)) -MT$(VBOX_VCC_CRT_TYPE)
     
    37813781#
    37823782# Temporary: Renaming the template and warnings will be errors (soon).
     3783# Unlike VBOXR3STATIC, this is strict wrt warnings and includes IPRT.
    37833784#
    37843785TEMPLATE_VBoxR3Static               = New name for VBOXR3STATIC
    37853786TEMPLATE_VBoxR3Static_EXTENDS       = VBOXR3STATIC
    37863787TEMPLATE_VBoxR3Static_EXTENDS_BY    = appending
     3788TEMPLATE_VBoxR3Static_SDKS         += VBOX_OPENSSL
     3789TEMPLATE_VBoxR3Static_SDKS.win     += VBOX_NTDLL
    37873790ifeq ($(KBUILD_TARGET),win)
    37883791 TEMPLATE_VBoxR3Static_CFLAGS      += $(VBOX_VCC_WERR)
     
    37933796 TEMPLATE_VBoxR3Static_CXXFLAGS    += $(VBOX_GCC_WERR)
    37943797endif
     3798TEMPLATE_VBoxR3Static_LIBS         += \
     3799        $(VBOX_LIB_RUNTIME_STATIC)
     3800ifndef SDK_VBOX_OPENSSL_LIBS
     3801 TEMPLATE_VBoxR3Static_LIBS        += \
     3802        $(PATH_STAGE_LIB)/VBox-libcrypto$(VBOX_SUFF_LIB) \
     3803        $(PATH_STAGE_LIB)/VBox-libssl$(VBOX_SUFF_LIB)
     3804endif
     3805if1of ($(KBUILD_TARGET),os2 win)
     3806 TEMPLATE_VBoxR3Static_LIBS        += \
     3807        $(PATH_STAGE_LIB)/VBox-liblzf-static$(VBOX_SUFF_LIB) \
     3808        $(PATH_STAGE_LIB)/VBox-zlib-static$(VBOX_SUFF_LIB) \
     3809        $(PATH_STAGE_LIB)/VBox-libxml2-static$(VBOX_SUFF_LIB)
     3810else
     3811 TEMPLATE_VBoxR3Static_LIBS        += \
     3812        $(PATH_STAGE_LIB)/VBox-liblzf$(VBOX_SUFF_LIB) \
     3813        $(SDK_VBOX_ZLIB_LIBS)
     3814 ifeq ($(KBUILD_TARGET),linux)
     3815  TEMPLATE_VBoxR3Static_LIBS       += crypt
     3816 else if1of ($(KBUILD_TARGET),darwin freebsd)
     3817  TEMPLATE_VBoxR3Static_LIBS       += iconv
     3818 else ifeq ($(KBUILD_TARGET),solaris)
     3819  TEMPLATE_VBoxR3Static_LIBS       += kstat
     3820 endif
     3821endif
     3822
    37953823
    37963824#
  • trunk/include/VBox/err.h

    r48267 r48852  
    15821582/** Block read was marked as free in the image and returned as a zero block. */
    15831583#define VINF_VD_NEW_ZEROED_BLOCK                    3283
     1584/** Unable to parse the XML in DMG file. */
     1585#define VERR_VD_DMG_XML_PARSE_ERROR                 (-3284)
     1586/** Unable to locate a usable DMG file within the XAR archive. */
     1587#define VERR_VD_DMG_NOT_FOUND_INSIDE_XAR            (-3285)
    15841588/** @} */
    15851589
  • trunk/src/VBox/Runtime/Makefile.kmk

    r48845 r48852  
    232232#
    233233RuntimeR3_TEMPLATE      = VBoxR3Static
    234 RuntimeR3_SDKS          = VBOX_OPENSSL
     234RuntimeR3_SDKS          = VBOX_OPENSSL VBOX_LIBXML2
    235235RuntimeR3_SDKS.win      = $(VBOX_WINPSDK) $(VBOX_WINDDK)
    236236RuntimeR3_DEFS          = IN_RT_R3 IN_SUP_R3 LDR_WITH_NATIVE LDR_WITH_ELF32 LDR_WITH_PE RT_WITH_VBOX RT_NO_GIP
     
    515515        r3/tcp.cpp \
    516516        r3/udp.cpp \
    517         r3/generic/semspinmutex-r3-generic.cpp
     517        r3/generic/semspinmutex-r3-generic.cpp \
     518        r3/xml.cpp \
     519        common/zip/xarvfs.cpp
     520
    518521
    519522#if1of ($(KBUILD_TARGET_ARCH),amd64 x86)
     
    10691072RuntimeBldProg_BLD_TRG_ARCH     := $(KBUILD_HOST_ARCH)
    10701073RuntimeBldProg_BLD_TRG_CPU      := $(KBUILD_HOST_CPU)
     1074RuntimeBldProg_SOURCES          = $(filter-out \
     1075        r3/xml.cpp \
     1076        common/zip/xarvfs.cpp \
     1077        , $(RuntimeR3_SOURCES))
     1078
    10711079
    10721080
     
    10931101        common/checksum/sha% \
    10941102        generic/RTLogWriteUser-generic.cpp \
     1103        r3/xml.cpp \
     1104        common/zip/xarvfs.cpp \
    10951105        , $(RuntimeR3_SOURCES))
    10961106RuntimeGuestR3_SOURCES              += \
     
    12981308VBoxRT_SOURCES                := \
    12991309        VBox/VBoxRTDeps.cpp \
    1300         r3/xml.cpp \
    13011310        $(filter-out common/checksum/crc32.cpp, $(RuntimeR3_SOURCES)) \
    13021311        common/checksum/crc32-zlib.cpp \
    1303         common/misc/aiomgr.cpp \
    1304         common/zip/xarvfs.cpp
     1312        common/misc/aiomgr.cpp
    13051313ifdef VBOX_WITH_LIBCURL
    13061314 VBoxRT_SOURCES               += common/misc/s3.cpp
  • trunk/src/VBox/Storage/DMG.cpp

    r48840 r48852  
    2121#define LOG_GROUP LOG_GROUP_VD_DMG
    2222#include <VBox/vd-plugin.h>
     23#include <VBox/vd-ifs.h>
    2324#include <VBox/log.h>
    2425#include <VBox/err.h>
     26
     27#include <iprt/asm.h>
     28#include <iprt/alloca.h>
    2529#include <iprt/assert.h>
    26 #include <iprt/asm.h>
     30#include <iprt/base64.h>
     31#include <iprt/ctype.h>
    2732#include <iprt/mem.h>
    28 #include <iprt/ctype.h>
    2933#include <iprt/string.h>
    30 #include <iprt/base64.h>
    3134#include <iprt/zip.h>
     35#include <iprt/formats/xar.h>
     36
    3237
    3338/*******************************************************************************
     
    311316    /** Error interface. */
    312317    PVDINTERFACEERROR   pIfError;
    313     /** I/O interface. */
    314     PVDINTERFACEIOINT   pIfIo;
     318    /** I/O interface - careful accessing this because of hDmgFileInXar. */
     319    PVDINTERFACEIOINT   pIfIoXxx;
     320
     321
     322    /** The VFS file handle for a DMG within a XAR archive.  */
     323    RTVFSFILE           hDmgFileInXar;
     324    /** XAR file system stream handle.
     325     * Sitting on this isn't really necessary, but insurance against the XAR code
     326     * changes making back references from child objects to the stream itself. */
     327    RTVFSFSSTREAM       hXarFss;
    315328
    316329    /** Flags the image was opened with. */
     
    393406    } while (0)
    394407
    395 /** VBoxDMG: Unable to parse the XML. */
    396 #define VERR_VD_DMG_XML_PARSE_ERROR         (-3280)
    397 
    398408
    399409/*******************************************************************************
     
    421431static bool dmgUdifCkSumIsValid(PCDMGUDIFCKSUM pCkSum, const char *pszPrefix);
    422432
     433
     434
     435/**
     436 * vdIfIoIntFileReadSync / RTVfsFileReadAt wrapper.
     437 */
     438static int dmgWrapFileReadSync(PDMGIMAGE pThis, RTFOFF off, void *pvBuf, size_t cbToRead)
     439{
     440    int rc;
     441    if (pThis->hDmgFileInXar == NIL_RTVFSFILE)
     442        rc = vdIfIoIntFileReadSync(pThis->pIfIoXxx, pThis->pStorage, off, pvBuf, cbToRead);
     443    else
     444        rc = RTVfsFileReadAt(pThis->hDmgFileInXar, off, pvBuf, cbToRead, NULL);
     445    return rc;
     446}
     447
     448/**
     449 * vdIfIoIntFileReadUser / RTVfsFileReadAt wrapper.
     450 */
     451static int dmgWrapFileReadUser(PDMGIMAGE pThis, RTFOFF off, PVDIOCTX pIoCtx, size_t cbToRead)
     452{
     453    int rc;
     454    if (pThis->hDmgFileInXar == NIL_RTVFSFILE)
     455        rc = vdIfIoIntFileReadUser(pThis->pIfIoXxx, pThis->pStorage, off, pIoCtx, cbToRead);
     456    else
     457    {
     458        /*
     459         * The I/O context stuff seems to complicated and undocument that I'm
     460         * not going to bother trying implement this efficiently right now.
     461         */
     462        void *pvFree = NULL;
     463        void *pvBuf;
     464        if (cbToRead < _32K)
     465            pvBuf = alloca(cbToRead);
     466        else
     467            pvFree = pvBuf = RTMemTmpAlloc(cbToRead);
     468        if (!pvBuf)
     469        {
     470            rc = RTVfsFileReadAt(pThis->hDmgFileInXar, off, pvBuf, cbToRead, NULL);
     471            if (RT_SUCCESS(rc))
     472                vdIfIoIntIoCtxCopyTo(pThis->pIfIoXxx, pIoCtx, pvBuf, cbToRead);
     473            if (pvFree)
     474                RTMemTmpFree(pvFree);
     475        }
     476        else
     477            rc = VERR_NO_TMP_MEMORY;
     478    }
     479    return rc;
     480}
     481
     482/**
     483 * vdIfIoIntFileGetSize / RTVfsFileGetSize wrapper.
     484 */
     485static int dmgWrapFileGetSize(PDMGIMAGE pThis, uint64_t *pcbFile)
     486{
     487    int rc;
     488    if (pThis->hDmgFileInXar == NIL_RTVFSFILE)
     489        rc = vdIfIoIntFileGetSize(pThis->pIfIoXxx, pThis->pStorage, pcbFile);
     490    else
     491        rc = RTVfsFileGetSize(pThis->hDmgFileInXar, pcbFile);
     492    return rc;
     493}
     494
     495
     496
    423497static DECLCALLBACK(int) dmgFileInflateHelper(void *pvUser, void *pvBuf, size_t cbBuf, size_t *pcbBuf)
    424498{
     
    435509    }
    436510    cbBuf = RT_MIN(cbBuf, pInflateState->cbSize);
    437     int rc = vdIfIoIntFileReadSync(pInflateState->pImage->pIfIo,
    438                                    pInflateState->pImage->pStorage,
    439                                    pInflateState->uFileOffset,
    440                                    pvBuf, cbBuf);
     511    int rc = dmgWrapFileReadSync(pInflateState->pImage, pInflateState->uFileOffset, pvBuf, cbBuf);
    441512    if (RT_FAILURE(rc))
    442513        return rc;
     
    737808        if (pThis->pStorage)
    738809        {
     810            RTVfsFileRelease(pThis->hDmgFileInXar);
     811            pThis->hDmgFileInXar = NIL_RTVFSFILE;
     812            RTVfsFsStrmRelease(pThis->hXarFss);
     813            pThis->hXarFss = NIL_RTVFSFSSTREAM;
     814
    739815            /* No point updating the file that is deleted anyway. */
    740816            if (!fDelete)
    741817                dmgFlushImage(pThis);
    742818
    743             rc = vdIfIoIntFileClose(pThis->pIfIo, pThis->pStorage);
     819            rc = vdIfIoIntFileClose(pThis->pIfIoXxx, pThis->pStorage);
    744820            pThis->pStorage = NULL;
    745821        }
     
    766842
    767843        if (fDelete && pThis->pszFilename)
    768             vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename);
     844            vdIfIoIntFileDelete(pThis->pIfIoXxx, pThis->pszFilename);
    769845
    770846        if (pThis->pvDecompExtent)
     
    774850            pThis->cbDecompExtent = 0;
    775851        }
    776 
    777852    }
    778853
     
    13571432}
    13581433
     1434
     1435/**
     1436 * Worker for dmgOpenImage that tries to open a DMG inside a XAR file.
     1437 *
     1438 * We'll select the first .dmg inside the archive that we can get a file
     1439 * interface to.
     1440 *
     1441 * @returns VBox status code.
     1442 * @param   fOpen           Flags for defining the open type.
     1443 * @param   pVDIfsIo        The storage I/O interface to use.
     1444 * @param   pvStorage       The storage pointer that goes with @a pVDIfsIo.
     1445 * @param   pszFilename     The input filename, optional.
     1446 * @param   phXarFss        Where to return the XAR file system stream handle on
     1447 *                          success
     1448 * @param   phDmgFileInXar  Where to return the VFS handle to the DMG file
     1449 *                          within the XAR image on success.
     1450 *
     1451 * @remarks Not using the PDMGIMAGE structure directly here because the function
     1452 *          is being in serveral places.
     1453 */
     1454static int dmgOpenImageWithinXar(uint32_t fOpen, PVDINTERFACEIO pVDIfsIo, void *pvStorage, const char *pszFilename,
     1455                                 PRTVFSFSSTREAM phXarFss, PRTVFSFILE phDmgFileInXar)
     1456{
     1457    /*
     1458     * Open the XAR file stream.
     1459     */
     1460    if (!pVDIfsIo)
     1461        return VERR_INVALID_PARAMETER;
     1462
     1463    RTVFSFILE hVfsFile;
     1464    int rc = VDIfCreateVfsFile(pVDIfsIo, pvStorage, fOpen, &hVfsFile);
     1465    if (RT_FAILURE(rc))
     1466        return rc;
     1467
     1468    RTVFSIOSTREAM hVfsIos = RTVfsFileToIoStream(hVfsFile);
     1469    RTVfsFileRelease(hVfsFile);
     1470
     1471    RTVFSFSSTREAM hXarFss;
     1472    rc = RTZipXarFsStreamFromIoStream(hVfsIos, 0 /*fFlags*/, &hXarFss);
     1473    RTVfsIoStrmRelease(hVfsIos);
     1474    if (RT_FAILURE(rc))
     1475        return rc;
     1476
     1477    /*
     1478     * Look for a DMG in the stream that we can use.
     1479     */
     1480    for (;;)
     1481    {
     1482        char           *pszName;
     1483        RTVFSOBJTYPE    enmType;
     1484        RTVFSOBJ        hVfsObj;
     1485        rc = RTVfsFsStrmNext(hXarFss, &pszName, &enmType, &hVfsObj);
     1486        if (RT_FAILURE(rc))
     1487            break;
     1488
     1489        /* It must be a file object so it can be seeked, this also implies that
     1490           it's uncompressed.  Then it must have the .dmg suffix. */
     1491        if (enmType == RTVFSOBJTYPE_FILE)
     1492        {
     1493            size_t      cchName = strlen(pszName);
     1494            const char *pszSuff = pszName + cchName - 4;
     1495            if (   cchName >= 4
     1496                && pszSuff[0] == '.'
     1497                && (pszSuff[1] == 'd' || pszSuff[1] == 'D')
     1498                && (pszSuff[2] == 'm' || pszSuff[2] == 'M')
     1499                && (pszSuff[3] == 'g' || pszSuff[3] == 'G'))
     1500            {
     1501                RTVFSFILE hDmgFileInXar = RTVfsObjToFile(hVfsObj);
     1502                AssertBreakStmt(hDmgFileInXar != NIL_RTVFSFILE, rc = VERR_INTERNAL_ERROR_3);
     1503
     1504                if (pszFilename)
     1505                    DMG_PRINTF(("DMG: Using '%s' within XAR file '%s'...\n", pszName, pszFilename));
     1506                *phXarFss       = hXarFss;
     1507                *phDmgFileInXar = hDmgFileInXar;
     1508
     1509                RTStrFree(pszName);
     1510                RTVfsObjRelease(hVfsObj);
     1511
     1512                return VINF_SUCCESS;
     1513            }
     1514        }
     1515
     1516        /* Release the current return values. */
     1517        RTStrFree(pszName);
     1518        RTVfsObjRelease(hVfsObj);
     1519    }
     1520
     1521    /* Not found or some kind of error. */
     1522    RTVfsFsStrmRelease(hXarFss);
     1523    if (rc == VERR_EOF)
     1524        rc = VERR_VD_DMG_NOT_FOUND_INSIDE_XAR;
     1525    AssertStmt(RT_FAILURE_NP(rc), rc = VERR_INTERNAL_ERROR_4);
     1526    return rc;
     1527}
     1528
     1529
    13591530/**
    13601531 * Worker for dmgOpen that reads in and validates all the necessary
     
    13701541
    13711542    pThis->pIfError = VDIfErrorGet(pThis->pVDIfsDisk);
    1372     pThis->pIfIo = VDIfIoIntGet(pThis->pVDIfsImage);
    1373     AssertPtrReturn(pThis->pIfIo, VERR_INVALID_PARAMETER);
    1374 
    1375     int rc = vdIfIoIntFileOpen(pThis->pIfIo, pThis->pszFilename,
    1376                                VDOpenFlagsToFileOpenFlags(uOpenFlags,
    1377                                                           false /* fCreate */),
     1543    pThis->pIfIoXxx = VDIfIoIntGet(pThis->pVDIfsImage);
     1544    pThis->hDmgFileInXar = NIL_RTVFSFILE;
     1545    pThis->hXarFss = NIL_RTVFSFSSTREAM;
     1546    AssertPtrReturn(pThis->pIfIoXxx, VERR_INVALID_PARAMETER);
     1547
     1548    int rc = vdIfIoIntFileOpen(pThis->pIfIoXxx, pThis->pszFilename,
     1549                               VDOpenFlagsToFileOpenFlags(uOpenFlags, false /* fCreate */),
    13781550                               &pThis->pStorage);
    13791551    if (RT_FAILURE(rc))
     
    13851557
    13861558    /*
     1559     * Check for XAR archive.
     1560     */
     1561    uint32_t u32XarMagic;
     1562    rc = dmgWrapFileReadSync(pThis, 0, &u32XarMagic, sizeof(u32XarMagic));
     1563    if (RT_FAILURE(rc))
     1564        return rc;
     1565    if (u32XarMagic == XAR_HEADER_MAGIC)
     1566    {
     1567        rc = dmgOpenImageWithinXar(VDOpenFlagsToFileOpenFlags(uOpenFlags, false /* fCreate */),
     1568                                   VDIfIoGet(pThis->pVDIfsImage),
     1569                                   pThis->pStorage,
     1570                                   pThis->pszFilename,
     1571                                   &pThis->hXarFss, &pThis->hDmgFileInXar);
     1572        if (RT_FAILURE(rc))
     1573            return rc;
     1574    }
     1575
     1576    /*
    13871577     * Read the footer.
    13881578     */
    1389     rc = vdIfIoIntFileGetSize(pThis->pIfIo, pThis->pStorage, &pThis->cbFile);
     1579    rc = dmgWrapFileGetSize(pThis, &pThis->cbFile);
    13901580    if (RT_FAILURE(rc))
    13911581        return rc;
    13921582    if (pThis->cbFile < 1024)
    13931583        return VERR_VD_DMG_INVALID_HEADER;
    1394     rc = vdIfIoIntFileReadSync(pThis->pIfIo, pThis->pStorage,
    1395                                pThis->cbFile - sizeof(pThis->Ftr),
    1396                                &pThis->Ftr, sizeof(pThis->Ftr));
     1584    rc = dmgWrapFileReadSync(pThis, pThis->cbFile - sizeof(pThis->Ftr), &pThis->Ftr, sizeof(pThis->Ftr));
    13971585    if (RT_FAILURE(rc))
    13981586        return rc;
     
    14241612    if (!pszXml)
    14251613        return VERR_NO_MEMORY;
    1426     rc = vdIfIoIntFileReadSync(pThis->pIfIo, pThis->pStorage, pThis->Ftr.offXml,
    1427                                pszXml, cchXml);
     1614    rc = dmgWrapFileReadSync(pThis, pThis->Ftr.offXml, pszXml, cchXml);
    14281615    if (RT_SUCCESS(rc))
    14291616    {
     
    14951682    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p penmType=%#p\n",
    14961683                 pszFilename, pVDIfsDisk, pVDIfsImage, penmType));
    1497     int rc;
    1498     PVDIOSTORAGE pStorage = NULL;
    1499     uint64_t cbFile, offFtr = 0;
    1500     DMGUDIF Ftr;
    15011684
    15021685    PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
     
    15041687
    15051688    /*
    1506      * Open the file and read the footer.
     1689     * Open the file and check for XAR.
    15071690     */
    1508     rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
    1509                            VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
    1510                                                       false /* fCreate */),
    1511                            &pStorage);
     1691    PVDIOSTORAGE pStorage = NULL;
     1692    int rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
     1693                               VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY, false /* fCreate */),
     1694                               &pStorage);
     1695    if (RT_FAILURE(rc))
     1696    {
     1697        LogFlowFunc(("returns %Rrc (error opening file)\n", rc));
     1698        return rc;
     1699    }
     1700
     1701    /*
     1702     * Check for XAR file.
     1703     */
     1704    RTVFSFSSTREAM   hXarFss       = NIL_RTVFSFSSTREAM;
     1705    RTVFSFILE       hDmgFileInXar = NIL_RTVFSFILE;
     1706    uint32_t        u32XarMagic;
     1707    rc = vdIfIoIntFileReadSync(pIfIo, pStorage, 0, &u32XarMagic, sizeof(u32XarMagic));
     1708    if (   RT_SUCCESS(rc)
     1709        && u32XarMagic == XAR_HEADER_MAGIC)
     1710    {
     1711        rc = dmgOpenImageWithinXar(RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE,
     1712                                   VDIfIoGet(pVDIfsImage), pStorage, NULL /* pszFilename */,
     1713                                   &hXarFss, &hDmgFileInXar);
     1714        if (RT_FAILURE(rc))
     1715            return rc;
     1716    }
     1717
     1718    /*
     1719     * Read the DMG footer.
     1720     */
     1721    uint64_t cbFile;
     1722    if (hDmgFileInXar == NIL_RTVFSFILE)
     1723        rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
     1724    else
     1725        rc = RTVfsFileGetSize(hDmgFileInXar, &cbFile);
    15121726    if (RT_SUCCESS(rc))
    1513         rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
    1514     if (RT_SUCCESS(rc))
    1515     {
    1516         offFtr = cbFile - sizeof(Ftr);
    1517         rc = vdIfIoIntFileReadSync(pIfIo, pStorage, offFtr, &Ftr, sizeof(Ftr));
     1727    {
     1728        DMGUDIF  Ftr;
     1729        uint64_t offFtr = cbFile - sizeof(Ftr);
     1730        if (hDmgFileInXar == NIL_RTVFSFILE)
     1731            rc = vdIfIoIntFileReadSync(pIfIo, pStorage, offFtr, &Ftr, sizeof(Ftr));
     1732        else
     1733            rc = RTVfsFileReadAt(hDmgFileInXar, offFtr, &Ftr, sizeof(Ftr), NULL);
     1734        if (RT_SUCCESS(rc))
     1735        {
     1736            /*
     1737             * Do we recognize this stuff? Does it look valid?
     1738             */
     1739            if (   Ftr.u32Magic    == RT_H2BE_U32(DMGUDIF_MAGIC)
     1740                && Ftr.u32Version  == RT_H2BE_U32(DMGUDIF_VER_CURRENT)
     1741                && Ftr.cbFooter    == RT_H2BE_U32(sizeof(Ftr)))
     1742            {
     1743                dmgUdifFtrFile2HostEndian(&Ftr);
     1744                if (dmgUdifFtrIsValid(&Ftr, offFtr))
     1745                {
     1746                    rc = VINF_SUCCESS;
     1747                    *penmType = VDTYPE_DVD;
     1748                }
     1749                else
     1750                {
     1751                    DMG_PRINTF(("Bad DMG: '%s' offFtr=%RTfoff\n", pszFilename, offFtr));
     1752                    rc = VERR_VD_DMG_INVALID_HEADER;
     1753                }
     1754            }
     1755            else
     1756                rc = VERR_VD_DMG_INVALID_HEADER;
     1757        }
    15181758    }
    15191759    else
    15201760        rc = VERR_VD_DMG_INVALID_HEADER;
    15211761
    1522     if (RT_SUCCESS(rc))
    1523     {
    1524         /*
    1525          * Do we recognize this stuff? Does it look valid?
    1526          */
    1527         if (    Ftr.u32Magic    == RT_H2BE_U32(DMGUDIF_MAGIC)
    1528             &&  Ftr.u32Version  == RT_H2BE_U32(DMGUDIF_VER_CURRENT)
    1529             &&  Ftr.cbFooter    == RT_H2BE_U32(sizeof(Ftr)))
    1530         {
    1531             dmgUdifFtrFile2HostEndian(&Ftr);
    1532             if (dmgUdifFtrIsValid(&Ftr, offFtr))
    1533             {
    1534                 rc = VINF_SUCCESS;
    1535                 *penmType = VDTYPE_DVD;
    1536             }
    1537             else
    1538             {
    1539                 DMG_PRINTF(("Bad DMG: '%s' offFtr=%RTfoff\n", pszFilename, offFtr));
    1540                 rc = VERR_VD_DMG_INVALID_HEADER;
    1541             }
    1542         }
    1543         else
    1544             rc = VERR_VD_DMG_INVALID_HEADER;
    1545     }
    1546 
    1547     if (pStorage)
    1548         vdIfIoIntFileClose(pIfIo, pStorage);
     1762    /* Clean up. */
     1763    RTVfsFileRelease(hDmgFileInXar);
     1764    RTVfsFsStrmRelease(hXarFss);
     1765    vdIfIoIntFileClose(pIfIo, pStorage);
    15491766
    15501767    LogFlowFunc(("returns %Rrc\n", rc));
     
    15581775{
    15591776    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
    1560     int rc = VINF_SUCCESS;
    1561     PDMGIMAGE pThis;
    15621777
    15631778    /* Check open flags. All valid flags are (in principle) supported. */
    1564     if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
    1565     {
    1566         rc = VERR_INVALID_PARAMETER;
    1567         goto out;
    1568     }
     1779    AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
    15691780
    15701781    /* Check remaining arguments. */
    1571     if (   !VALID_PTR(pszFilename)
    1572         || !*pszFilename)
    1573     {
    1574         rc = VERR_INVALID_PARAMETER;
    1575         goto out;
    1576     }
     1782    AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
     1783    AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
    15771784
    15781785    /*
     
    15861793        || (uOpenFlags & VD_OPEN_FLAGS_ASYNC_IO))
    15871794    {
    1588         rc = VERR_NOT_SUPPORTED;
    1589         goto out;
     1795        LogFlowFunc(("Unsupported flag(s): %#x\n", uOpenFlags));
     1796        return VERR_INVALID_PARAMETER;
    15901797    }
    15911798
     
    15941801     * then hand it over to a worker function that does all the rest.
    15951802     */
    1596     pThis = (PDMGIMAGE)RTMemAllocZ(sizeof(*pThis));
    1597     if (!pThis)
    1598     {
    1599         rc = VERR_NO_MEMORY;
    1600         goto out;
    1601     }
    1602 
    1603     pThis->pszFilename = pszFilename;
    1604     pThis->pStorage    = NULL;
    1605     pThis->pVDIfsDisk  = pVDIfsDisk;
    1606     pThis->pVDIfsImage = pVDIfsImage;
    1607 
    1608     rc = dmgOpenImage(pThis, uOpenFlags);
    1609   if (RT_SUCCESS(rc))
    1610         *ppBackendData = pThis;
    1611     else
    1612         RTMemFree(pThis);
    1613 
    1614 out:
     1803    int rc = VERR_NO_MEMORY;
     1804    PDMGIMAGE pThis = (PDMGIMAGE)RTMemAllocZ(sizeof(*pThis));
     1805    if (pThis)
     1806    {
     1807        pThis->pszFilename = pszFilename;
     1808        pThis->pStorage    = NULL;
     1809        pThis->pVDIfsDisk  = pVDIfsDisk;
     1810        pThis->pVDIfsImage = pVDIfsImage;
     1811
     1812        rc = dmgOpenImage(pThis, uOpenFlags);
     1813        if (RT_SUCCESS(rc))
     1814            *ppBackendData = pThis;
     1815        else
     1816            RTMemFree(pThis);
     1817    }
     1818
    16151819    LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
    16161820    return rc;
     
    16901894            case DMGEXTENTTYPE_RAW:
    16911895            {
    1692                 rc = vdIfIoIntFileReadUser(pThis->pIfIo, pThis->pStorage,
    1693                                            pExtent->offFileStart + DMG_BLOCK2BYTE(uExtentRel),
    1694                                            pIoCtx, cbToRead);
     1896                rc = dmgWrapFileReadUser(pThis, pExtent->offFileStart + DMG_BLOCK2BYTE(uExtentRel), pIoCtx, cbToRead);
    16951897                break;
    16961898            }
    16971899            case DMGEXTENTTYPE_ZERO:
    16981900            {
    1699                 vdIfIoIntIoCtxSet(pThis->pIfIo, pIoCtx, 0, cbToRead);
     1901                vdIfIoIntIoCtxSet(pThis->pIfIoXxx, pIoCtx, 0, cbToRead);
    17001902                break;
    17011903            }
     
    17271929
    17281930                if (RT_SUCCESS(rc))
    1729                     vdIfIoIntIoCtxCopyTo(pThis->pIfIo, pIoCtx,
     1931                    vdIfIoIntIoCtxCopyTo(pThis->pIfIoXxx, pIoCtx,
    17301932                                         (uint8_t *)pThis->pvDecompExtent + DMG_BLOCK2BYTE(uExtentRel),
    17311933                                         cbToRead);
     
    18392041    AssertPtr(pThis);
    18402042
    1841     if (pThis)
     2043    if (pThis && pThis->pStorage)
    18422044    {
    18432045        uint64_t cbFile;
    1844         if (pThis->pStorage)
    1845         {
    1846             int rc = vdIfIoIntFileGetSize(pThis->pIfIo, pThis->pStorage, &cbFile);
    1847             if (RT_SUCCESS(rc))
    1848                 cb = cbFile;
    1849         }
     2046        int rc = dmgWrapFileGetSize(pThis, &cbFile);
     2047        if (RT_SUCCESS(rc))
     2048            cb = cbFile;
    18502049    }
    18512050
  • trunk/src/VBox/Storage/testcase/Makefile.kmk

    r48846 r48852  
    8484 # vbox-img - static because it migth be used as at standalone tool.
    8585 #
    86  vbox-img_TEMPLATE = VBOXR3STATIC
     86 vbox-img_TEMPLATE = VBoxR3Static
    8787 vbox-img_DEFS += IN_VBOXDDU IN_VBOXDDU_STATIC VBOX_HDD_NO_DYNAMIC_BACKENDS
    8888 vbox-img_SOURCES = \
     
    100100        ../QCOW.cpp \
    101101        ../VHDX.cpp \
    102         ../VCICache.cpp
     102        ../VCICache.cpp \
     103       ../VDIfVfs.cpp
    103104 vbox-img_LIBS = \
    104105        $(VBOX_LIB_RUNTIME_STATIC)
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