Beispiel #1
0
        public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, byte[] aData)
        {
            UInt64 xHostBlockNo = mStartingSector + aBlockNo;

            CheckBlockNo(xHostBlockNo, aBlockCount);
            mHost.ReadBlock(xHostBlockNo, aBlockCount, aData);
        }
Beispiel #2
0
        /// <summary>
        /// Read block from partition.
        /// </summary>
        /// <param name="aBlockNo">A block to read from.</param>
        /// <param name="aBlockCount">A number of blocks in the partition.</param>
        /// <param name="aData">A data that been read.</param>
        /// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
        /// <exception cref="Exception">Thrown when data size invalid.</exception>
        public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData)
        {
            CheckDataSize(aData, aBlockCount);
            UInt64 xHostBlockNo = mStartingSector + aBlockNo;

            CheckBlockNo(xHostBlockNo, aBlockCount);
            mHost.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
        }
Beispiel #3
0
        public static bool IsGPTPartition(BlockDevice aBlockDevice)
        {
            byte[] GPTHeader = new byte[512];
            aBlockDevice.ReadBlock(1, 1, ref GPTHeader);

            ulong signature = BitConverter.ToUInt64(GPTHeader, 0);

            return(signature == EFIParitionSignature);
        }
Beispiel #4
0
        public MBR(BlockDevice device)
        {
            var aMBR = device.NewBlockArray(1);

            device.ReadBlock(0, 1, ref aMBR);

            ParsePartition(aMBR, 446);
            ParsePartition(aMBR, 462);
            ParsePartition(aMBR, 478);
            ParsePartition(aMBR, 494);
        }
Beispiel #5
0
        /// <summary>
        /// Read block from partition.
        /// </summary>
        /// <param name="aBlockNo">A block to read from.</param>
        /// <param name="aBlockCount">A number of blocks in the partition.</param>
        /// <param name="aData">A data that been read.</param>
        /// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
        /// <exception cref="Exception">Thrown when data size invalid.</exception>
        public override void ReadBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData)
        {
            Global.mDebugger.SendInternal("-- Partition.ReadBlock --");
            Global.mDebugger.SendInternal($"aBlockNo = {aBlockNo}");
            Global.mDebugger.SendInternal($"aBlockCount = {aBlockCount}");
            CheckDataSize(aData, aBlockCount);
            ulong xHostBlockNo = StartingSector + aBlockNo;

            CheckBlockNo(xHostBlockNo, aBlockCount);
            Host.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
            Global.mDebugger.SendInternal("Returning -- Partition.ReadBlock --");
        }
Beispiel #6
0
        public GPT(BlockDevice aBlockDevice)
        {
            byte[] GPTHeader = new byte[512];
            aBlockDevice.ReadBlock(1, 1, ref GPTHeader);

            // Start of parition entries
            ulong partEntryStart = BitConverter.ToUInt64(GPTHeader, 72);
            uint  numParitions   = BitConverter.ToUInt32(GPTHeader, 80);
            uint  partSize       = BitConverter.ToUInt32(GPTHeader, 84);

            uint paritionsPerSector = 512 / partSize;

            for (ulong i = 0; i < numParitions / paritionsPerSector; i++)
            {
                byte[] partData = new byte[512];
                aBlockDevice.ReadBlock(partEntryStart + i, 1, ref partData);

                for (uint j = 0; j < paritionsPerSector; j++)
                {
                    ParseParition(partData, j * partSize);
                }
            }
        }
Beispiel #7
0
        internal static void ScanAndInitPartitions(BlockDevice device)
        {
            if (GPT.IsGPTPartition(device))
            {
                var xGPT = new GPT(device);

                Ata.AtaDebugger.Send("Number of GPT partitions found:");
                Ata.AtaDebugger.SendNumber(xGPT.Partitions.Count);
                int i = 0;
                foreach (var part in xGPT.Partitions)
                {
                    Partition.Partitions.Add(new Partition(device, part.StartSector, part.SectorCount));
                    i++;
                }
            }
            else
            {
                var mbr = new MBR(device);

                if (mbr.EBRLocation != 0)
                {
                    //EBR Detected
                    var xEbrData = new byte[512];
                    device.ReadBlock(mbr.EBRLocation, 1U, ref xEbrData);
                    var xEBR = new EBR(xEbrData);

                    for (int i = 0; i < xEBR.Partitions.Count; i++)
                    {
                        //var xPart = xEBR.Partitions[i];
                        //var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
                        //Partition.Partitions.Add(xATA, xPartDevice);
                    }
                }
                int c = 0;
                foreach (var part in mbr.Partitions)
                {
                    Partition.Partitions.Add(new Partition(device, part.StartSector, part.SectorCount));
                    c++;
                }
            }
        }
Beispiel #8
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;

        }
Beispiel #9
0
 public void ReadFatTableSector(UInt64 xSectorNum, byte[] aData)
 {
     mDevice.ReadBlock(ReservedSectorCount + xSectorNum, 1, aData);
 }
Beispiel #10
0
        public FatFileSystem(Cosmos.HAL.BlockDevice.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;

        }