VirtualBox

Changeset 19685 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
May 14, 2009 10:20:15 AM (16 years ago)
Author:
vboxsync
Message:

.vhd: nitpicking, logging fixes

File:
1 edited

Legend:

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

    r18965 r19685  
    3636#include <iprt/string.h>
    3737#include <iprt/rand.h>
     38#include <iprt/stream.h>
    3839
    3940#define VHD_RELATIVE_MAX_PATH 512
     
    4142
    4243#define VHD_SECTOR_SIZE 512
    43 #define VHD_BLOCK_SIZE  0x00200000
     44#define VHD_BLOCK_SIZE  (2 * _1M)
    4445
    4546/* This is common to all VHD disk types and is located at the end of the image */
    4647#pragma pack(1)
    47 typedef struct VHDFooter {
     48typedef struct VHDFooter
     49{
    4850    char     Cookie[8];
    4951    uint32_t Features;
     
    325327    }
    326328    rc = RTFileWriteAt(pImage->File, RT_BE2H_U64(pLocator->u64DataOffset), pvBuf,
    327         RT_BE2H_U32(pLocator->u32DataSpace) * VHD_SECTOR_SIZE, NULL);
     329                       RT_BE2H_U32(pLocator->u32DataSpace) * VHD_SECTOR_SIZE, NULL);
    328330
    329331out:
     
    348350        return rc;
    349351    if (memcmp(ddh.Cookie, VHD_DYNAMIC_DISK_HEADER_COOKIE, VHD_DYNAMIC_DISK_HEADER_COOKIE_SIZE) != 0)
    350     {
    351352        return VERR_VD_VHD_INVALID_HEADER;
    352     }
     353
    353354    uint32_t u32Checksum = RT_BE2H_U32(ddh.Checksum);
    354355    ddh.Checksum = 0;
    355356    if (u32Checksum != vhdChecksum(&ddh, sizeof(ddh)))
    356     {
    357357        return VERR_VD_VHD_INVALID_HEADER;
    358     }
     358
    359359    /* Update parent's timestamp. */
    360360    ddh.ParentTimeStamp = RT_H2BE_U32(pImage->u32ParentTimeStamp);
     
    420420
    421421    rc = RTFileReadAt(File, pImage->uCurrentEndOfFile, &vhdFooter, sizeof(VHDFooter), NULL);
    422     if (memcmp(vhdFooter.Cookie, VHD_FOOTER_COOKIE, VHD_FOOTER_COOKIE_SIZE) != 0) {
     422    if (memcmp(vhdFooter.Cookie, VHD_FOOTER_COOKIE, VHD_FOOTER_COOKIE_SIZE) != 0)
    423423        return VERR_VD_VHD_INVALID_HEADER;
    424     }
    425424
    426425    switch (RT_BE2H_U32(vhdFooter.DiskType))
     
    526525    pImage->cBlockAllocationTableEntries = RT_BE2H_U32(vhdDynamicDiskHeader.MaxTableEntries);
    527526    LogFlowFunc(("MaxTableEntries=%lu\n", pImage->cBlockAllocationTableEntries));
    528     AssertMsg(!(pImage->cbDataBlock % 512), ("%s: Data block size is not a multiple of 512!!\n", __FUNCTION__));
    529 
    530     pImage->cSectorsPerDataBlock = pImage->cbDataBlock / 512;
     527    AssertMsg(!(pImage->cbDataBlock % VHD_SECTOR_SIZE), ("%s: Data block size is not a multiple of %!\n", __FUNCTION__, VHD_SECTOR_SIZE));
     528
     529    pImage->cSectorsPerDataBlock = pImage->cbDataBlock / VHD_SECTOR_SIZE;
    531530    LogFlowFunc(("SectorsPerDataBlock=%u\n", pImage->cSectorsPerDataBlock));
    532531
     
    536535     */
    537536    pImage->cbDataBlockBitmap = pImage->cSectorsPerDataBlock / 8;
    538     pImage->cDataBlockBitmapSectors = pImage->cbDataBlockBitmap / 512;
     537    pImage->cDataBlockBitmapSectors = pImage->cbDataBlockBitmap / VHD_SECTOR_SIZE;
    539538    LogFlowFunc(("cbDataBlockBitmap=%u\n", pImage->cbDataBlockBitmap));
    540539
     
    566565
    567566    for (i = 0; i < pImage->cBlockAllocationTableEntries; i++)
    568     {
    569567        pImage->pBlockAllocationTable[i] = RT_BE2H_U32(pBlockAllocationTable[i]);
    570     }
    571568
    572569    RTMemFree(pBlockAllocationTable);
     
    747744        uOpenFlags = 0;
    748745
    749     LogFlowFunc(("returned %d\n", uOpenFlags));
     746    LogFlowFunc(("returned %#x\n", uOpenFlags));
    750747    return uOpenFlags;
    751748}
     
    849846    /* Freeing a never allocated image (e.g. because the open failed) is
    850847     * not signalled as an error. After all nothing bad happens. */
    851     if (pImage) {
     848    if (pImage)
     849    {
    852850        vhdFlush(pImage);
    853851        RTFileClose(pImage->File);
     
    866864    /* Freeing a never allocated image (e.g. because the open failed) is
    867865     * not signalled as an error. After all nothing bad happens. */
    868     if (pImage) {
     866    if (pImage)
     867    {
    869868        if (fDelete)
    870869        {
     
    900899         * Get the data block first.
    901900         */
    902         uint32_t cBlockAllocationTableEntry = (uOffset / 512) / pImage->cSectorsPerDataBlock;
    903         uint32_t cBATEntryIndex = (uOffset / 512) % pImage->cSectorsPerDataBlock;
     901        uint32_t cBlockAllocationTableEntry = (uOffset / VHD_SECTOR_SIZE) / pImage->cSectorsPerDataBlock;
     902        uint32_t cBATEntryIndex = (uOffset / VHD_SECTOR_SIZE) % pImage->cSectorsPerDataBlock;
    904903        uint64_t uVhdOffset;
    905904
     
    917916        }
    918917
    919         uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * 512;
     918        uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * VHD_SECTOR_SIZE;
    920919        LogFlowFunc(("uVhdOffset=%llu cbRead=%u\n", uVhdOffset, cbRead));
    921920
     
    923922         * Clip read range to remain in this data block.
    924923         */
    925         cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
     924        cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE)));
    926925
    927926        /* Read in the block's bitmap. */
    928927        rc = RTFileReadAt(pImage->File,
    929             ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry]) * VHD_SECTOR_SIZE,
    930             pImage->pu8Bitmap, pImage->cbDataBlockBitmap, NULL);
     928                          ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry]) * VHD_SECTOR_SIZE,
     929                          pImage->pu8Bitmap, pImage->cbDataBlockBitmap, NULL);
    931930        if (RT_SUCCESS(rc))
    932931        {
     
    10261025
    10271026    LogFlowFunc(("pBackendData=%p uOffset=%llu pvBuf=%p cbToWrite=%u pcbWriteProcess=%p pcbPreRead=%p pcbPostRead=%p fWrite=%u\n",
    1028              pBackendData, uOffset, pvBuf, cbToWrite, pcbPreRead, pcbPostRead, fWrite));
    1029 
    1030     AssertPtr(pImage);
    1031     Assert(uOffset % 512 == 0);
    1032     Assert(cbToWrite % 512 == 0);
     1027             pBackendData, uOffset, pvBuf, cbToWrite, pcbWriteProcess, pcbPreRead, pcbPostRead, fWrite));
     1028
     1029    AssertPtr(pImage);
     1030    Assert(uOffset % VHD_SECTOR_SIZE == 0);
     1031    Assert(cbToWrite % VHD_SECTOR_SIZE == 0);
    10331032
    10341033    if (pImage->pBlockAllocationTable)
     
    10371036         * Get the data block first.
    10381037         */
    1039         uint32_t cSector = uOffset / 512;
     1038        uint32_t cSector = uOffset / VHD_SECTOR_SIZE;
    10401039        uint32_t cBlockAllocationTableEntry = cSector / pImage->cSectorsPerDataBlock;
    10411040        uint32_t cBATEntryIndex = cSector % pImage->cSectorsPerDataBlock;
     
    10661065             * Set the new end of the file and link the new block into the BAT.
    10671066             */
    1068             pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / 512;
     1067            pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / VHD_SECTOR_SIZE;
    10691068            pImage->uCurrentEndOfFile += cbNewBlock;
    10701069            RTMemFree(pNewBlock);
     
    10741073         * Calculate the real offset in the file.
    10751074         */
    1076         uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * 512;
     1075        uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * VHD_SECTOR_SIZE;
    10771076
    10781077        /*
    10791078         * Clip write range.
    10801079         */
    1081         cbToWrite = RT_MIN(cbToWrite, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
     1080        cbToWrite = RT_MIN(cbToWrite, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE)));
    10821081        RTFileWriteAt(pImage->File, uVhdOffset, pvBuf, cbToWrite, NULL);
    10831082
     
    11421141         * The BAT entries have to be stored in big endian format.
    11431142         */
    1144         unsigned i = 0;
    1145         for (i = 0; i < pImage->cBlockAllocationTableEntries; i++)
    1146         {
     1143        for (unsigned i = 0; i < pImage->cBlockAllocationTableEntries; i++)
    11471144            pBlockAllocationTableToWrite[i] = RT_H2BE_U32(pImage->pBlockAllocationTable[i]);
    1148         }
    11491145
    11501146        /*
     
    13901386static void vhdSetDiskGeometry(PVHDIMAGE pImage, uint64_t cbSize)
    13911387{
    1392     uint64_t u64TotalSectors = cbSize / 512;
     1388    uint64_t u64TotalSectors = cbSize / VHD_SECTOR_SIZE;
    13931389    uint32_t u32CylinderTimesHeads, u32Heads, u32SectorsPerTrack;
    13941390
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