VirtualBox

Changeset 13571 in vbox


Ignore:
Timestamp:
Oct 26, 2008 10:02:50 PM (16 years ago)
Author:
vboxsync
Message:

VHD: Backout r38444. Caused another problem and #3263 will be fixed in another way.

File:
1 edited

Legend:

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

    r13568 r13571  
    879879         * Get the data block first.
    880880         */
    881         uint64_t uOffsetSectorAligned       = uOffset & ~0x1ff;
    882         uint32_t cbOffsetDifference         = uOffset - uOffsetSectorAligned;
    883         uint32_t cBlockAllocationTableEntry = (uOffsetSectorAligned / VHD_SECTOR_SIZE) / pImage->cSectorsPerDataBlock;
    884         uint32_t cSectorsToRead             = (cbRead / VHD_SECTOR_SIZE) + (cbOffsetDifference ? 1 : 0);
    885         uint32_t cBATEntryIndex             = (uOffsetSectorAligned / VHD_SECTOR_SIZE) % pImage->cSectorsPerDataBlock;
     881        uint32_t cBlockAllocationTableEntry = (uOffset / 512) / pImage->cSectorsPerDataBlock;
     882        uint32_t cBATEntryIndex = (uOffset / 512) % pImage->cSectorsPerDataBlock;
    886883        uint64_t uVhdOffset;
    887884
     
    899896        }
    900897
    901         uVhdOffset = (((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * VHD_SECTOR_SIZE) + cbOffsetDifference;
     898        uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * 512;
    902899        Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
    903900
     
    905902         * Clip read range to remain in this data block.
    906903         */
    907         cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE) - cbOffsetDifference));
     904        cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
    908905
    909906        /* Read in the block's bitmap. */
     
    947944
    948945                    iBATEntryIndexCurr++;
    949                 } while (cSectors < cSectorsToRead);
    950 
    951                 cbRead = RT_MIN(cbRead, cSectors * VHD_SECTOR_SIZE);
     946                } while (cSectors < (cbRead / VHD_SECTOR_SIZE));
     947
     948                cbRead = cSectors * VHD_SECTOR_SIZE;
    952949
    953950                Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
     
    977974
    978975                    iBATEntryIndexCurr++;
    979                 } while (cSectors < cSectorsToRead);
    980 
    981                 cbRead = RT_MIN(cbRead, cSectors * VHD_SECTOR_SIZE);
     976                } while (cSectors < (cbRead / VHD_SECTOR_SIZE));
     977
     978                cbRead = cSectors * VHD_SECTOR_SIZE;
    982979                Log(("%s: Sectors free: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead));
    983980                rc = VERR_VDI_BLOCK_FREE;
     
    10101007             __FUNCTION__, pBackendData, uOffset, pvBuf, cbWrite, pcbPreRead, pcbPostRead, fWrite));
    10111008
     1009    Assert(uOffset % 512 == 0);
     1010    Assert(cbWrite % 512 == 0);
     1011
    10121012    if (pImage->pBlockAllocationTable)
    10131013    {
     
    10151015         * Get the data block first.
    10161016         */
    1017         uint64_t uOffsetSectorAligned       = uOffset & ~0x1ff;
    1018         uint32_t cbOffsetDifference         = uOffset - uOffsetSectorAligned;
    1019         uint32_t cSector                    = uOffsetSectorAligned / VHD_SECTOR_SIZE;
    1020         uint32_t cSectorsToWrite            = (cbWrite / VHD_SECTOR_SIZE) + (cbOffsetDifference ? 1 : 0);
     1017        uint32_t cSector = uOffset / 512;
    10211018        uint32_t cBlockAllocationTableEntry = cSector / pImage->cSectorsPerDataBlock;
    1022         uint32_t cBATEntryIndex             = cSector % pImage->cSectorsPerDataBlock;
     1019        uint32_t cBATEntryIndex = cSector % pImage->cSectorsPerDataBlock;
    10231020        uint64_t uVhdOffset;
    10241021
     
    10431040             * Set the new end of the file and link the new block into the BAT.
    10441041             */
    1045             pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / VHD_SECTOR_SIZE;
     1042            pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / 512;
    10461043            pImage->uCurrentEndOfFile += cbNewBlock;
    10471044            RTMemFree(pNewBlock);
     
    10511048         * Calculate the real offset in the file.
    10521049         */
    1053         uVhdOffset = (((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * VHD_SECTOR_SIZE) + cbOffsetDifference;
     1050        uVhdOffset = ((uint64_t)pImage->pBlockAllocationTable[cBlockAllocationTableEntry] + pImage->cDataBlockBitmapSectors + cBATEntryIndex) * 512;
    10541051
    10551052        /*
    10561053         * Clip write range.
    10571054         */
    1058         cbWrite = RT_MIN(cbWrite, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE) - cbOffsetDifference));
     1055        cbWrite = RT_MIN(cbWrite, (pImage->cbDataBlock - (cBATEntryIndex * 512)));
    10591056        RTFileWriteAt(pImage->File, uVhdOffset, pvBuf, cbWrite, NULL);
    10601057
     
    10661063        {
    10671064            /* Set the bits for all sectors having been written. */
    1068             for (uint32_t iSector = 0; iSector < cSectorsToWrite; iSector++)
     1065            for (uint32_t iSector = 0; iSector < (cbWrite / VHD_SECTOR_SIZE); iSector++)
    10691066            {
    10701067                uint32_t iBitmap    = cBATEntryIndex / 8; /* Byte in the block bitmap. */
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