/// <param name="clusterNumber">The cluster number to check.</param>
/// <returns>True if the cluster is allocated (in use, not free, not bad); otherwise, false.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if cluster number is out of range.</exception>
publicboolIsClusterAllocated(uintclusterNumber)
{
if(clusterNumber>=m_totalClusters)
thrownewArgumentOutOfRangeException(nameof(clusterNumber),$"Cluster number {clusterNumber} is out of range. Valid range is 0 to {m_totalClusters - 1}.");
returnm_allocationBitmap[(int)clusterNumber];
}
/// <summary>
/// Gets the next cluster in a cluster chain.
/// </summary>
/// <param name="clusterNumber">The current cluster number.</param>
/// <returns>The next cluster number in the chain, or the end-of-chain marker if this is the last cluster.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if cluster number is out of range.</exception>
publicuintGetNextCluster(uintclusterNumber)
{
if(clusterNumber>=m_totalClusters)
thrownewArgumentOutOfRangeException(nameof(clusterNumber),$"Cluster number {clusterNumber} is out of range. Valid range is 0 to {m_totalClusters - 1}.");
varentry=GetFatEntry(clusterNumber);
// Return the masked entry value (only lower 28 bits are valid)
returnentry&ENTRY_MASK;
}
/// <summary>
/// Gets the full cluster chain starting from the specified cluster.
/// <returns>A list of cluster numbers in the chain, including the start cluster.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if start cluster is out of range.</exception>
/// <exception cref="InvalidOperationException">Thrown if a circular chain is detected.</exception>
publicList<uint>GetClusterChain(uintstartCluster)
{
if(startCluster>=m_totalClusters)
thrownewArgumentOutOfRangeException(nameof(startCluster),$"Cluster number {startCluster} is out of range. Valid range is 0 to {m_totalClusters - 1}.");
varchain=newList<uint>();
varvisited=newHashSet<uint>();
varcurrentCluster=startCluster;
while(true)
{
// Check for circular chain
if(!visited.Add(currentCluster))
thrownewInvalidOperationException($"Circular cluster chain detected at cluster {currentCluster}.");
chain.Add(currentCluster);
varnextCluster=GetNextCluster(currentCluster);
// Check for end of chain
if(IsEndOfChain(nextCluster))
break;
// Check for bad or free cluster in the middle of a chain