numOfBlocksLeft = cntBlocks.length;
}
else
{
//Get the last segment
BlockId idOfLastFreeBlock = cnt.findLastFreeBlock();
DataSegment lastSegOfCnt = cnt.getSegment(idOfLastFreeBlock.getSegmentId());
int freeInLastSeg = SEGSIZE - idOfLastFreeBlock.getId();
for (int i=idOfLastFreeBlock.getContainerId(); i < SEGSIZE; i++)
{
BlockId currFullBlockId = new BlockId(cntId, lastSegOfCnt.getId(), i);
blockIds.add(currFullBlockId);
cntBlocks[i].setId(currFullBlockId);
}
numOfBlocksLeft = cntBlocks.length - freeInLastSeg;
}
//Reserve somme Id-s for the blocks
int currBlockId = 0;
DataSegment currSeg = null;
int startIdx = (cntBlocks.length - numOfBlocksLeft);
for (int i = startIdx ; i < cntBlocks.length; i++)
{
if (i == startIdx || i % SEGSIZE == 0)
{
//Extend
currBlockId = 0;
currSeg = cnt.extend();
currSeg.open();
}
BlockId currFullBlockId = new BlockId(cntId, currSeg.getId(), currBlockId);
blockIds.add(currFullBlockId);
cntBlocks[i].setId(currFullBlockId);
currBlockId++;
}