public IB Reserve(AllocationInfo allocationInfo) { amapRegionUpdater.Update( allocationInfo.MapOffset, map => { var bits = map.Data.Value.ToBits(); for (var i = allocationInfo.BitStartIndex; i <= allocationInfo.BitEndIndex; i++) { bits[i] = 1; } var bytes = bits.ToBytes(); return (new AMap( BinaryData.OfValue(bytes), new PageTrailer( Constants.ptypeAMap, Constants.ptypeAMap, 0x0000, Crc32.ComputeCrc32(bytes), BID.OfValue(allocationInfo.MapOffset)))); }); var allocateSize = (allocationInfo.BitEndIndex - allocationInfo.BitStartIndex + 1) * 64; headerUsageProvider.Use(header => header.SetRoot(header.Root.SetFreeSpaceInAllAMaps(header.Root.AMapFree - allocateSize))); return(IB.OfValue(allocationInfo.MapOffset + allocationInfo.BitStartIndex * 64)); }
public NID Allocate(int type) { NID nid = NID.Zero; headerUsageProvider.Use( header => { nid = header.NIDs[type]; return(header.IncrementNIDForType(type)); }); return(nid); }
public IB ExtendSingle() { var extensionOffset = IB.OfValue(dataStream.Length); var numberOfAMapsSoFar = Convert.ToInt32(extensionOffset.Subtract(OffsetOfFirstAMap) / AMapExtensionSize); var numberOfPMapsSoFar = Convert.ToInt32(extensionOffset.Add(0x512).Subtract(OffsetOfFirstPMap) / PMapExtensionSize); var createPMap = extensionOffset.Add(0x512).Subtract(OffsetOfFirstPMap) % PMapExtensionSize == 0; var createFMap = numberOfAMapsSoFar == 127 || numberOfAMapsSoFar == 495; var createFPMap = numberOfPMapsSoFar == 127 * 8 || numberOfPMapsSoFar == 495 * 8; var amap = CreateAMap(extensionOffset, createPMap, createFMap, createFPMap); var dataGenerator = BinaryDataGenerator.New(); dataGenerator.Append(amap, amapEncoder); if (createPMap) { dataGenerator.Append(CreatePMap(extensionOffset + 0x200), pmapEncoder); } if (createFMap) { dataGenerator.Append(CreateFMap(extensionOffset + 0x400), fmapEncoder); } if (createFPMap) { dataGenerator.Append(CreateFPMap(extensionOffset + 0x600), fpmapEncoder); } dataGenerator.FillTo(AMapExtensionSize); dataGenerator.WriteTo(dataStream); headerUsageProvider.Use( header => header .SetRoot( header .Root .SetFileEOF(extensionOffset + AMapExtensionSize) .SetLastAMapOffset(extensionOffset) .SetFreeSpaceInAllAMaps(header.Root.AMapFree + AMapExtensionSize - GetDefaultAllocationsSize(createPMap, createFMap, createFPMap)))); return(extensionOffset); }
public BID Allocate(IB blockOffset, int rawDataSize, bool internalBlock) { var bidIndex = headerUsageProvider.GetHeader().NextBID; headerUsageProvider.Use(header => header.IncrementBIDIndexForDataBlocks()); var blockId = internalBlock ? BID.ForInternalBlock(bidIndex) : BID.ForExternalBlock(bidIndex); allocatedBlockBTreeEntries.Add( new LBBTEntry( BREF.OfValue(blockId, blockOffset), rawDataSize, numberOfReferencesToThisBlock: 2, padding: BinaryData.OfSize(4))); return(blockId); }