internal IEnumerable<long> FindAllocatedAreasNotIn(List<long> usedAreas)
{
// Sort the list
var list = new List<long>(usedAreas);
list.Sort();
// The list of leaked areas
var leakedAreas = new List<long>();
int listIndex = 0;
// What area are we looking for?
long lookingFor = Int64.MaxValue;
if (listIndex < list.Count) {
lookingFor = list[listIndex];
++listIndex;
}
long endOfDataArea = DataAreaEndOffset;
long[] header = new long[2];
long offset = DataAreaOffset;
while (offset < endOfDataArea) {
ReadAreaHeader(offset, header);
long areaSize = (header[0] & ActiveFlag);
bool areaFree = (header[0] & DeletedFlag) != 0;
if (offset == lookingFor) {
if (areaFree)
throw new IOException("Area is not allocated!");
// Update the 'looking_for' offset
if (listIndex < list.Count) {
lookingFor = (long)list[listIndex];
++listIndex;
} else {
lookingFor = Int64.MaxValue;
}
} else if (offset > lookingFor) {
throw new IOException("IArea (offset = " + lookingFor + ") wasn't found input store!");
} else {
// An area that isn't input the list
if (!areaFree) {
// This is a leaked area.
// It isn't free and it isn't input the list
leakedAreas.Add(offset);
}
}
offset += areaSize;
}
return leakedAreas.ToArray();
}