VirtualBox

Changeset 14321 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Nov 18, 2008 5:20:18 PM (16 years ago)
Author:
vboxsync
Message:

Storage/VHD: Add todo for handling diff images (too complicated and risky to do this right now), and lots of assertion/logging cleanup. No functionality change.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp

    r13840 r14321  
    468468
    469469    pImage->u64DataOffset = RT_BE2H_U64(vhdFooter.DataOffset);
    470     LogFlow(("%s: DataOffset=%llu\n", __FUNCTION__, pImage->u64DataOffset));
     470    LogFlowFunc(("DataOffset=%llu\n", pImage->u64DataOffset));
    471471
    472472    if (pImage->enmImageType == VD_IMAGE_TYPE_NORMAL || pImage->enmImageType == VD_IMAGE_TYPE_DIFF)
     
    524524
    525525    pImage->cbDataBlock = RT_BE2H_U32(vhdDynamicDiskHeader.BlockSize);
    526     LogFlow(("%s: BlockSize=%u\n", __FUNCTION__, pImage->cbDataBlock));
     526    LogFlowFunc(("BlockSize=%u\n", pImage->cbDataBlock));
    527527    pImage->cBlockAllocationTableEntries = RT_BE2H_U32(vhdDynamicDiskHeader.MaxTableEntries);
    528     LogFlow(("%s: MaxTableEntries=%lu\n", __FUNCTION__, pImage->cBlockAllocationTableEntries));
     528    LogFlowFunc(("MaxTableEntries=%lu\n", pImage->cBlockAllocationTableEntries));
    529529    AssertMsg(!(pImage->cbDataBlock % 512), ("%s: Data block size is not a multiple of 512!!\n", __FUNCTION__));
    530530
    531531    pImage->cSectorsPerDataBlock = pImage->cbDataBlock / 512;
    532     LogFlow(("%s: SectorsPerDataBlock=%u\n", __FUNCTION__, pImage->cSectorsPerDataBlock));
     532    LogFlowFunc(("SectorsPerDataBlock=%u\n", pImage->cSectorsPerDataBlock));
    533533
    534534    /*
     
    538538    pImage->cbDataBlockBitmap = pImage->cSectorsPerDataBlock / 8;
    539539    pImage->cDataBlockBitmapSectors = pImage->cbDataBlockBitmap / 512;
    540     LogFlow(("%s: cbDataBlockBitmap=%u\n", __FUNCTION__, pImage->cbDataBlockBitmap));
     540    LogFlowFunc(("cbDataBlockBitmap=%u\n", pImage->cbDataBlockBitmap));
    541541
    542542    pImage->pu8Bitmap = (uint8_t *)RTMemAllocZ(pImage->cbDataBlockBitmap);
     
    552552     */
    553553    uBlockAllocationTableOffset = RT_BE2H_U64(vhdDynamicDiskHeader.TableOffset);
    554     LogFlow(("%s: uBlockAllocationTableOffset=%llu\n", __FUNCTION__, uBlockAllocationTableOffset));
     554    LogFlowFunc(("uBlockAllocationTableOffset=%llu\n", uBlockAllocationTableOffset));
    555555    pImage->uBlockAllocationTableOffset = uBlockAllocationTableOffset;
    556556    rc = RTFileReadAt(pImage->File, uBlockAllocationTableOffset, pBlockAllocationTable, pImage->cBlockAllocationTableEntries * sizeof(uint32_t), NULL);
    557557    pImage->uDataBlockStart = uBlockAllocationTableOffset + pImage->cBlockAllocationTableEntries * sizeof(uint32_t);
    558     LogFlow(("%s: uDataBlockStart=%llu\n", __FUNCTION__, pImage->uDataBlockStart));
     558    LogFlowFunc(("uDataBlockStart=%llu\n", pImage->uDataBlockStart));
    559559
    560560    /*
     
    612612    PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;
    613613
    614     Assert(pImage);
     614    AssertPtr(pImage);
    615615
    616616    if (pImage)
     
    625625    int rc = VINF_SUCCESS;
    626626
    627     Assert(pImage);
    628     Assert(penmImageType);
     627    AssertPtr(pImage);
     628    AssertPtr(penmImageType);
    629629
    630630    if (pImage)
     
    641641    int rc;
    642642
    643     Assert(pImage);
     643    AssertPtr(pImage);
    644644
    645645    if (pImage)
     
    656656        rc = VERR_VDI_NOT_OPENED;
    657657
    658     LogFlow(("%s: returned %Rrc (CHS=%u/%u/%u)\n", __FUNCTION__, rc,
    659              pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors));
     658    LogFlowFunc(("returned %Rrc (CHS=%u/%u/%u)\n", rc, pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors));
    660659    return rc;
    661660}
     
    666665    int rc;
    667666
    668     Assert(pImage);
     667    AssertPtr(pImage);
    669668
    670669    if (pImage)
     
    683682
    684683out:
    685     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     684    LogFlowFunc(("returned %Rrc\n", rc));
    686685    return rc;
    687686}
     
    692691    int rc;
    693692
    694     Assert(pImage);
     693    AssertPtr(pImage);
    695694
    696695    if (pImage)
     
    707706        rc = VERR_VDI_NOT_OPENED;
    708707
    709     LogFlow(("%s: returned %Rrc (CHS=%u/%u/%u)\n", __FUNCTION__, rc,
    710              pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors));
     708    LogFlowFunc(("returned %Rrc (CHS=%u/%u/%u)\n", rc, pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors));
    711709    return rc;
    712710}
     
    717715    int rc;
    718716
    719     Assert(pImage);
     717    AssertPtr(pImage);
    720718
    721719    if (pImage)
     
    734732
    735733out:
    736     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     734    LogFlowFunc(("returned %Rrc\n", rc));
    737735    return rc;
    738736}
     
    743741    unsigned uImageFlags;
    744742
    745     Assert(pImage);
     743    AssertPtr(pImage);
    746744
    747745    if (pImage)
     
    750748        uImageFlags = 0;
    751749
    752     LogFlow(("%s: returned %#x\n", __FUNCTION__, uImageFlags));
     750    LogFlowFunc(("returned %#x\n", uImageFlags));
    753751    return uImageFlags;
    754752}
     
    759757    unsigned uOpenFlags;
    760758
    761     Assert(pImage);
     759    AssertPtr(pImage);
    762760
    763761    if (pImage)
     
    766764        uOpenFlags = 0;
    767765
    768     LogFlow(("%s: returned %d\n", __FUNCTION__, uOpenFlags));
     766    LogFlowFunc(("returned %d\n", uOpenFlags));
    769767    return uOpenFlags;
    770768}
     
    793791
    794792out:
    795     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     793    LogFlowFunc(("returned %Rrc\n", rc));
    796794    return rc;
    797795}
     
    834832    }
    835833
    836     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     834    LogFlowFunc(("returned %Rrc\n", rc));
    837835    return rc;
    838836}
     
    857855    }
    858856
    859     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     857    LogFlowFunc(("returned %Rrc\n", rc));
    860858    return rc;
    861859}
     
    866864    int rc = VINF_SUCCESS;
    867865
    868     LogFlow(("%s: pBackendData=%p uOffset=%#llx pvBuf=%p cbRead=%u pcbActuallyRead=%p\n", __FUNCTION__, pBackendData, uOffset, pvBuf, cbRead, pcbActuallyRead));
     866    LogFlowFunc(("pBackendData=%p uOffset=%#llx pvBuf=%p cbRead=%u pcbActuallyRead=%p\n", pBackendData, uOffset, pvBuf, cbRead, pcbActuallyRead));
    869867
    870868    if (uOffset + cbRead > pImage->cbSize)
     
    883881        uint64_t uVhdOffset;
    884882
    885         LogFlow(("%s: cBlockAllocationTableEntry=%u cBatEntryIndex=%u\n", __FUNCTION__, cBlockAllocationTableEntry, cBATEntryIndex));
    886         LogFlow(("%s: BlockAllocationEntry=%u\n", __FUNCTION__, pImage->pBlockAllocationTable[cBlockAllocationTableEntry]));
     883        LogFlowFunc(("cBlockAllocationTableEntry=%u cBatEntryIndex=%u\n", cBlockAllocationTableEntry, cBATEntryIndex));
     884        LogFlowFunc(("BlockAllocationEntry=%u\n", pImage->pBlockAllocationTable[cBlockAllocationTableEntry]));
    887885
    888886        /*
     
    897895
    898896        uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * 512;
    899         Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
     897        Log(("%s: uVhdOffset=%llu cbRead=%u\n", uVhdOffset, cbRead));
    900898
    901899        /*
     
    948946                cbRead = cSectors * VHD_SECTOR_SIZE;
    949947
    950                 Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
     948                Log(("%s: uVhdOffset=%llu cbRead=%u\n", uVhdOffset, cbRead));
    951949                rc = RTFileReadAt(pImage->File, uVhdOffset, pvBuf, cbRead, NULL);
    952950            }
     
    977975
    978976                cbRead = cSectors * VHD_SECTOR_SIZE;
    979                 Log(("%s: Sectors free: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
     977                Log(("%s: Sectors free: uVhdOffset=%llu cbRead=%u\n", uVhdOffset, cbRead));
    980978                rc = VERR_VDI_BLOCK_FREE;
    981979            }
     
    999997}
    1000998
    1001 static int vhdWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf, size_t cbWrite, size_t *pcbWriteProcess, size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite)
     999static int vhdWrite(void *pBackendData, uint64_t uOffset, const void *pvBuf, size_t cbToWrite, size_t *pcbWriteProcess, size_t *pcbPreRead, size_t *pcbPostRead, unsigned fWrite)
    10021000{
    10031001    PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;
    10041002    int rc = VINF_SUCCESS;
    10051003
    1006     LogFlow(("%s: pBackendData=%p uOffset=%llu pvBuf=%p cbWrite=%u pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p fWrite=%u\n",
    1007              __FUNCTION__, pBackendData, uOffset, pvBuf, cbWrite, pcbPreRead, pcbPostRead, fWrite));
    1008 
     1004    LogFlowFunc(("pBackendData=%p uOffset=%llu pvBuf=%p cbToWrite=%u pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p fWrite=%u\n",
     1005             pBackendData, uOffset, pvBuf, cbToWrite, pcbPreRead, pcbPostRead, fWrite));
     1006
     1007    AssertPtr(pImage);
    10091008    Assert(uOffset % 512 == 0);
    1010     Assert(cbWrite % 512 == 0);
     1009    Assert(cbToWrite % 512 == 0);
    10111010
    10121011    if (pImage->pBlockAllocationTable)
     
    10241023         * and we need to allocate a new block.
    10251024         */
     1025        /** @todo Integrate this properly into the unallocated block logic.
     1026         * The current code wouldn't be able to handle diff images at all. */
    10261027        if (pImage->pBlockAllocationTable[cBlockAllocationTableEntry] == ~0U)
    10271028        {
     
    10531054         * Clip write range.
    10541055         */
    1055         cbWrite = RT_MIN(cbWrite, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
    1056         RTFileWriteAt(pImage->File, uVhdOffset, pvBuf, cbWrite, NULL);
     1056        cbToWrite = RT_MIN(cbToWrite, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
     1057        RTFileWriteAt(pImage->File, uVhdOffset, pvBuf, cbToWrite, NULL);
    10571058
    10581059        /* Read in the block's bitmap. */
     
    10631064        {
    10641065            /* Set the bits for all sectors having been written. */
    1065             for (uint32_t iSector = 0; iSector < (cbWrite / VHD_SECTOR_SIZE); iSector++)
     1066            for (uint32_t iSector = 0; iSector < (cbToWrite / VHD_SECTOR_SIZE); iSector++)
    10661067            {
    10671068                uint32_t iBitmap    = cBATEntryIndex / 8; /* Byte in the block bitmap. */
     
    10811082    else
    10821083    {
    1083         rc = RTFileWriteAt(pImage->File, uOffset, pvBuf, cbWrite, NULL);
     1084        rc = RTFileWriteAt(pImage->File, uOffset, pvBuf, cbToWrite, NULL);
    10841085    }
    10851086
    10861087    if (pcbWriteProcess)
    1087         *pcbWriteProcess = cbWrite;
     1088        *pcbWriteProcess = cbToWrite;
    10881089
    10891090    return rc;
     
    11361137    PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;
    11371138
    1138     Assert(pImage);
    1139 
    1140     if (pImage)
    1141     {
    1142         Log(("%s: cbSize=%llu\n", __FUNCTION__, pImage->cbSize));
     1139    AssertPtr(pImage);
     1140
     1141    if (pImage)
     1142    {
     1143        Log(("%s: cbSize=%llu\n", pImage->cbSize));
    11431144        return pImage->cbSize;
    11441145    }
     
    11511152    PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;
    11521153
    1153     Assert(pImage);
     1154    AssertPtr(pImage);
    11541155
    11551156    if (pImage)
     
    11711172    int rc;
    11721173
    1173     Assert(pImage);
     1174    AssertPtr(pImage);
    11741175
    11751176    if (pImage)
     
    11801181    else
    11811182        rc = VERR_VDI_NOT_OPENED;
    1182     LogFlow(("%s: returned %Rrc (%RTuuid)\n", __FUNCTION__, rc, pUuid));
     1183    LogFlowFunc(("returned %Rrc (%RTuuid)\n", rc, pUuid));
    11831184    return rc;
    11841185}
     
    11891190    int rc;
    11901191
    1191     LogFlowFunc((" %RTuuid\n", pUuid));
    1192     Assert(pImage);
     1192    LogFlowFunc(("Uuid=%RTuuid\n", pUuid));
     1193    AssertPtr(pImage);
    11931194
    11941195    if (pImage)
     
    12001201    else
    12011202        rc = VERR_VDI_NOT_OPENED;
    1202     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1203    LogFlowFunc(("returned %Rrc\n", rc));
    12031204    return rc;
    12041205}
     
    12091210    int rc;
    12101211
    1211     Assert(pImage);
     1212    AssertPtr(pImage);
    12121213
    12131214    if (pImage)
     
    12181219        rc = VERR_VDI_NOT_OPENED;
    12191220
    1220     LogFlow(("%s: returned %Rrc comment='%s'\n", __FUNCTION__, rc, pszComment));
     1221    LogFlowFunc(("returned %Rrc comment='%s'\n", rc, pszComment));
    12211222    return rc;
    12221223}
     
    12271228    int rc;
    12281229
    1229     LogFlowFunc((" comment '%s'\n", pszComment));
    1230     Assert(pImage);
     1230    LogFlowFunc(("pszComment='%s'\n", pszComment));
     1231    AssertPtr(pImage);
    12311232
    12321233    if (pImage)
     
    12381239        rc = VERR_VDI_NOT_OPENED;
    12391240
    1240     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1241    LogFlowFunc(("returned %Rrc\n", rc));
    12411242    return rc;
    12421243}
     
    12471248    int rc;
    12481249
    1249     Assert(pImage);
     1250    AssertPtr(pImage);
    12501251
    12511252    if (pImage)
     
    12551256    else
    12561257        rc = VERR_VDI_NOT_OPENED;
    1257     LogFlow(("%s: returned %Rrc (%RTuuid)\n", __FUNCTION__, rc, pUuid));
     1258    LogFlowFunc(("returned %Rrc (%RTuuid)\n", rc, pUuid));
    12581259    return rc;
    12591260}
     
    12641265    int rc;
    12651266
    1266     LogFlowFunc((" %RTuuid\n", pUuid));
    1267     Assert(pImage);
     1267    LogFlowFunc(("Uuid=%RTuuid\n", pUuid));
     1268    AssertPtr(pImage);
    12681269
    12691270    if (pImage)
     
    12731274    else
    12741275        rc = VERR_VDI_NOT_OPENED;
    1275     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1276    LogFlowFunc(("returned %Rrc\n", rc));
    12761277    return rc;
    12771278}
     
    12821283    int rc;
    12831284
    1284     Assert(pImage);
     1285    AssertPtr(pImage);
    12851286
    12861287    if (pImage)
     
    12911292    else
    12921293        rc = VERR_VDI_NOT_OPENED;
    1293     LogFlow(("%s: returned %Rrc (%RTuuid)\n", __FUNCTION__, rc, pUuid));
     1294    LogFlowFunc(("returned %Rrc (%RTuuid)\n", rc, pUuid));
    12941295    return rc;
    12951296}
     
    13011302
    13021303    LogFlowFunc((" %RTuuid\n", pUuid));
    1303     Assert(pImage);
     1304    AssertPtr(pImage);
    13041305
    13051306    if (pImage && pImage->File != NIL_RTFILE)
     
    13151316    else
    13161317        rc = VERR_VDI_NOT_OPENED;
    1317     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1318    LogFlowFunc(("returned %Rrc\n", rc));
    13181319    return rc;
    13191320}
     
    13241325    int rc;
    13251326
    1326     Assert(pImage);
     1327    AssertPtr(pImage);
    13271328
    13281329    if (pImage)
     
    13321333    else
    13331334        rc = VERR_VDI_NOT_OPENED;
    1334     LogFlow(("%s: returned %Rrc (%RTuuid)\n", __FUNCTION__, rc, pUuid));
     1335    LogFlowFunc(("returned %Rrc (%RTuuid)\n", rc, pUuid));
    13351336    return rc;
    13361337}
     
    13411342    int rc;
    13421343
    1343     LogFlow(("%s: %RTuuid\n", pUuid));
    1344     Assert(pImage);
     1344    LogFlowFunc(("%RTuuid\n", pUuid));
     1345    AssertPtr(pImage);
    13451346
    13461347    if (pImage)
     
    13501351    else
    13511352        rc = VERR_VDI_NOT_OPENED;
    1352     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1353    LogFlowFunc(("returned %Rrc\n", rc));
    13531354    return rc;
    13541355}
     
    17211722    }
    17221723out:
    1723     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1724    LogFlowFunc(("returned %Rrc\n", rc));
    17241725    return rc;
    17251726}
     
    17291730    PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;
    17301731
    1731     Assert(pImage);
     1732    AssertPtr(pImage);
    17321733    if (pImage)
    17331734    {
     
    17421743    PVHDIMAGE pImage = (PVHDIMAGE)pvBackendData;
    17431744
    1744     Assert(pImage);
     1745    AssertPtr(pImage);
    17451746    if (pImage)
    17461747    {
     
    17521753    else
    17531754        rc = VERR_VDI_NOT_OPENED;
    1754     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1755    LogFlowFunc(("returned %Rrc\n", rc));
    17551756    return rc;
    17561757}
     
    17611762    PVHDIMAGE pImage = (PVHDIMAGE)pvBackendData;
    17621763
    1763     Assert(pImage);
     1764    AssertPtr(pImage);
    17641765    if (pImage)
    17651766        vhdTime2RtTime(pTimeStamp, pImage->u32ParentTimeStamp);
    17661767    else
    17671768        rc = VERR_VDI_NOT_OPENED;
    1768     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1769    LogFlowFunc(("returned %Rrc\n", rc));
    17691770    return rc;
    17701771}
     
    17751776    PVHDIMAGE pImage = (PVHDIMAGE)pvBackendData;
    17761777
    1777     Assert(pImage);
     1778    AssertPtr(pImage);
    17781779    if (pImage)
    17791780    {
     
    17881789    else
    17891790        rc = VERR_VDI_NOT_OPENED;
    1790     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1791    LogFlowFunc(("returned %Rrc\n", rc));
    17911792    return rc;
    17921793}
     
    17971798    PVHDIMAGE pImage = (PVHDIMAGE)pvBackendData;
    17981799
    1799     Assert(pImage);
     1800    AssertPtr(pImage);
    18001801    if (pImage)
    18011802        *ppszParentFilename = RTStrDup(pImage->pszParentFilename);
    18021803    else
    18031804        rc = VERR_VDI_NOT_OPENED;
    1804     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1805    LogFlowFunc(("returned %Rrc\n", rc));
    18051806    return rc;
    18061807}
     
    18111812    PVHDIMAGE pImage = (PVHDIMAGE)pvBackendData;
    18121813
    1813     Assert(pImage);
     1814    AssertPtr(pImage);
    18141815    if (pImage)
    18151816    {
     
    18291830    else
    18301831        rc = VERR_VDI_NOT_OPENED;
    1831     LogFlow(("%s: returned %Rrc\n", __FUNCTION__, rc));
     1832    LogFlowFunc(("returned %Rrc\n", rc));
    18321833    return rc;
    18331834}
     
    18461847}
    18471848
    1848 static int vhdAsyncWrite(void *pvBackendData, uint64_t uOffset, size_t cbWrite,
     1849static int vhdAsyncWrite(void *pvBackendData, uint64_t uOffset, size_t cbToWrite,
    18491850                         PPDMDATASEG paSeg, unsigned cSeg, void *pvUser)
    18501851{
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