}
private boolean fixBlocks( int blockCount , int blockSize , int firstBlock , byte[] flags , int[] allocatedSize , int[] previousBlock , int[] nextBlock )
{
boolean changed = false;
FastBitSet fixedBlocks = new FastBitSet(blockCount);
// Fix reverse links first
int previous = -1;
int current = firstBlock;
while (current != -1)
{
if (previousBlock[current] != previous)
{
log.debug("Fixing previous reference "+previousBlock[current]+" -> "+previous);
previousBlock[current] = previous;
changed = true;
}
fixedBlocks.set(current);
previous = current;
current = nextBlock[current];
}
// Look for lost blocks and fix allocated sizes
for (int n = 0 ; n < blockCount ; n++)
{
if (allocatedSize[n] != -1 && !fixedBlocks.get(n))
{
log.warn("Lost block found : "+n);
allocatedSize[n] = -1;
changed = true;
}
if (fixedBlocks.get(n) && (allocatedSize[n] <= 0 || allocatedSize[n]>blockSize))
{
log.warn("Block has an invalid size ("+allocatedSize[n]+"), replacing by "+blockSize);
allocatedSize[n] = blockSize;
changed = true;
}