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) { BlockDevice.BlockDevice.Devices.Add(xATA); 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 Console.WriteLine("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); } } } }
public static void ReadMBR(AtaPio dev) { BinaryReader binaryReader = new BinaryReader(ATA.a); for (int i = 0; i < 4; i++) { binaryReader.BaseStream.Position = 446 + i * 16 + 8; uint num = binaryReader.ReadUInt32(); uint num2 = binaryReader.ReadUInt32(); if (num2 != 0u) { Partition dev2 = new Partition(dev, (ulong)num, (ulong)num2); Devices.device device = new Devices.device(); device.dev = dev2; device.name = "/dev/sd" + ATA.b.ToString() + (i + 1).ToString(); Devices.dev.Add(device); } } }
protected override void Run() { Cosmos.Core.IOGroup.ATA ataOne = Cosmos.Core.Global.BaseIOGroups.ATA1; var xATA = new Cosmos.Hardware.BlockDevice.AtaPio(ataOne, Cosmos.Hardware.BlockDevice.Ata.ControllerIdEnum.Primary, Cosmos.Hardware.BlockDevice.Ata.BusPositionEnum.Master); Console.WriteLine(Cosmos.Hardware.BlockDevice.BlockDevice.Devices == null ? "BlockDevice, Devices List is null" : "BlockDevice, Devices List isn't null"); for (int i = 0; i < Cosmos.Hardware.BlockDevice.BlockDevice.Devices.Count; i++) { var xDevice = Cosmos.Hardware.BlockDevice.BlockDevice.Devices[i]; if (xDevice is AtaPio) { xATA = (AtaPio)xDevice; } } Console.WriteLine(); Console.WriteLine("--------------------------"); Console.WriteLine("Type: " + (xATA.DriveType == AtaPio.SpecLevel.ATA ? "ATA" : "ATAPI")); Console.WriteLine("Serial No: " + xATA.SerialNo); Console.WriteLine("Firmware Rev: " + xATA.FirmwareRev); Console.WriteLine("Model No: " + xATA.ModelNo); Console.WriteLine("Block Size: " + xATA.BlockSize + " bytes"); Console.WriteLine("Size: " + xATA.BlockCount * xATA.BlockSize / 1024 / 1024 + " MB"); Partition xPartition = null; for (int i = 0; i < BlockDevice.Devices.Count; i++) { var xDevice = BlockDevice.Devices[i]; if (xDevice is Partition) { xPartition = (Partition)xDevice; } } if (xPartition != null) { Console.WriteLine(); Console.WriteLine("--------------------------"); Console.WriteLine("Partition found."); var xFS = new FatFileSystem(xPartition); Console.WriteLine(); Console.WriteLine("BytesPerSector : " + xFS.BytesPerSector.ToString()); Console.WriteLine("SectorsPerCluster : " + xFS.SectorsPerCluster.ToString()); Console.WriteLine("BytesPerCluster : " + xFS.BytesPerCluster.ToString()); Console.WriteLine("ReservedSectorCount : " + xFS.ReservedSectorCount.ToString()); Console.WriteLine("TotalSectorCount : " + xFS.TotalSectorCount.ToString()); Console.WriteLine("ClusterCount : " + xFS.ClusterCount.ToString()); Console.WriteLine("NumberOfFATs : " + xFS.NumberOfFATs.ToString()); Console.WriteLine("FatSectorCount : " + xFS.FatSectorCount.ToString()); Console.WriteLine("RootSector : " + xFS.RootSector.ToString()); Console.WriteLine("RootSectorCount : " + xFS.RootSectorCount.ToString()); Console.WriteLine("RootCluster : " + xFS.RootCluster.ToString()); Console.WriteLine("RootEntryCount : " + xFS.RootEntryCount.ToString()); Console.WriteLine("DataSector : " + xFS.DataSector.ToString()); Console.WriteLine("DataSectorCount : " + xFS.DataSectorCount.ToString()); } else { Console.WriteLine("Partition not found."); } Console.WriteLine(); Console.WriteLine("--------------------------"); Console.Write("Pausing... (Press enter to continue.)"); Console.ReadLine(); }