コード例 #1
0
        private static void InitAta(BlockDevice.Ata.ControllerIdEnum aControllerID,
                                    BlockDevice.Ata.BusPositionEnum aBusPosition)
        {
            var xIO = aControllerID == BlockDevice.Ata.ControllerIdEnum.Primary
                ? Cosmos.Core.Global.BaseIOGroups.ATA1
                : Cosmos.Core.Global.BaseIOGroups.ATA2;
            var xATA = new BlockDevice.AtaPio(xIO, aControllerID, aBusPosition);

            if (xATA.DriveType == BlockDevice.AtaPio.SpecLevel.Null)
            {
                return;
            }
            if (xATA.DriveType == BlockDevice.AtaPio.SpecLevel.ATA)
            {
                BlockDevice.BlockDevice.Devices.Add(xATA);
                Ata.AtaDebugger.Send("ATA device with speclevel ATA found.");
            }
            else
            {
                Ata.AtaDebugger.Send("ATA device with spec level " + (int)xATA.DriveType +
                                     " found, which is not supported!");
                return;
            }
            var xMbrData = new byte[512];

            xATA.ReadBlock(0UL, 1U, xMbrData);
            var xMBR = new BlockDevice.MBR(xMbrData);

            if (xMBR.EBRLocation != 0)
            {
                //EBR Detected
                var xEbrData = new byte[512];
                xATA.ReadBlock(xMBR.EBRLocation, 1U, xEbrData);
                var xEBR = new BlockDevice.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);
                    //BlockDevice.BlockDevice.Devices.Add(xPartDevice);
                }
            }

            // TODO Change this to foreach when foreach is supported
            Ata.AtaDebugger.Send("Number of MBR partitions found:  " + xMBR.Partitions.Count);
            for (int i = 0; i < xMBR.Partitions.Count; i++)
            {
                var xPart = xMBR.Partitions[i];
                if (xPart == null)
                {
                    Console.WriteLine("Null partition found at idx " + i);
                }
                else
                {
                    var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
                    BlockDevice.BlockDevice.Devices.Add(xPartDevice);
                    Console.WriteLine("Found partition at idx " + i);
                }
            }
        }
コード例 #2
0
ファイル: Global.cs プロジェクト: fanoI/Cosmos
    private static void InitAta(Ata.ControllerIdEnum aControllerID,
        Ata.BusPositionEnum aBusPosition)
    {
      var xIO = aControllerID == Ata.ControllerIdEnum.Primary
          ? Core.Global.BaseIOGroups.ATA1
          : Core.Global.BaseIOGroups.ATA2;
      var xATA = new AtaPio(xIO, aControllerID, aBusPosition);
      if (xATA.DriveType == AtaPio.SpecLevel.Null)
      {
        return;
      }
      if (xATA.DriveType == AtaPio.SpecLevel.ATA)
      {
        BlockDevice.BlockDevice.Devices.Add(xATA);
        Ata.AtaDebugger.Send("ATA device with speclevel ATA found.");
      }
      else
      {
        //Ata.AtaDebugger.Send("ATA device with spec level " + (int)xATA.DriveType +
        //                     " found, which is not supported!");
        return;
      }
      var xMbrData = new byte[512];
      xATA.ReadBlock(0UL, 1U, xMbrData);
      var xMBR = new MBR(xMbrData);

      if (xMBR.EBRLocation != 0)
      {
        //EBR Detected
        var xEbrData = new byte[512];
        xATA.ReadBlock(xMBR.EBRLocation, 1U, 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);
          //BlockDevice.BlockDevice.Devices.Add(xPartDevice);
        }
      }

      // TODO Change this to foreach when foreach is supported
      Ata.AtaDebugger.Send("Number of MBR partitions found:");
      Ata.AtaDebugger.SendNumber(xMBR.Partitions.Count);
      for (int i = 0; i < xMBR.Partitions.Count; i++)
      {
        var xPart = xMBR.Partitions[i];
        if (xPart == null)
        {
          Console.WriteLine("Null partition found at idx: " + i);
        }
        else
        {
          var xPartDevice = new Partition(xATA, xPart.StartSector, xPart.SectorCount);
          BlockDevice.BlockDevice.Devices.Add(xPartDevice);
          Console.WriteLine("Found partition at idx" + i);
        }
      }
    }
コード例 #3
0
ファイル: FileSystem.cs プロジェクト: nstone101/Cosmos
        // Currently we map to the Windows scheme of single lettter: for drives. Cosmos will
        // NOT do this in the future, but it will be able to map paths to things that look like
        // drive letters for compatibility with Windows code.
        // For now we use Dictionary for simplicity, but in future this will change.
        //static protected Dictionary<string, FileSystem> mMappings = new Dictionary<string, FileSystem>();

        //static protected FileSystem mFS;

        //static public void AddMapping(string aPath, FileSystem aFileSystem)
        //{
        //    //mMappings.Add(aPath.ToUpper(), aFileSystem);
        //    // Dictionary<> doesnt work yet, so for now we just hack this and support only one FS
        //    mFS = aFileSystem;
        //}

        public static FileSystemType GetFileSystemType(Partition aDevice)
        {
            if (FAT.FatFileSystem.IsDeviceFAT(aDevice))
            {
                return FileSystemType.FAT;
            }

            return FileSystemType.Unknown;
        }
コード例 #4
0
ファイル: FatFileSystem.cs プロジェクト: bjuriewicz/Cosmos
        public static bool IsDeviceFat(Partition aDevice)
        {
            if (aDevice == null)
            {
                throw new ArgumentNullException(nameof(aDevice));
            }

            var xBPB = aDevice.NewBlockArray(1);
            aDevice.ReadBlock(0UL, 1U, xBPB);
            ushort xSig = xBPB.ToUInt16(510);
            if (xSig != 0xAA55)
            {
                return false;
            }
            return true;
        }
コード例 #5
0
ファイル: FatFileSystem.cs プロジェクト: bjuriewicz/Cosmos
        /// <summary>
        /// Initializes a new instance of the <see cref="FatFileSystem"/> class.
        /// </summary>
        /// <param name="aDevice">The partition.</param>
        /// <param name="aRootPath">The root path.</param>
        /// <exception cref="Exception">FAT signature not found.</exception>
        public FatFileSystem(Partition aDevice, string aRootPath)
            : base(aDevice, aRootPath)
        {
            if (aDevice == null)
            {
                throw new ArgumentNullException(nameof(aDevice));
            }

            if (string.IsNullOrEmpty(aRootPath))
            {
                throw new ArgumentException("Argument is null or empty", nameof(aRootPath));
            }

            var xBPB = mDevice.NewBlockArray(1);

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

            ushort 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);
            }

            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)
            {
                mFatType = FatTypeEnum.Fat12;
            }
            else if (ClusterCount < 65525)
            {
                mFatType = FatTypeEnum.Fat16;
            }
            else
            {
                mFatType = FatTypeEnum.Fat32;
            }

            if (mFatType == FatTypeEnum.Fat32)
            {
                RootCluster = xBPB.ToUInt32(44);
            }
            else
            {
                RootSector = ReservedSectorCount + NumberOfFATs * FatSectorCount;
                RootSectorCount = (RootEntryCount * 32 + (BytesPerSector - 1)) / BytesPerSector;
            }
            DataSector = ReservedSectorCount + NumberOfFATs * FatSectorCount + RootSectorCount;

            mFats = new Fat[NumberOfFATs];
            for (ulong i = 0; i < NumberOfFATs; i++)
            {
                mFats[i] = new Fat(this, (ReservedSectorCount + i * FatSectorCount));
            }
        }
コード例 #6
0
ファイル: BreakpointsOS.cs プロジェクト: Orvid/Cosmos
    public void Format(Partition p)
    {
      byte[] aData = p.NewBlockArray(1);
      p.ReadBlock(0, 1U, aData);

      aData[510] = 0xAA;
      aData[511] = 0x55;

      //The number of Bytes per sector (remember, all numbers are in the little-endian format).
      aData[11] = 0x01;
      aData[12] = 0xCA;
      aData[13] = 0x08; //Number of sectors per cluster.
      aData[14] = 0x01;
      aData[15] = 0xFF; //Number of reserved sectors. The boot record sectors are included in this value
      aData[16] = 0x02; //Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2.
      aData[17] = 0x00;
      aData[18] = 0x0f; //Number of directory entries (must be set so that the root directory occupies entire sectors).
      aData[19] = 0xFF;
      aData[20] = 0xFF; //The total sectors in the logical volume. If this value is 0, it means there are more than 65535 sectors in the volume, and the actual count is stored in "Large Sectors (bytes 32-35).
      aData[22] = 0x0F;
      aData[23] = 0xFF; //Number of sectors per FAT. FAT12/FAT16 only.
      p.WriteBlock(0, 1U, aData);
    }
コード例 #7
0
ファイル: FatFileSystem.cs プロジェクト: nwiede/Cosmos
 public static bool IsDeviceFAT(Partition aDevice)
 {
     byte[] xBPB = aDevice.NewBlockArray(1);
     aDevice.ReadBlock(0UL, 1U, xBPB);
     UInt16 xSig = xBPB.ToUInt16(510);
     if (xSig != 0xAA55)
     {
         return false;
     }
     return true;
 }
コード例 #8
0
ファイル: FileSystem.cs プロジェクト: Orvid/Cosmos
 protected FileSystem(Partition aDevice, string aRootPath)
 {
     mDevice = aDevice;
     mRootPath = aRootPath;
 }
コード例 #9
0
ファイル: FatFileSystem.cs プロジェクト: sajadbanooie/Cosmos
        public FatFileSystem(Partition aDevice, string aRootPath)
            : base(aDevice, aRootPath)
        {
            byte[] xBPB = mDevice.NewBlockArray(1);

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

            ushort 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)
            {
                mFatType = FatTypeEnum.Fat12;
            }
            else if (ClusterCount < 65525)
            {
                mFatType = FatTypeEnum.Fat16;
            }
            else
            {
                mFatType = FatTypeEnum.Fat32;
            }

            if (mFatType == FatTypeEnum.Fat32)
            {
                RootCluster = xBPB.ToUInt32(44);
            }
            else
            {
                RootSector = ReservedSectorCount + (NumberOfFATs * FatSectorCount);
                RootSectorCount = (RootEntryCount * 32 + (BytesPerSector - 1)) / BytesPerSector;
            }
            DataSector = ReservedSectorCount + (NumberOfFATs * FatSectorCount) + RootSectorCount;
        }