/// <summary> /// This method should only be used for informational purposes. /// </summary> public KeyValuePairList <long, long> GetClustersInUse() { long clusterCount = HighestVCN - LowestVCN + 1; KeyValuePairList <long, long> sequence = m_dataRunSequence.TranslateToLCN(0, clusterCount); return(sequence); }
/// <param name="count">Maximum number of clusters to read</param> public byte[] ReadDataClusters(NTFSVolume volume, long firstClusterVCN, int count) { long lastClusterVcnToRead = firstClusterVCN + count - 1; if (firstClusterVCN < LowestVCN || firstClusterVCN > HighestVCN) { string message = String.Format("Cluster VCN {0}-{1} is not within the valid range ({2}-{3})", firstClusterVCN, lastClusterVcnToRead, LowestVCN, HighestVCN); throw new ArgumentOutOfRangeException(message); } if (lastClusterVcnToRead > HighestVCN) { lastClusterVcnToRead = HighestVCN; } byte[] result = new byte[count * volume.BytesPerCluster]; KeyValuePairList <long, int> sequence = m_dataRunSequence.TranslateToLCN(firstClusterVCN - LowestVCN, count); long bytesRead = 0; foreach (KeyValuePair <long, int> run in sequence) { byte[] clusters = volume.ReadClusters(run.Key, run.Value); Array.Copy(clusters, 0, result, bytesRead, clusters.Length); bytesRead += clusters.Length; } // If the last cluster is only partially used or we have been asked to read clusters beyond the last cluster, trim result. // (Either of those cases could only be true if we have just read the last cluster). if (lastClusterVcnToRead == (long)HighestVCN) { long bytesToUse = (long)(FileSize - (ulong)firstClusterVCN * (uint)volume.BytesPerCluster); if (bytesToUse < result.Length) { byte[] resultTrimmed = new byte[bytesToUse]; Array.Copy(result, resultTrimmed, bytesToUse); return(resultTrimmed); } } return(result); }