Exemplo n.º 1
0
        /// <summary>
        /// Reads the cluster numbers in a cluster chain starting at the specified cluster number.
        /// </summary>
        /// <param name="fileSize">The size of file being read (used only for estimating number of clusters). Must be non-zero.</param>
        /// <param name="FirstClusterNum">The first cluster number in the chain.</param>
        /// <returns>The list of cluster numbers in the chain.</returns>
        public UInt32List ReadClusterChain(UInt64 fileSize, UInt32 FirstClusterNum)
        {
            //The capacity calculation is designed to make the internal array of the list exactly
            //  the correct size (or one bigger) for the number of cluster numbers in the chain.
            UInt32List Result = new UInt32List((int)((UInt32)fileSize / (SectorsPerCluster * BytesPerSector)) + 1);

            //Preallocated array for a sector of data. Used to store table data
            byte[] SectorBuffer = new byte[BytesPerSector];
            //The sector number of the sector which contains the cluster chain information
            //  for the current cluster number
            UInt64 SectorNum = 0;
            //Whether the current sector has been loaded or not. This allows us to load a given sector
            //  the minimum number of times. If the cluster chain stays all within one sector, then 
            //  there's no need to keep reloading the sector.
            bool SectorLoaded = false;
            //The current cluster number in the chain
            UInt32 ClusterNum = FirstClusterNum;

            //The sector number and offset for the next entry in the cluster chain
            UInt64 NextSectorNum;
            UInt32 NextSectorOffset;

            //We need to do this at least once to read in the value for the starting cluster number
            do
            {
                //Get the sector number and offset for the current cluster num in the table.
                NextSectorNum = GetFATTableSectorPosition_SectorNum(ClusterNum);
                NextSectorOffset = GetFATTableSectorPosition_Offset(ClusterNum);

                //Load the sector if it hasn't already been loaded
                if (SectorLoaded == false || SectorNum != NextSectorNum)
                {
                    ReadFATSector(NextSectorNum, SectorBuffer);
                    SectorNum = NextSectorNum;
                    SectorLoaded = true;
                }

                //Add the current cluster number
                Result.Add(ClusterNum);

                //Read the entry in the table for the current cluster number
                ClusterNum = ReadFATEntry(SectorBuffer, ClusterNum, NextSectorOffset);
            }
            //Keep looping reading the chain until we reach the end of the file.
            while (!FATEntryIndicatesEOF(ClusterNum));

            return Result;
        }
Exemplo n.º 2
0
 public UInt32Dictionary(int capacity = 5)
 {
     Keys   = new UInt32List(capacity);
     Values = new UInt32List(capacity);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the list of cluster numbers that are part of the file being read/written from/to.
 /// </summary>
 private void GetClusterNums()
 {
     //Cluster number of 0 is invalid! Minimum is 2. Therefore, we can use
     //  the cluster number to determine whether this stream is to a valid
     //  / non-empty file or not.
     if (TheFATFile.FirstClusterNum > 0 || IgnoreFileSize)
     {
         //BasicConsole.WriteLine("Reading cluster chain...");
         ClusterNums = TheFATFileSystem.ReadClusterChain(TheFile.Size, TheFATFile.FirstClusterNum);
         //BasicConsole.WriteLine("Read cluster chain.");
     }
 }
Exemplo n.º 4
0
 public UInt32Stack(int capacity)
 {
     internalList = new UInt32List(capacity);
 }
Exemplo n.º 5
0
 public UInt32Stack(int capacity)
 {
     internalList = new UInt32List(capacity);
 }
Exemplo n.º 6
0
 public UInt32Dictionary(int capacity = 5)
 {
     Keys = new UInt32List(capacity);
     Values = new UInt32List(capacity);
 }