Skip to content

Commit

Permalink
Enable better counting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Feb 27, 2024
1 parent 65a8098 commit 823ce0f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions FirmwareGen/GPT/GPTUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,24 @@ private static byte[] MakeGPT(ulong FirstLBA, ulong LastLBA, ulong SectorSize, G
ulong FirstUsableLBA = FirstLBA + TotalGPTLBACount;
ulong LastUsableLBA = LastLBA - TotalGPTLBACount;

uint PartitionEntryCount = 32;
if ((uint)Partitions.Length + 2 > PartitionEntryCount)
{
if ((uint)Partitions.Length + 2 > PartitionEntryCount * 4)
{
throw new Exception("Unsupported Configuration, too many partitions than supported, please file an issue.");
}
uint PartitionEntryCount;

if ((uint)Partitions.Length > 128)
{
throw new Exception("Unsupported Configuration, too many partitions than supported, please file an issue.");
}
else if ((uint)Partitions.Length > 64)
{
PartitionEntryCount = 128;
}
else if ((uint)Partitions.Length > 32)
{
PartitionEntryCount = 64;
}
else
{
PartitionEntryCount = 32;
}

GPTHeader Header = new()
{
Expand All @@ -199,7 +207,6 @@ private static byte[] MakeGPT(ulong FirstLBA, ulong LastLBA, ulong SectorSize, G
PartitionArrayCRC32 = 0
};


List<byte> PartitionTableBuffer = [];
for (int i = 0; i < Partitions.Length; i++)
{
Expand Down

0 comments on commit 823ce0f

Please sign in to comment.