VirtualBox

Changeset 63784 in vbox for trunk/src/VBox/Storage/RAW.cpp


Ignore:
Timestamp:
Sep 9, 2016 9:47:15 PM (8 years ago)
Author:
vboxsync
Message:

Storage/Raw: Cleanup, get rid of goto ...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/RAW.cpp

    r63781 r63784  
    144144                    uint64_t uOff;
    145145                    void *pvBuf = RTMemTmpAllocZ(RAW_FILL_SIZE);
    146                     if (!pvBuf)
    147                         goto out;
    148 
    149                     uOff = pImage->offAccess;
    150                     /* Write data to all image blocks. */
    151                     while (uOff < pImage->cbSize)
     146                    if (RT_LIKELY(pvBuf))
    152147                    {
    153                         unsigned cbChunk = (unsigned)RT_MIN(pImage->cbSize - uOff,
    154                                                             RAW_FILL_SIZE);
    155 
    156                         rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
    157                                                     uOff, pvBuf, cbChunk);
    158                         if (RT_FAILURE(rc))
    159                             goto out;
    160 
    161                         uOff += cbChunk;
     148                        uOff = pImage->offAccess;
     149                        /* Write data to all image blocks. */
     150                        while (uOff < pImage->cbSize)
     151                        {
     152                            unsigned cbChunk = (unsigned)RT_MIN(pImage->cbSize - uOff,
     153                                                                RAW_FILL_SIZE);
     154
     155                            rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage,
     156                                                        uOff, pvBuf, cbChunk);
     157                            if (RT_FAILURE(rc))
     158                                break;
     159
     160                            uOff += cbChunk;
     161                        }
     162
     163                        RTMemTmpFree(pvBuf);
    162164                    }
    163 out:
    164                     if (pvBuf)
    165                         RTMemTmpFree(pvBuf);
     165                    else
     166                        rc = VERR_NO_MEMORY;
    166167                }
    167168                rawFlushImage(pImage);
     
    185186static int rawOpenImage(PRAWIMAGE pImage, unsigned uOpenFlags)
    186187{
    187     int rc;
    188 
    189188    pImage->uOpenFlags = uOpenFlags;
    190189    pImage->fCreate = false;
     
    194193    AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
    195194
    196     /*
    197      * Open the image.
    198      */
    199     rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename,
    200                            VDOpenFlagsToFileOpenFlags(uOpenFlags,
    201                                                       false /* fCreate */),
    202                            &pImage->pStorage);
    203     if (RT_FAILURE(rc))
    204     {
    205         /* Do NOT signal an appropriate error here, as the VD layer has the
    206          * choice of retrying the open if it failed. */
    207         goto out;
    208     }
    209 
    210     rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &pImage->cbSize);
    211     if (RT_FAILURE(rc))
    212         goto out;
    213     if (pImage->cbSize % 512)
    214     {
    215         rc = VERR_VD_RAW_SIZE_MODULO_512;
    216         goto out;
    217     }
    218     pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    219 
    220 out:
     195    /* Open the image. */
     196    int rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename,
     197                               VDOpenFlagsToFileOpenFlags(uOpenFlags,
     198                                                          false /* fCreate */),
     199                               &pImage->pStorage);
     200    if (RT_SUCCESS(rc))
     201    {
     202        rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &pImage->cbSize);
     203        if (   RT_SUCCESS(rc)
     204            && !(pImage->cbSize % 512))
     205            pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
     206        else if (RT_SUCCESS(rc))
     207            rc = VERR_VD_RAW_SIZE_MODULO_512;
     208    }
     209    /* else: Do NOT signal an appropriate error here, as the VD layer has the
     210     *       choice of retrying the open if it failed. */
     211
    221212    if (RT_FAILURE(rc))
    222213        rawFreeImage(pImage, false);
     
    231222                          PCVDGEOMETRY pPCHSGeometry,
    232223                          PCVDGEOMETRY pLCHSGeometry, unsigned uOpenFlags,
    233                           PFNVDPROGRESS pfnProgress, void *pvUser,
     224                          PVDINTERFACEPROGRESS pIfProgress,
    234225                          unsigned uPercentStart, unsigned uPercentSpan)
    235226{
    236227    RT_NOREF1(pszComment);
    237     int rc;
    238     RTFOFF cbFree = 0;
    239     int32_t fOpen;
    240 
    241     uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    242 
    243     pImage->uOpenFlags = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
    244 
    245     pImage->uImageFlags = uImageFlags;
    246     pImage->fCreate = true;
     228    int rc = VINF_SUCCESS;
     229
     230    pImage->fCreate      = true;
     231    pImage->uOpenFlags   = uOpenFlags & ~VD_OPEN_FLAGS_READONLY;
     232    pImage->uImageFlags  = uImageFlags | VD_IMAGE_FLAGS_FIXED;
    247233    pImage->PCHSGeometry = *pPCHSGeometry;
    248234    pImage->LCHSGeometry = *pLCHSGeometry;
    249 
    250     pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk);
    251     pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage);
     235    pImage->pIfError     = VDIfErrorGet(pImage->pVDIfsDisk);
     236    pImage->pIfIo        = VDIfIoIntGet(pImage->pVDIfsImage);
    252237    AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER);
    253238
    254     if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
    255     {
     239    if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF))
     240    {
     241        /* Create image file. */
     242        uint32_t fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */);
     243        if (uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL)
     244            fOpen &= ~RTFILE_O_READ;
     245        rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage);
     246        if (RT_SUCCESS(rc))
     247        {
     248            if (!(uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL))
     249            {
     250                RTFOFF cbFree = 0;
     251
     252                /* Check the free space on the disk and leave early if there is not
     253                 * sufficient space available. */
     254                rc = vdIfIoIntFileGetFreeSpace(pImage->pIfIo, pImage->pszFilename, &cbFree);
     255                if (RT_FAILURE(rc) /* ignore errors */ || ((uint64_t)cbFree >= cbSize))
     256                {
     257                    rc = vdIfIoIntFileSetAllocationSize(pImage->pIfIo, pImage->pStorage, cbSize, 0 /* fFlags */,
     258                                                        pIfProgress ? pIfProgress->pfnProgress : NULL,
     259                                                        pIfProgress ? pIfProgress->Core.pvUser : NULL,
     260                                                        uPercentStart, uPercentSpan);
     261                    if (RT_SUCCESS(rc))
     262                    {
     263                        vdIfProgress(pIfProgress, uPercentStart + uPercentSpan * 98 / 100);
     264
     265                        pImage->cbSize = cbSize;
     266                        rc = rawFlushImage(pImage);
     267                    }
     268                }
     269                else
     270                    rc = vdIfError(pImage->pIfError, VERR_DISK_FULL, RT_SRC_POS, N_("Raw: disk would overflow creating image '%s'"), pImage->pszFilename);
     271            }
     272        }
     273        else
     274            rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
     275    }
     276    else
    256277        rc = vdIfError(pImage->pIfError, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
    257         goto out;
    258     }
    259 
    260     /* Create image file. */
    261     fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */);
    262     if (uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL)
    263         fOpen &= ~RTFILE_O_READ;
    264     rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage);
    265     if (RT_FAILURE(rc))
    266     {
    267         rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Raw: cannot create image '%s'"), pImage->pszFilename);
    268         goto out;
    269     }
    270 
    271     if (!(uOpenFlags & VD_OPEN_FLAGS_SEQUENTIAL))
    272     {
    273         /* Check the free space on the disk and leave early if there is not
    274          * sufficient space available. */
    275         rc = vdIfIoIntFileGetFreeSpace(pImage->pIfIo, pImage->pszFilename, &cbFree);
    276         if (RT_SUCCESS(rc) /* ignore errors */ && ((uint64_t)cbFree < cbSize))
    277         {
    278             rc = vdIfError(pImage->pIfError, VERR_DISK_FULL, RT_SRC_POS, N_("Raw: disk would overflow creating image '%s'"), pImage->pszFilename);
    279             goto out;
    280         }
    281 
    282         /* Allocate & commit whole file if fixed image, it must be more
    283          * effective than expanding file by write operations. */
    284         rc = vdIfIoIntFileSetAllocationSize(pImage->pIfIo, pImage->pStorage, cbSize,
    285                                             0 /* fFlags */, pfnProgress, pvUser, uPercentStart, uPercentSpan);
    286     }
    287 
    288     if (RT_SUCCESS(rc) && pfnProgress)
    289         pfnProgress(pvUser, uPercentStart + uPercentSpan * 98 / 100);
    290 
    291     pImage->cbSize = cbSize;
    292 
    293     rc = rawFlushImage(pImage);
    294 
    295 out:
    296 
    297     if (RT_SUCCESS(rc) && pfnProgress)
    298         pfnProgress(pvUser, uPercentStart + uPercentSpan);
     278
     279    if (RT_SUCCESS(rc))
     280        vdIfProgress(pIfProgress, uPercentStart + uPercentSpan);
    299281
    300282    if (RT_FAILURE(rc))
     
    304286
    305287
    306 /** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
     288/** @copydoc VDIMAGEBACKEND::pfnCheckIfValid */
    307289static DECLCALLBACK(int) rawCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    308290                                         PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
     
    311293    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
    312294    PVDIOSTORAGE pStorage = NULL;
    313     uint64_t cbFile;
    314     int rc = VINF_SUCCESS;
    315     char *pszSuffix = NULL;
    316 
    317295    PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage);
     296
    318297    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
    319 
    320     if (   !VALID_PTR(pszFilename)
    321         || !*pszFilename)
    322     {
    323         rc = VERR_INVALID_PARAMETER;
    324         goto out;
    325     }
    326 
    327     pszSuffix = RTPathSuffix(pszFilename);
     298    AssertReturn((VALID_PTR(pszFilename) && *pszFilename), VERR_INVALID_PARAMETER);
    328299
    329300    /*
    330301     * Open the file and read the footer.
    331302     */
    332     rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
    333                            VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
    334                                                       false /* fCreate */),
    335                            &pStorage);
     303    int rc = vdIfIoIntFileOpen(pIfIo, pszFilename,
     304                               VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
     305                                                          false /* fCreate */),
     306                               &pStorage);
    336307    if (RT_SUCCESS(rc))
    337308    {
     309        uint64_t cbFile;
     310        const char *pszSuffix = RTPathSuffix(pszFilename);
    338311        rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile);
    339312
     
    385358        vdIfIoIntFileClose(pIfIo, pStorage);
    386359
    387 out:
    388     LogFlowFunc(("returns %Rrc\n", rc));
    389     return rc;
    390 }
    391 
    392 /** @copydoc VBOXHDDBACKEND::pfnOpen */
     360    LogFlowFunc(("returns %Rrc\n", rc));
     361    return rc;
     362}
     363
     364/** @copydoc VDIMAGEBACKEND::pfnOpen */
    393365static DECLCALLBACK(int) rawOpen(const char *pszFilename, unsigned uOpenFlags,
    394366                                 PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    395367                                 VDTYPE enmType, void **ppBackendData)
    396368{
    397     LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
     369    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p enmType=%u ppBackendData=%#p\n",
     370                 pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, enmType, ppBackendData));
    398371    int rc;
    399372    PRAWIMAGE pImage;
     
    402375
    403376    /* Check open flags. All valid flags are supported. */
    404     if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
    405     {
    406         rc = VERR_INVALID_PARAMETER;
    407         goto out;
    408     }
    409 
    410     /* Check remaining arguments. */
    411     if (   !VALID_PTR(pszFilename)
    412         || !*pszFilename)
    413     {
    414         rc = VERR_INVALID_PARAMETER;
    415         goto out;
    416     }
    417 
     377    AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
     378    AssertReturn((VALID_PTR(pszFilename) && *pszFilename), VERR_INVALID_PARAMETER);
    418379
    419380    pImage = (PRAWIMAGE)RTMemAllocZ(sizeof(RAWIMAGE));
    420     if (!pImage)
    421     {
     381    if (RT_LIKELY(pImage))
     382    {
     383        pImage->pszFilename = pszFilename;
     384        pImage->pStorage = NULL;
     385        pImage->pVDIfsDisk = pVDIfsDisk;
     386        pImage->pVDIfsImage = pVDIfsImage;
     387
     388        rc = rawOpenImage(pImage, uOpenFlags);
     389        if (RT_SUCCESS(rc))
     390        {
     391            if (enmType == VDTYPE_DVD)
     392                pImage->cbSector = 2048;
     393            else
     394                pImage->cbSector = 512;
     395            *ppBackendData = pImage;
     396        }
     397        else
     398            RTMemFree(pImage);
     399    }
     400    else
    422401        rc = VERR_NO_MEMORY;
    423         goto out;
    424     }
    425     pImage->pszFilename = pszFilename;
    426     pImage->pStorage = NULL;
    427     pImage->pVDIfsDisk = pVDIfsDisk;
    428     pImage->pVDIfsImage = pVDIfsImage;
    429 
    430     rc = rawOpenImage(pImage, uOpenFlags);
    431     if (RT_SUCCESS(rc))
    432     {
    433         if (enmType == VDTYPE_DVD)
    434             pImage->cbSector = 2048;
    435         else
    436             pImage->cbSector = 512;
    437         *ppBackendData = pImage;
    438     }
    439     else
    440         RTMemFree(pImage);
    441 
    442 out:
     402
    443403    LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
    444404    return rc;
    445405}
    446406
    447 /** @copydoc VBOXHDDBACKEND::pfnCreate */
     407/** @copydoc VDIMAGEBACKEND::pfnCreate */
    448408static DECLCALLBACK(int) rawCreate(const char *pszFilename, uint64_t cbSize,
    449409                                   unsigned uImageFlags, const char *pszComment,
     
    458418    LogFlowFunc(("pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p Uuid=%RTuuid uOpenFlags=%#x uPercentStart=%u uPercentSpan=%u pVDIfsDisk=%#p pVDIfsImage=%#p pVDIfsOperation=%#p enmType=%u ppBackendData=%#p",
    459419                 pszFilename, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, enmType, ppBackendData));
    460     int rc;
    461     PRAWIMAGE pImage;
    462 
    463     PFNVDPROGRESS pfnProgress = NULL;
    464     void *pvUser = NULL;
    465     PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
    466     if (pIfProgress)
    467     {
    468         pfnProgress = pIfProgress->pfnProgress;
    469         pvUser = pIfProgress->Core.pvUser;
    470     }
    471420
    472421    /* Check the VD container type. Yes, hard disk must be allowed, otherwise
    473422     * various tools using this backend for hard disk images will fail. */
    474423    if (enmType != VDTYPE_HDD && enmType != VDTYPE_DVD && enmType != VDTYPE_FLOPPY)
    475     {
    476         rc = VERR_VD_INVALID_TYPE;
    477         goto out;
    478     }
    479 
    480     /* Check open flags. All valid flags are supported. */
    481     if (uOpenFlags & ~VD_OPEN_FLAGS_MASK)
    482     {
    483         rc = VERR_INVALID_PARAMETER;
    484         goto out;
    485     }
    486 
    487     /* Check remaining arguments. */
    488     if (   !VALID_PTR(pszFilename)
    489         || !*pszFilename
    490         || !VALID_PTR(pPCHSGeometry)
    491         || !VALID_PTR(pLCHSGeometry))
    492     {
    493         rc = VERR_INVALID_PARAMETER;
    494         goto out;
    495     }
    496 
    497     pImage = (PRAWIMAGE)RTMemAllocZ(sizeof(RAWIMAGE));
    498     if (!pImage)
    499     {
     424        return VERR_VD_INVALID_TYPE;
     425
     426    int rc = VINF_SUCCESS;
     427    PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
     428
     429    /* Check arguments. */
     430    AssertReturn(!(uOpenFlags & ~VD_OPEN_FLAGS_MASK), VERR_INVALID_PARAMETER);
     431    AssertReturn(   VALID_PTR(pszFilename)
     432                 && *pszFilename
     433                 && VALID_PTR(pPCHSGeometry)
     434                 && VALID_PTR(pLCHSGeometry), VERR_INVALID_PARAMETER);
     435
     436    PRAWIMAGE pImage = (PRAWIMAGE)RTMemAllocZ(sizeof(RAWIMAGE));
     437    if (RT_LIKELY(pImage))
     438    {
     439        pImage->pszFilename = pszFilename;
     440        pImage->pStorage = NULL;
     441        pImage->pVDIfsDisk = pVDIfsDisk;
     442        pImage->pVDIfsImage = pVDIfsImage;
     443
     444        rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
     445                            pPCHSGeometry, pLCHSGeometry, uOpenFlags,
     446                            pIfProgress, uPercentStart, uPercentSpan);
     447        if (RT_SUCCESS(rc))
     448        {
     449            /* So far the image is opened in read/write mode. Make sure the
     450             * image is opened in read-only mode if the caller requested that. */
     451            if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
     452            {
     453                rawFreeImage(pImage, false);
     454                rc = rawOpenImage(pImage, uOpenFlags);
     455            }
     456
     457            if (RT_SUCCESS(rc))
     458                *ppBackendData = pImage;
     459        }
     460
     461        if (RT_FAILURE(rc))
     462            RTMemFree(pImage);
     463    }
     464    else
    500465        rc = VERR_NO_MEMORY;
    501         goto out;
    502     }
    503     pImage->pszFilename = pszFilename;
    504     pImage->pStorage = NULL;
    505     pImage->pVDIfsDisk = pVDIfsDisk;
    506     pImage->pVDIfsImage = pVDIfsImage;
    507 
    508     rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
    509                         pPCHSGeometry, pLCHSGeometry, uOpenFlags,
    510                         pfnProgress, pvUser, uPercentStart, uPercentSpan);
     466
     467    LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
     468    return rc;
     469}
     470
     471/** @copydoc VDIMAGEBACKEND::pfnRename */
     472static DECLCALLBACK(int) rawRename(void *pBackendData, const char *pszFilename)
     473{
     474    LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
     475    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     476
     477    AssertReturn((pImage && pszFilename && *pszFilename), VERR_INVALID_PARAMETER);
     478
     479    /* Close the image. */
     480    int rc = rawFreeImage(pImage, false);
    511481    if (RT_SUCCESS(rc))
    512482    {
    513         /* So far the image is opened in read/write mode. Make sure the
    514          * image is opened in read-only mode if the caller requested that. */
    515         if (uOpenFlags & VD_OPEN_FLAGS_READONLY)
     483        /* Rename the file. */
     484        rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
     485        if (RT_SUCCESS(rc))
    516486        {
    517             rawFreeImage(pImage, false);
    518             rc = rawOpenImage(pImage, uOpenFlags);
    519             if (RT_FAILURE(rc))
    520             {
    521                 RTMemFree(pImage);
    522                 goto out;
    523             }
     487            /* Update pImage with the new information. */
     488            pImage->pszFilename = pszFilename;
     489
     490            /* Open the old image with new name. */
     491            rc = rawOpenImage(pImage, pImage->uOpenFlags);
    524492        }
    525         *ppBackendData = pImage;
    526     }
    527     else
    528         RTMemFree(pImage);
    529 
    530 out:
    531     LogFlowFunc(("returns %Rrc (pBackendData=%#p)\n", rc, *ppBackendData));
    532     return rc;
    533 }
    534 
    535 /** @copydoc VBOXHDDBACKEND::pfnRename */
    536 static DECLCALLBACK(int) rawRename(void *pBackendData, const char *pszFilename)
    537 {
    538     LogFlowFunc(("pBackendData=%#p pszFilename=%#p\n", pBackendData, pszFilename));
    539     int rc = VINF_SUCCESS;
    540     PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    541 
    542     /* Check arguments. */
    543     if (   !pImage
    544         || !pszFilename
    545         || !*pszFilename)
    546     {
    547         rc = VERR_INVALID_PARAMETER;
    548         goto out;
    549     }
    550 
    551     /* Close the image. */
    552     rc = rawFreeImage(pImage, false);
    553     if (RT_FAILURE(rc))
    554         goto out;
    555 
    556     /* Rename the file. */
    557     rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0);
    558     if (RT_FAILURE(rc))
    559     {
    560         /* The move failed, try to reopen the original image. */
    561         int rc2 = rawOpenImage(pImage, pImage->uOpenFlags);
    562         if (RT_FAILURE(rc2))
    563             rc = rc2;
    564 
    565         goto out;
    566     }
    567 
    568     /* Update pImage with the new information. */
    569     pImage->pszFilename = pszFilename;
    570 
    571     /* Open the old image with new name. */
    572     rc = rawOpenImage(pImage, pImage->uOpenFlags);
    573     if (RT_FAILURE(rc))
    574         goto out;
    575 
    576 out:
    577     LogFlowFunc(("returns %Rrc\n", rc));
    578     return rc;
    579 }
    580 
    581 /** @copydoc VBOXHDDBACKEND::pfnClose */
     493        else
     494        {
     495            /* The move failed, try to reopen the original image. */
     496            int rc2 = rawOpenImage(pImage, pImage->uOpenFlags);
     497            if (RT_FAILURE(rc2))
     498                rc = rc2;
     499        }
     500    }
     501
     502    LogFlowFunc(("returns %Rrc\n", rc));
     503    return rc;
     504}
     505
     506/** @copydoc VDIMAGEBACKEND::pfnClose */
    582507static DECLCALLBACK(int) rawClose(void *pBackendData, bool fDelete)
    583508{
    584509    LogFlowFunc(("pBackendData=%#p fDelete=%d\n", pBackendData, fDelete));
    585510    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    586     int rc;
    587 
    588     rc = rawFreeImage(pImage, fDelete);
     511    int rc = rawFreeImage(pImage, fDelete);
    589512    RTMemFree(pImage);
    590513
     
    593516}
    594517
    595 /** @copydoc VBOXHDDBACKEND::pfnRead */
     518/** @copydoc VDIMAGEBACKEND::pfnRead */
    596519static DECLCALLBACK(int) rawRead(void *pBackendData, uint64_t uOffset, size_t cbRead,
    597520                                 PVDIOCTX pIoCtx, size_t *pcbActuallyRead)
     
    619542}
    620543
    621 /** @copydoc VBOXHDDBACKEND::pfnWrite */
     544/** @copydoc VDIMAGEBACKEND::pfnWrite */
    622545static DECLCALLBACK(int) rawWrite(void *pBackendData, uint64_t uOffset, size_t cbWrite,
    623546                                  PVDIOCTX pIoCtx, size_t *pcbWriteProcess, size_t *pcbPreRead,
     
    651574}
    652575
    653 /** @copydoc VBOXHDDBACKEND::pfnFlush */
     576/** @copydoc VDIMAGEBACKEND::pfnFlush */
    654577static DECLCALLBACK(int) rawFlush(void *pBackendData, PVDIOCTX pIoCtx)
    655578{
     
    664587}
    665588
    666 /** @copydoc VBOXHDDBACKEND::pfnGetVersion */
     589/** @copydoc VDIMAGEBACKEND::pfnGetVersion */
    667590static DECLCALLBACK(unsigned) rawGetVersion(void *pBackendData)
    668591{
     
    670593    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    671594
    672     AssertPtr(pImage);
    673 
    674     if (pImage)
    675         return 1;
    676     else
    677         return 0;
    678 }
    679 
    680 /** @copydoc VBOXHDDBACKEND::pfnGetSize */
     595    AssertPtrReturn(pImage, 0);
     596
     597    return 1;
     598}
     599
     600/** @copydoc VDIMAGEBACKEND::pfnGetSize */
    681601static DECLCALLBACK(uint32_t) rawGetSectorSize(void *pBackendData)
    682602{
     
    685605    uint32_t cb = 0;
    686606
    687     AssertPtr(pImage);
    688 
    689     if (pImage && pImage->pStorage)
     607    AssertPtrReturn(pImage, 0);
     608
     609    if (pImage->pStorage)
    690610        cb = pImage->cbSector;
    691611
     
    694614}
    695615
    696 /** @copydoc VBOXHDDBACKEND::pfnGetSize */
     616/** @copydoc VDIMAGEBACKEND::pfnGetSize */
    697617static DECLCALLBACK(uint64_t) rawGetSize(void *pBackendData)
    698618{
     
    701621    uint64_t cb = 0;
    702622
    703     AssertPtr(pImage);
    704 
    705     if (pImage && pImage->pStorage)
     623    AssertPtrReturn(pImage, 0);
     624
     625    if (pImage->pStorage)
    706626        cb = pImage->cbSize;
    707627
     
    710630}
    711631
    712 /** @copydoc VBOXHDDBACKEND::pfnGetFileSize */
     632/** @copydoc VDIMAGEBACKEND::pfnGetFileSize */
    713633static DECLCALLBACK(uint64_t) rawGetFileSize(void *pBackendData)
    714634{
    715635    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    716636    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    717     uint64_t cb = 0;
    718 
    719     AssertPtr(pImage);
    720 
    721     if (pImage)
    722     {
    723         uint64_t cbFile;
    724         if (pImage->pStorage)
    725         {
    726             int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile);
    727             if (RT_SUCCESS(rc))
    728                 cb += cbFile;
    729         }
    730     }
    731 
    732     LogFlowFunc(("returns %lld\n", cb));
    733     return cb;
    734 }
    735 
    736 /** @copydoc VBOXHDDBACKEND::pfnGetPCHSGeometry */
     637
     638    AssertPtrReturn(pImage, 0);
     639
     640    uint64_t cbFile = 0;
     641    if (pImage->pStorage)
     642    {
     643        int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile);
     644        if (RT_FAILURE(rc))
     645            cbFile = 0; /* Make sure it is 0 */
     646    }
     647
     648    LogFlowFunc(("returns %lld\n", cbFile));
     649    return cbFile;
     650}
     651
     652/** @copydoc VDIMAGEBACKEND::pfnGetPCHSGeometry */
    737653static DECLCALLBACK(int) rawGetPCHSGeometry(void *pBackendData,
    738654                                            PVDGEOMETRY pPCHSGeometry)
     
    740656    LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
    741657    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    742     int rc;
    743 
    744     AssertPtr(pImage);
    745 
    746     if (pImage)
    747     {
    748         if (pImage->PCHSGeometry.cCylinders)
    749         {
    750             *pPCHSGeometry = pImage->PCHSGeometry;
    751             rc = VINF_SUCCESS;
    752         }
    753         else
    754             rc = VERR_VD_GEOMETRY_NOT_SET;
    755     }
    756     else
    757         rc = VERR_VD_NOT_OPENED;
     658    int rc = VINF_SUCCESS;
     659
     660    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     661
     662    if (pImage->PCHSGeometry.cCylinders)
     663        *pPCHSGeometry = pImage->PCHSGeometry;
     664    else
     665        rc = VERR_VD_GEOMETRY_NOT_SET;
    758666
    759667    LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
     
    761669}
    762670
    763 /** @copydoc VBOXHDDBACKEND::pfnSetPCHSGeometry */
     671/** @copydoc VDIMAGEBACKEND::pfnSetPCHSGeometry */
    764672static DECLCALLBACK(int) rawSetPCHSGeometry(void *pBackendData,
    765673                                            PCVDGEOMETRY pPCHSGeometry)
    766674{
    767     LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n", pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
    768     PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    769     int rc;
    770 
    771     AssertPtr(pImage);
    772 
    773     if (pImage)
    774     {
    775         if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    776         {
    777             rc = VERR_VD_IMAGE_READ_ONLY;
    778             goto out;
    779         }
    780 
     675    LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
     676                 pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
     677    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     678    int rc = VINF_SUCCESS;
     679
     680    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     681
     682    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     683        rc = VERR_VD_IMAGE_READ_ONLY;
     684    else
    781685        pImage->PCHSGeometry = *pPCHSGeometry;
    782         rc = VINF_SUCCESS;
    783     }
    784     else
    785         rc = VERR_VD_NOT_OPENED;
    786 
    787 out:
    788     LogFlowFunc(("returns %Rrc\n", rc));
    789     return rc;
    790 }
    791 
    792 /** @copydoc VBOXHDDBACKEND::pfnGetLCHSGeometry */
     686
     687    LogFlowFunc(("returns %Rrc\n", rc));
     688    return rc;
     689}
     690
     691/** @copydoc VDIMAGEBACKEND::pfnGetLCHSGeometry */
    793692static DECLCALLBACK(int) rawGetLCHSGeometry(void *pBackendData,
    794693                                            PVDGEOMETRY pLCHSGeometry)
     
    796695     LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
    797696    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    798     int rc;
    799 
    800     AssertPtr(pImage);
    801 
    802     if (pImage)
    803     {
    804         if (pImage->LCHSGeometry.cCylinders)
    805         {
    806             *pLCHSGeometry = pImage->LCHSGeometry;
    807             rc = VINF_SUCCESS;
    808         }
    809         else
    810             rc = VERR_VD_GEOMETRY_NOT_SET;
    811     }
    812     else
    813         rc = VERR_VD_NOT_OPENED;
     697    int rc = VINF_SUCCESS;
     698
     699    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     700
     701    if (pImage->LCHSGeometry.cCylinders)
     702        *pLCHSGeometry = pImage->LCHSGeometry;
     703    else
     704        rc = VERR_VD_GEOMETRY_NOT_SET;
    814705
    815706    LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
     
    817708}
    818709
    819 /** @copydoc VBOXHDDBACKEND::pfnSetLCHSGeometry */
     710/** @copydoc VDIMAGEBACKEND::pfnSetLCHSGeometry */
    820711static DECLCALLBACK(int) rawSetLCHSGeometry(void *pBackendData,
    821712                                            PCVDGEOMETRY pLCHSGeometry)
    822713{
    823     LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n", pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
    824     PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    825     int rc;
    826 
    827     AssertPtr(pImage);
    828 
    829     if (pImage)
    830     {
    831         if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    832         {
    833             rc = VERR_VD_IMAGE_READ_ONLY;
    834             goto out;
    835         }
    836 
     714    LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
     715                 pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
     716    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     717    int rc = VINF_SUCCESS;
     718
     719    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     720
     721    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     722        rc = VERR_VD_IMAGE_READ_ONLY;
     723    else
    837724        pImage->LCHSGeometry = *pLCHSGeometry;
    838         rc = VINF_SUCCESS;
    839     }
    840     else
    841         rc = VERR_VD_NOT_OPENED;
    842 
    843 out:
    844     LogFlowFunc(("returns %Rrc\n", rc));
    845     return rc;
    846 }
    847 
    848 /** @copydoc VBOXHDDBACKEND::pfnGetImageFlags */
     725
     726    LogFlowFunc(("returns %Rrc\n", rc));
     727    return rc;
     728}
     729
     730/** @copydoc VDIMAGEBACKEND::pfnGetImageFlags */
    849731static DECLCALLBACK(unsigned) rawGetImageFlags(void *pBackendData)
    850732{
    851733    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    852734    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    853     unsigned uImageFlags;
    854 
    855     AssertPtr(pImage);
    856 
    857     if (pImage)
    858         uImageFlags = pImage->uImageFlags;
    859     else
    860         uImageFlags = 0;
    861 
    862     LogFlowFunc(("returns %#x\n", uImageFlags));
    863     return uImageFlags;
    864 }
    865 
    866 /** @copydoc VBOXHDDBACKEND::pfnGetOpenFlags */
     735
     736    AssertPtrReturn(pImage, 0);
     737
     738    LogFlowFunc(("returns %#x\n", pImage->uImageFlags));
     739    return pImage->uImageFlags;
     740}
     741
     742/** @copydoc VDIMAGEBACKEND::pfnGetOpenFlags */
    867743static DECLCALLBACK(unsigned) rawGetOpenFlags(void *pBackendData)
    868744{
    869745    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    870746    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    871     unsigned uOpenFlags;
    872 
    873     AssertPtr(pImage);
    874 
    875     if (pImage)
    876         uOpenFlags = pImage->uOpenFlags;
    877     else
    878         uOpenFlags = 0;
    879 
    880     LogFlowFunc(("returns %#x\n", uOpenFlags));
    881     return uOpenFlags;
    882 }
    883 
    884 /** @copydoc VBOXHDDBACKEND::pfnSetOpenFlags */
     747
     748    AssertPtrReturn(pImage, 0);
     749
     750    LogFlowFunc(("returns %#x\n", pImage->uOpenFlags));
     751    return pImage->uOpenFlags;
     752}
     753
     754/** @copydoc VDIMAGEBACKEND::pfnSetOpenFlags */
    885755static DECLCALLBACK(int) rawSetOpenFlags(void *pBackendData, unsigned uOpenFlags)
    886756{
    887757    LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
    888758    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    889     int rc;
     759    int rc = VINF_SUCCESS;
    890760
    891761    /* Image must be opened and the new flags must be valid. */
     
    893763                                   | VD_OPEN_FLAGS_ASYNC_IO | VD_OPEN_FLAGS_SHAREABLE
    894764                                   | VD_OPEN_FLAGS_SEQUENTIAL | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS)))
    895     {
    896765        rc = VERR_INVALID_PARAMETER;
    897         goto out;
    898     }
    899 
    900     /* Implement this operation via reopening the image. */
    901     rc = rawFreeImage(pImage, false);
    902     if (RT_FAILURE(rc))
    903         goto out;
    904     rc = rawOpenImage(pImage, uOpenFlags);
    905 
    906 out:
    907     LogFlowFunc(("returns %Rrc\n", rc));
    908     return rc;
    909 }
    910 
    911 /** @copydoc VBOXHDDBACKEND::pfnGetComment */
     766    else
     767    {
     768        /* Implement this operation via reopening the image. */
     769        rc = rawFreeImage(pImage, false);
     770        if (RT_SUCCESS(rc))
     771            rc = rawOpenImage(pImage, uOpenFlags);
     772    }
     773
     774    LogFlowFunc(("returns %Rrc\n", rc));
     775    return rc;
     776}
     777
     778/** @copydoc VDIMAGEBACKEND::pfnGetComment */
    912779static DECLCALLBACK(int) rawGetComment(void *pBackendData, char *pszComment,
    913780                                       size_t cbComment)
     
    916783    LogFlowFunc(("pBackendData=%#p pszComment=%#p cbComment=%zu\n", pBackendData, pszComment, cbComment));
    917784    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    918     int rc;
    919 
    920     AssertPtr(pImage);
    921 
    922     if (pImage)
    923         rc = VERR_NOT_SUPPORTED;
    924     else
    925         rc = VERR_VD_NOT_OPENED;
    926 
    927     LogFlowFunc(("returns %Rrc comment='%s'\n", rc, pszComment));
    928     return rc;
    929 }
    930 
    931 /** @copydoc VBOXHDDBACKEND::pfnSetComment */
     785
     786    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     787
     788    LogFlowFunc(("returns %Rrc comment='%s'\n", VERR_NOT_SUPPORTED, pszComment));
     789    return VERR_NOT_SUPPORTED;
     790}
     791
     792/** @copydoc VDIMAGEBACKEND::pfnSetComment */
    932793static DECLCALLBACK(int) rawSetComment(void *pBackendData, const char *pszComment)
    933794{
     
    935796    LogFlowFunc(("pBackendData=%#p pszComment=\"%s\"\n", pBackendData, pszComment));
    936797    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     798
     799    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     800
    937801    int rc;
    938 
    939     AssertPtr(pImage);
    940 
    941     if (pImage)
    942     {
    943         if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    944             rc = VERR_VD_IMAGE_READ_ONLY;
    945         else
    946             rc = VERR_NOT_SUPPORTED;
    947     }
    948     else
    949         rc = VERR_VD_NOT_OPENED;
    950 
    951     LogFlowFunc(("returns %Rrc\n", rc));
    952     return rc;
    953 }
    954 
    955 /** @copydoc VBOXHDDBACKEND::pfnGetUuid */
     802    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     803        rc = VERR_VD_IMAGE_READ_ONLY;
     804    else
     805        rc = VERR_NOT_SUPPORTED;
     806
     807    LogFlowFunc(("returns %Rrc\n", rc));
     808    return rc;
     809}
     810
     811/** @copydoc VDIMAGEBACKEND::pfnGetUuid */
    956812static DECLCALLBACK(int) rawGetUuid(void *pBackendData, PRTUUID pUuid)
    957813{
     
    959815    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    960816    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    961     int rc;
    962 
    963     AssertPtr(pImage);
    964 
    965     if (pImage)
    966         rc = VERR_NOT_SUPPORTED;
    967     else
    968         rc = VERR_VD_NOT_OPENED;
    969 
    970     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    971     return rc;
    972 }
    973 
    974 /** @copydoc VBOXHDDBACKEND::pfnSetUuid */
     817
     818    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     819
     820    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     821    return VERR_NOT_SUPPORTED;
     822}
     823
     824/** @copydoc VDIMAGEBACKEND::pfnSetUuid */
    975825static DECLCALLBACK(int) rawSetUuid(void *pBackendData, PCRTUUID pUuid)
    976826{
     
    978828    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    979829    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     830
     831    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     832
    980833    int rc;
    981 
    982     LogFlowFunc(("%RTuuid\n", pUuid));
    983     AssertPtr(pImage);
    984 
    985     if (pImage)
    986     {
    987         if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    988             rc = VERR_NOT_SUPPORTED;
    989         else
    990             rc = VERR_VD_IMAGE_READ_ONLY;
    991     }
    992     else
    993         rc = VERR_VD_NOT_OPENED;
    994 
    995     LogFlowFunc(("returns %Rrc\n", rc));
    996     return rc;
    997 }
    998 
    999 /** @copydoc VBOXHDDBACKEND::pfnGetModificationUuid */
     834    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     835        rc = VERR_VD_IMAGE_READ_ONLY;
     836    else
     837        rc = VERR_NOT_SUPPORTED;
     838
     839    LogFlowFunc(("returns %Rrc\n", rc));
     840    return rc;
     841}
     842
     843/** @copydoc VDIMAGEBACKEND::pfnGetModificationUuid */
    1000844static DECLCALLBACK(int) rawGetModificationUuid(void *pBackendData, PRTUUID pUuid)
    1001845{
     
    1003847    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    1004848    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    1005     int rc;
    1006 
    1007     AssertPtr(pImage);
    1008 
    1009     if (pImage)
    1010         rc = VERR_NOT_SUPPORTED;
    1011     else
    1012         rc = VERR_VD_NOT_OPENED;
    1013 
    1014     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    1015     return rc;
    1016 }
    1017 
    1018 /** @copydoc VBOXHDDBACKEND::pfnSetModificationUuid */
     849
     850    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     851
     852    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     853    return VERR_NOT_SUPPORTED;
     854}
     855
     856/** @copydoc VDIMAGEBACKEND::pfnSetModificationUuid */
    1019857static DECLCALLBACK(int) rawSetModificationUuid(void *pBackendData, PCRTUUID pUuid)
    1020858{
     
    1022860    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    1023861    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     862
     863    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     864
    1024865    int rc;
    1025 
    1026     AssertPtr(pImage);
    1027 
    1028     if (pImage)
    1029     {
    1030         if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    1031             rc = VERR_NOT_SUPPORTED;
    1032         else
    1033             rc = VERR_VD_IMAGE_READ_ONLY;
    1034     }
    1035     else
    1036         rc = VERR_VD_NOT_OPENED;
    1037 
    1038     LogFlowFunc(("returns %Rrc\n", rc));
    1039     return rc;
    1040 }
    1041 
    1042 /** @copydoc VBOXHDDBACKEND::pfnGetParentUuid */
     866    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     867        rc = VERR_VD_IMAGE_READ_ONLY;
     868    else
     869        rc = VERR_NOT_SUPPORTED;
     870
     871    LogFlowFunc(("returns %Rrc\n", rc));
     872    return rc;
     873}
     874
     875/** @copydoc VDIMAGEBACKEND::pfnGetParentUuid */
    1043876static DECLCALLBACK(int) rawGetParentUuid(void *pBackendData, PRTUUID pUuid)
    1044877{
     
    1046879    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    1047880    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    1048     int rc;
    1049 
    1050     AssertPtr(pImage);
    1051 
    1052     if (pImage)
    1053         rc = VERR_NOT_SUPPORTED;
    1054     else
    1055         rc = VERR_VD_NOT_OPENED;
    1056 
    1057     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    1058     return rc;
    1059 }
    1060 
    1061 /** @copydoc VBOXHDDBACKEND::pfnSetParentUuid */
     881
     882    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     883
     884    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     885    return VERR_NOT_SUPPORTED;
     886}
     887
     888/** @copydoc VDIMAGEBACKEND::pfnSetParentUuid */
    1062889static DECLCALLBACK(int) rawSetParentUuid(void *pBackendData, PCRTUUID pUuid)
    1063890{
     
    1065892    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    1066893    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     894
     895    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     896
    1067897    int rc;
    1068 
    1069     AssertPtr(pImage);
    1070 
    1071     if (pImage)
    1072     {
    1073         if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    1074             rc = VERR_NOT_SUPPORTED;
    1075         else
    1076             rc = VERR_VD_IMAGE_READ_ONLY;
    1077     }
    1078     else
    1079         rc = VERR_VD_NOT_OPENED;
    1080 
    1081     LogFlowFunc(("returns %Rrc\n", rc));
    1082     return rc;
    1083 }
    1084 
    1085 /** @copydoc VBOXHDDBACKEND::pfnGetParentModificationUuid */
     898    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     899        rc = VERR_VD_IMAGE_READ_ONLY;
     900    else
     901        rc = VERR_NOT_SUPPORTED;
     902
     903    LogFlowFunc(("returns %Rrc\n", rc));
     904    return rc;
     905}
     906
     907/** @copydoc VDIMAGEBACKEND::pfnGetParentModificationUuid */
    1086908static DECLCALLBACK(int) rawGetParentModificationUuid(void *pBackendData, PRTUUID pUuid)
    1087909{
     
    1089911    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    1090912    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     913
     914    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     915
    1091916    int rc;
    1092 
    1093     AssertPtr(pImage);
    1094 
    1095     if (pImage)
     917    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     918        rc = VERR_VD_IMAGE_READ_ONLY;
     919    else
    1096920        rc = VERR_NOT_SUPPORTED;
    1097     else
    1098         rc = VERR_VD_NOT_OPENED;
    1099921
    1100922    LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
     
    1102924}
    1103925
    1104 /** @copydoc VBOXHDDBACKEND::pfnSetParentModificationUuid */
     926/** @copydoc VDIMAGEBACKEND::pfnSetParentModificationUuid */
    1105927static DECLCALLBACK(int) rawSetParentModificationUuid(void *pBackendData, PCRTUUID pUuid)
    1106928{
     
    1108930    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    1109931    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
     932
     933    AssertPtrReturn(pImage, VERR_VD_NOT_OPENED);
     934
    1110935    int rc;
    1111 
    1112     AssertPtr(pImage);
    1113 
    1114     if (pImage)
    1115     {
    1116         if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    1117             rc = VERR_NOT_SUPPORTED;
    1118         else
    1119             rc = VERR_VD_IMAGE_READ_ONLY;
    1120     }
    1121     else
    1122         rc = VERR_VD_NOT_OPENED;
    1123 
    1124     LogFlowFunc(("returns %Rrc\n", rc));
    1125     return rc;
    1126 }
    1127 
    1128 /** @copydoc VBOXHDDBACKEND::pfnDump */
     936    if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     937        rc = VERR_VD_IMAGE_READ_ONLY;
     938    else
     939        rc = VERR_NOT_SUPPORTED;
     940
     941    LogFlowFunc(("returns %Rrc\n", rc));
     942    return rc;
     943}
     944
     945/** @copydoc VDIMAGEBACKEND::pfnDump */
    1129946static DECLCALLBACK(void) rawDump(void *pBackendData)
    1130947{
    1131948    PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;
    1132949
    1133     AssertPtr(pImage);
    1134     if (pImage)
    1135     {
    1136         vdIfErrorMessage(pImage->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cbSector=%llu\n",
    1137                         pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors,
    1138                         pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors,
    1139                         pImage->cbSize / 512);
    1140     }
     950    AssertPtrReturnVoid(pImage);
     951    vdIfErrorMessage(pImage->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cbSector=%llu\n",
     952                     pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors,
     953                     pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors,
     954                     pImage->cbSize / 512);
    1141955}
    1142956
Note: See TracChangeset for help on using the changeset viewer.

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