protected uint AllocateCluster()
{
uint at = lastFreeHint + 1;
if (at < 2)
at = 2;
uint last = at - 1;
if (last == 1)
last = fatEntries;
while (at != last)
{
uint value = GetClusterEntryValue(at);
if (IsClusterFree(value))
{
SetClusterEntryValue(at, 0xFFFFFFFF /*endOfClusterMark*/);
lastFreeHint = at;
return at;
}
at++;
if (at >= fatEntries)
at = 2;
}
return 0; // mean no free space
}