diff --git a/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs b/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs index da6128884f..7b258f3d65 100644 --- a/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs +++ b/source/Cosmos.HAL2/BlockDevice/BlockDevice.cs @@ -24,7 +24,7 @@ public abstract class BlockDevice : Device /// /// Number of blocks to alloc. /// byte array. - public byte[] NewBlockArray(uint aBlockCount) + public byte[] NewBlockArray(ulong aBlockCount) { return new byte[aBlockCount * mBlockSize]; } diff --git a/source/Cosmos.HAL2/BlockDevice/EBR.cs b/source/Cosmos.HAL2/BlockDevice/EBR.cs index 91e96ed7ba..cdf7744776 100644 --- a/source/Cosmos.HAL2/BlockDevice/EBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/EBR.cs @@ -13,10 +13,10 @@ public class EBR public class PartInfo { public readonly byte SystemID; - public readonly uint StartSector; - public readonly uint SectorCount; + public readonly ulong StartSector; + public readonly ulong SectorCount; - public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount) + public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount) { SystemID = aSystemID; StartSector = aStartSector; @@ -30,7 +30,7 @@ public EBR(byte[] aEBR) ParsePartition(aEBR, 462); } - protected void ParsePartition(byte[] aEBR, uint aLoc) + protected void ParsePartition(byte[] aEBR, int aLoc) //This should be int. ToUInt64(byte[] value, int)!! { byte xSystemID = aEBR[aLoc + 4]; // SystemID = 0 means no partition @@ -41,8 +41,8 @@ protected void ParsePartition(byte[] aEBR, uint aLoc) } else if (xSystemID != 0) { - uint xStartSector = BitConverter.ToUInt32(aEBR, (int)aLoc + 8); - uint xSectorCount = BitConverter.ToUInt32(aEBR, (int)aLoc + 12); + ulong xStartSector = BitConverter.ToUInt32(aEBR, aLoc + 8); + ulong xSectorCount = BitConverter.ToUInt32(aEBR, aLoc + 12); var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount); Partitions.Add(xPartInfo); diff --git a/source/Cosmos.HAL2/BlockDevice/GPT.cs b/source/Cosmos.HAL2/BlockDevice/GPT.cs index ba7aed04f2..fb9aae8040 100644 --- a/source/Cosmos.HAL2/BlockDevice/GPT.cs +++ b/source/Cosmos.HAL2/BlockDevice/GPT.cs @@ -36,12 +36,12 @@ public GPT(BlockDevice aBlockDevice) // Start of parition entries ulong partEntryStart = BitConverter.ToUInt64(GPTHeader, 72); - uint numParitions = BitConverter.ToUInt32(GPTHeader, 80); - uint partSize = BitConverter.ToUInt32(GPTHeader, 84); + ulong numParitions = BitConverter.ToUInt32(GPTHeader, 80); + ulong partSize = BitConverter.ToUInt32(GPTHeader, 84); - uint paritionsPerSector = 512 / partSize; + ulong paritionsPerSector = 512 / partSize; - for (ulong i = 0; i < numParitions/paritionsPerSector; i++) + for (ulong i = 0; i < numParitions / paritionsPerSector; i++) { byte[] partData = new byte[512]; @@ -49,12 +49,12 @@ public GPT(BlockDevice aBlockDevice) for (uint j = 0; j < paritionsPerSector; j++) { - ParseParition(partData, j * partSize); + ParseParition(partData, j * (long)partSize); } } } - private void ParseParition(byte[] partData, uint off) + private void ParseParition(byte[] partData, long off) { byte[] guidArray = new byte[16]; diff --git a/source/Cosmos.HAL2/BlockDevice/IDE.cs b/source/Cosmos.HAL2/BlockDevice/IDE.cs index 2552a6daed..e474a59492 100644 --- a/source/Cosmos.HAL2/BlockDevice/IDE.cs +++ b/source/Cosmos.HAL2/BlockDevice/IDE.cs @@ -117,4 +117,4 @@ internal static void ScanAndInitPartitions(BlockDevice device) } } } -} \ No newline at end of file +} diff --git a/source/Cosmos.HAL2/BlockDevice/MBR.cs b/source/Cosmos.HAL2/BlockDevice/MBR.cs index 548a2a4296..32359b6c92 100644 --- a/source/Cosmos.HAL2/BlockDevice/MBR.cs +++ b/source/Cosmos.HAL2/BlockDevice/MBR.cs @@ -19,10 +19,10 @@ public class MBR public class PartInfo { public readonly byte SystemID; - public readonly uint StartSector; - public readonly uint SectorCount; + public readonly ulong StartSector; + public readonly ulong SectorCount; - public PartInfo(byte aSystemID, uint aStartSector, uint aSectorCount) + public PartInfo(byte aSystemID, ulong aStartSector, ulong aSectorCount) { SystemID = aSystemID; StartSector = aStartSector; @@ -41,7 +41,7 @@ public MBR(BlockDevice device) ParsePartition(aMBR, 494); } - protected void ParsePartition(byte[] aMBR, uint aLoc) + protected void ParsePartition(byte[] aMBR, ulong aLoc) { byte xSystemID = aMBR[aLoc + 4]; // SystemID = 0 means no partition @@ -56,8 +56,8 @@ protected void ParsePartition(byte[] aMBR, uint aLoc) } else if (xSystemID != 0) { - uint xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8); - uint xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12); + ulong xStartSector = BitConverter.ToUInt32(aMBR, (int)aLoc + 8); + ulong xSectorCount = BitConverter.ToUInt32(aMBR, (int)aLoc + 12); var xPartInfo = new PartInfo(xSystemID, xStartSector, xSectorCount); Partitions.Add(xPartInfo); @@ -128,11 +128,11 @@ public void WritePartitionInformation(Partition partition, byte PartitionNo) partition.Host.ReadBlock(0, 1, ref mb.memory); //TO DO: Implement the CHS starting / ending sector adresses and partition type mb.Write8((uint)(446 + (PartitionNo * 16) + 4), 0x0B); - mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint) partition.StartingSector); - mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint) partition.BlockCount); + mb.Write32((uint)(446 + (PartitionNo * 16) + 8), (uint)partition.StartingSector); + mb.Write32((uint)(446 + (PartitionNo * 16) + 12), (uint)partition.BlockCount); partition.Host.WriteBlock(0, 1, ref mb.memory); ParsePartition(mb.memory, 446 + (uint)(PartitionNo * 16)); - + } } } diff --git a/source/Cosmos.System2/FileSystem/Disk.cs b/source/Cosmos.System2/FileSystem/Disk.cs index f3bb292144..a69292c0f3 100644 --- a/source/Cosmos.System2/FileSystem/Disk.cs +++ b/source/Cosmos.System2/FileSystem/Disk.cs @@ -20,7 +20,7 @@ public class Disk /// /// The size of the disk in bytes. /// - public int Size { get; } + public long Size { get; } /// /// List of partitions /// @@ -30,10 +30,12 @@ public List Partitions { List converted = new(); - if (Host.Type == BlockDeviceType.RemovableCD) { + if (Host.Type == BlockDeviceType.RemovableCD) + { ManagedPartition part = new(new Partition(Host, 0, 1000000000), nameof(ISO9660FileSystemFactory)); // For some reason, BlockCount is always 0, so just put a large value here. - if (mountedPartitions[0] != null) { + if (mountedPartitions[0] != null) + { var data = mountedPartitions[0]; part.RootPath = data.RootPath; part.MountedFS = data; @@ -97,7 +99,7 @@ public Disk(BlockDevice mainBlockDevice) parts.Add(new ManagedPartition(part)); } } - Size = (int)(mainBlockDevice.BlockCount * mainBlockDevice.BlockSize); + Size = (long)(mainBlockDevice.BlockCount * mainBlockDevice.BlockSize); } /// /// Mounts all of the partitions in the disk @@ -156,10 +158,9 @@ public void CreatePartition(int size) throw new Exception("Creating partitions with GPT style not yet supported!"); } - int location; - int startingSector = 63; - uint amountOfSectors = (uint)(size * 1024 * 1024 / 512); - //TODO: Check if partition is too big + ulong location; + ulong startingSector = 63; + ulong amountOfSectors = ((ulong)size * 1024 * 1024 / 512); if (Partitions.Count == 0) { @@ -169,7 +170,7 @@ public void CreatePartition(int size) else if (Partitions.Count == 1) { location = 462; - startingSector = (int)(Partitions[0].Host.BlockSize + Partitions[0].Host.BlockCount); + startingSector = (ulong)(Partitions[0].Host.BlockSize + Partitions[0].Host.BlockCount); } else if (Partitions.Count == 2) { @@ -215,7 +216,7 @@ public void CreatePartition(int size) mbrData[510] = boot[0]; mbrData[511] = boot[1]; - Partition partion = new(Host, (ulong)startingSector, amountOfSectors); + Partition partion = new(Host, startingSector, amountOfSectors); Partition.Partitions.Add(partion); parts.Add(new ManagedPartition(partion)); @@ -299,11 +300,12 @@ public void MountPartition(int index) foreach (var item in FileSystemManager.RegisteredFileSystems) { - if(part.LimitFS != null && item.GetType().Name != part.LimitFS) { + if (part.LimitFS != null && item.GetType().Name != part.LimitFS) + { Kernel.PrintDebug("Did not mount partition " + index + " as " + item.GetType().Name + " because the partition has been limited to being a " + part.LimitFS); continue; } - + if (item.IsType(part.Host)) { Kernel.PrintDebug("Mounted partition."); diff --git a/source/Cosmos.System2/FileSystem/ManagedPartition.cs b/source/Cosmos.System2/FileSystem/ManagedPartition.cs index 8c6c5a77d4..10669305cb 100644 --- a/source/Cosmos.System2/FileSystem/ManagedPartition.cs +++ b/source/Cosmos.System2/FileSystem/ManagedPartition.cs @@ -23,7 +23,8 @@ public class ManagedPartition public string LimitFS = null; - public ManagedPartition(Partition host, string limitFS = null) { + public ManagedPartition(Partition host, string limitFS = null) + { Host = host; LimitFS = limitFS; }