Changeset 13571 in vbox
- Timestamp:
- Oct 26, 2008 10:02:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp
r13568 r13571 879 879 * Get the data block first. 880 880 */ 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; 886 883 uint64_t uVhdOffset; 887 884 … … 899 896 } 900 897 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; 902 899 Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead)); 903 900 … … 905 902 * Clip read range to remain in this data block. 906 903 */ 907 cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE) - cbOffsetDifference));904 cbRead = RT_MIN(cbRead, (pImage->cbDataBlock - (cBATEntryIndex * 512))); 908 905 909 906 /* Read in the block's bitmap. */ … … 947 944 948 945 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; 952 949 953 950 Log(("%s: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead)); … … 977 974 978 975 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; 982 979 Log(("%s: Sectors free: uVhdOffset=%llu cbRead=%u\n", __FUNCTION__, uVhdOffset, cbRead)); 983 980 rc = VERR_VDI_BLOCK_FREE; … … 1010 1007 __FUNCTION__, pBackendData, uOffset, pvBuf, cbWrite, pcbPreRead, pcbPostRead, fWrite)); 1011 1008 1009 Assert(uOffset % 512 == 0); 1010 Assert(cbWrite % 512 == 0); 1011 1012 1012 if (pImage->pBlockAllocationTable) 1013 1013 { … … 1015 1015 * Get the data block first. 1016 1016 */ 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; 1021 1018 uint32_t cBlockAllocationTableEntry = cSector / pImage->cSectorsPerDataBlock; 1022 uint32_t cBATEntryIndex 1019 uint32_t cBATEntryIndex = cSector % pImage->cSectorsPerDataBlock; 1023 1020 uint64_t uVhdOffset; 1024 1021 … … 1043 1040 * Set the new end of the file and link the new block into the BAT. 1044 1041 */ 1045 pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / VHD_SECTOR_SIZE;1042 pImage->pBlockAllocationTable[cBlockAllocationTableEntry] = pImage->uCurrentEndOfFile / 512; 1046 1043 pImage->uCurrentEndOfFile += cbNewBlock; 1047 1044 RTMemFree(pNewBlock); … … 1051 1048 * Calculate the real offset in the file. 1052 1049 */ 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; 1054 1051 1055 1052 /* 1056 1053 * Clip write range. 1057 1054 */ 1058 cbWrite = RT_MIN(cbWrite, (pImage->cbDataBlock - (cBATEntryIndex * VHD_SECTOR_SIZE) - cbOffsetDifference));1055 cbWrite = RT_MIN(cbWrite, (pImage->cbDataBlock - (cBATEntryIndex * 512))); 1059 1056 RTFileWriteAt(pImage->File, uVhdOffset, pvBuf, cbWrite, NULL); 1060 1057 … … 1066 1063 { 1067 1064 /* 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++) 1069 1066 { 1070 1067 uint32_t iBitmap = cBATEntryIndex / 8; /* Byte in the block bitmap. */
Note:
See TracChangeset
for help on using the changeset viewer.