VirtualBox

Changeset 21006 in vbox


Ignore:
Timestamp:
Jun 28, 2009 7:07:20 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49220
Message:

VHD:

  • Fix calculation of block bitmap bit to test or set

Explanation: The code to avoid unaligned accesses for bt calculates the wrong bit to test.

If sector 0 in the block bitmap should be tested we have to test bit 7 in the first
byte the pointer of the data block bitmap points to.
The current code however would test the 31th bit which is wrong.
It would be correct to add the skipped bytes as number of bits to the bit position
like iBitInByte = ((8-1) - (cBlockBitmapEntry % 8)) + ((cBlockBitmapEntry / 8) & 3)*8
to ensure aligned access but I doubt that the additional instructions outweigh the
the slower memory access. So we restore the old behavior here and accept unaligned accesses.

  • On 64bit Windows systems we have to add 8 bytes instead of 4 because BT might read 8 bytes from the memory operand

Many thanks to Huihong Luo for pointing that out!

File:
1 edited

Legend:

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

    r20797 r21006  
    223223
    224224/**
    225  * Internal: Allocates the block bitmap rounding up to the next 32bit boundary.
     225 * Internal: Allocates the block bitmap rounding up to the next 32bit or 64bit boundary.
    226226 *           Can be freed with RTMemFree. The memory is zeroed.
    227227 */
    228228DECLINLINE(uint8_t *)vhdBlockBitmapAllocate(PVHDIMAGE pImage)
    229229{
    230     return (uint8_t *)RTMemAllocZ(RT_ALIGN_T(pImage->cbDataBlockBitmap, 4, uint32_t));
     230#ifdef RT_ARCH_AMD64
     231    return (uint8_t *)RTMemAllocZ(RT_ALIGN_64(pImage->cbDataBlockBitmap, 8));
     232#else
     233    return (uint8_t *)RTMemAllocZ(RT_ALIGN_32(pImage->cbDataBlockBitmap, 4));
     234#endif
    231235}
    232236
     
    917921     * The most signifcant bit stands for a lower sector number.
    918922     */
    919     uint8_t  iBitInByte = (32-1) - (cBlockBitmapEntry % 32);
     923    uint8_t  iBitInByte = (8-1) - (cBlockBitmapEntry % 8);
    920924    uint8_t *puBitmap = pImage->pu8Bitmap + iBitmap;
    921925
     
    937941     * The most signifcant bit stands for a lower sector number.
    938942     */
    939     uint8_t  iBitInByte = (32-1) - (cBlockBitmapEntry % 32);
     943    uint8_t  iBitInByte = (8-1) - (cBlockBitmapEntry % 8);
    940944    uint8_t  *puBitmap  = pImage->pu8Bitmap + iBitmap;
    941945
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