예제 #1
0
 public List <Base> GetRoot()
 {
     byte[] xData;
     if (FatType == FatTypeEnum.Fat32)
     {
         xData = NewClusterArray();
         ReadCluster(RootCluster, xData);
     }
     else
     {
         xData = mDevice.NewBlockArray(RootSectorCount);
         mDevice.ReadBlock(RootSector, RootSectorCount, xData);
         // todo: is this correct??
     }
     return(ReadDirectoryContents(xData));
 }
예제 #2
0
        /// <summary>
        /// Deletes a partition
        /// </summary>
        /// <param name="index">Partition index starting from 0</param>
        public void DeletePartition(int index)
        {
            if (GPT.IsGPTPartition(Host))
            {
                throw new Exception("Deleting partitions with GPT style not yet supported!");
            }
            var location = 446 + 16 * index;

            byte[] mbr = Host.NewBlockArray(1);
            Host.ReadBlock(0, 1, ref mbr);
            for (int i = location; i < location + 16; i++)
            {
                mbr[i] = 0;
            }
            Host.WriteBlock(0, 1, ref mbr);
        }
예제 #3
0
        public FatFileSystem(BlockDevice aDevice)
        {
            mDevice = aDevice;
            byte[] xBPB = mDevice.NewBlockArray(1);

            mDevice.ReadBlock(0UL, 1U, xBPB);

            UInt16 xSig = xBPB.ToUInt16(510);

            if (xSig != 0xAA55)
            {
                throw new Exception("FAT signature not found.");
            }

            BytesPerSector      = xBPB.ToUInt16(11);
            SectorsPerCluster   = xBPB[13];
            BytesPerCluster     = BytesPerSector * SectorsPerCluster;
            ReservedSectorCount = xBPB.ToUInt16(14);
            NumberOfFATs        = xBPB[16];
            RootEntryCount      = xBPB.ToUInt16(17);

            TotalSectorCount = xBPB.ToUInt16(19);
            if (TotalSectorCount == 0)
            {
                TotalSectorCount = xBPB.ToUInt32(32);
            }

            // FATSz
            FatSectorCount = xBPB.ToUInt16(22);
            if (FatSectorCount == 0)
            {
                FatSectorCount = xBPB.ToUInt32(36);
            }
            //Global.Dbg.Send("FAT Sector Count: " + FatSectorCount);

            DataSectorCount = TotalSectorCount - (ReservedSectorCount + (NumberOfFATs * FatSectorCount) + ReservedSectorCount);

            // Computation rounds down.
            ClusterCount = DataSectorCount / SectorsPerCluster;
            // Determine the FAT type. Do not use another method - this IS the official and
            // proper way to determine FAT type.
            // Comparisons are purposefully < and not <=
            // FAT16 starts at 4085, FAT32 starts at 65525
            if (ClusterCount < 4085)
            {
                FatType = FatTypeEnum.Fat12;
            }
            else if (ClusterCount < 65525)
            {
                FatType = FatTypeEnum.Fat16;
            }
            else
            {
                FatType = FatTypeEnum.Fat32;
            }

            if (FatType == FatTypeEnum.Fat32)
            {
                RootCluster = xBPB.ToUInt32(44);
            }
            else
            {
                RootSector      = ReservedSectorCount + (NumberOfFATs * FatSectorCount);
                RootSectorCount = (RootEntryCount * 32 + (BytesPerSector - 1)) / BytesPerSector;
            }
            DataSector = ReservedSectorCount + (NumberOfFATs * FatSectorCount) + RootSectorCount;
        }
 /// <summary>
 /// Gets a new Byte array formatted with number of elements equal to [num * blockSize]
 /// </summary>
 /// <param name="num">Number of blocks</param>
 public Byte[] NewBlockArray(uint num)
 {
     return(blockDevice.NewBlockArray(num));
 }