Changeset 38657 in vbox for trunk/src/VBox/Storage/VDI.cpp
- Timestamp:
- Sep 6, 2011 2:06:56 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VDI.cpp
r38647 r38657 888 888 889 889 return rc; 890 } 891 892 /** 893 * Internal: Creates a allocation bitmap from the given data. 894 * Sectors which contain only 0 are marked as unallocated and sectors with 895 * other data as allocated. 896 * 897 * @returns Pointer to the allocation bitmap or NULL on failure. 898 * @param pvData The data to create the allocation bitmap for. 899 * @param cbData Number of bytes in the buffer. 900 */ 901 static void *vdiAllocationBitmapCreate(void *pvData, size_t cbData) 902 { 903 unsigned cSectors = cbData / 512; 904 unsigned uSectorCur = 0; 905 void *pbmAllocationBitmap = NULL; 906 907 Assert(!(cbData % 512)); 908 Assert(!(cSectors % 8)); 909 910 pbmAllocationBitmap = RTMemAllocZ(cSectors / 8); 911 912 while (uSectorCur < cSectors) 913 { 914 int idxSet = ASMBitFirstSet((uint8_t *)pvData + uSectorCur * 512, cbData * 8); 915 916 if (idxSet != -1) 917 { 918 unsigned idxSectorAlloc = idxSet / 8 / 512; 919 ASMBitSet(pbmAllocationBitmap, uSectorCur + idxSectorAlloc); 920 921 uSectorCur += idxSectorAlloc + 1; 922 cbData -= (idxSectorAlloc + 1) * 512; 923 } 924 else 925 break; 926 } 927 928 return pbmAllocationBitmap; 890 929 } 891 930 … … 2560 2599 Assert(!(cbDiscard % 512)); 2561 2600 2601 AssertMsgReturn(!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY), 2602 ("Image is readonly\n"), VERR_VD_IMAGE_READ_ONLY); 2603 AssertMsgReturn( uOffset + cbDiscard <= getImageDiskSize(&pImage->Header) 2604 && cbDiscard, 2605 ("Invalid parameters uOffset=%llu cbDiscard=%zu\n", 2606 uOffset, cbDiscard), 2607 VERR_INVALID_PARAMETER); 2608 2562 2609 do 2563 2610 { … … 2669 2716 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, cbImage - pImage->cbTotalBlockData); 2670 2717 } 2671 else /* if (fDiscard & VD_DISCARD_MARK_UNUSED) */2718 else if (fDiscard & VD_DISCARD_MARK_UNUSED) 2672 2719 { 2673 2720 /* Write changed data to the image. */ … … 2675 2722 pbBlockData + offDiscard, cbDiscard, NULL); 2676 2723 } 2677 #if 02678 2724 else 2679 2725 { … … 2681 2727 *pcbPreAllocated = cbPreAllocated; 2682 2728 *pcbPostAllocated = cbPostAllocated; 2683 *ppbmAllocationBitmap = vd AllocationBitmapCreate(pvBlock, getImageBlockSize(&pImage->Header));2729 *ppbmAllocationBitmap = vdiAllocationBitmapCreate(pbBlockData, getImageBlockSize(&pImage->Header)); 2684 2730 if (RT_UNLIKELY(!*ppbmAllocationBitmap)) 2685 2731 rc = VERR_NO_MEMORY; … … 2687 2733 rc = VERR_VD_DISCARD_ALIGNMENT_NOT_MET; 2688 2734 } 2689 #endif2690 2735 } 2691 2736 /* else: nothing to do. */
Note:
See TracChangeset
for help on using the changeset viewer.