1- using BlockIO . GPT ;
2- using BlockIO . Arch . Windows ;
1+ using BlockIO . Arch . Windows ;
2+ using BlockIO . GPT ;
3+ using System . Buffers . Binary ;
4+ using System . IO . Hashing ;
35
46namespace BlockIO . GPT
57{
@@ -8,17 +10,28 @@ namespace BlockIO.GPT
810 /// </summary>
911 public static class GptDeviceWriter
1012 {
13+ //TODO: ADD TO UTILS CLASS
14+ private static uint CreateCRC32 ( byte [ ] buffer )
15+ {
16+ var span = buffer . AsSpan ( ) ;
17+ BinaryPrimitives . WriteUInt32LittleEndian ( span . Slice ( 16 , 4 ) , 0 ) ;
18+
19+ var crc32 = new System . IO . Hashing . Crc32 ( ) ;
20+ crc32 . Append ( span ) ;
21+ return crc32 . GetCurrentHashAsUInt32 ( ) ;
22+ }
23+
1124 /// <summary>
1225 /// Writes a default GPT header, empty partition entry array, and backup header to the device.
1326 /// </summary>
1427 /// <param name="stream">The GPT-capable device stream.</param>
1528 public static void WriteDefaultGpt ( GPTDeviceStream stream )
1629 {
17- var sectorSize = stream . Partition . SectorSize ;
18- var sectorCount = stream . Partition . SectorCount ;
30+ var sectorSize = stream . SectorSize ;
31+ var sectorCount = stream . Device . SectorCount ;
1932
2033 // 1. Protective MBR at sector 0
21- var protectiveMbr = ProtectiveMBR . Create ( sectorSize , sectorCount ) ;
34+ var protectiveMbr = ProtectiveMBR . Create ( ( ulong ) sectorSize , sectorCount ) ;
2235 stream . WriteSector ( 0 , protectiveMbr ) ;
2336
2437 // 2. Primary GPT header
@@ -29,7 +42,8 @@ public static void WriteDefaultGpt(GPTDeviceStream stream)
2942
3043 // 3. Empty partition entry array (sectors 2–33)
3144 var entryArray = new byte [ header . NumberOfEntries * header . EntrySize ] ;
32- header . PartitionArrayCRC32 = Crc32Helper . Compute ( entryArray ) ;
45+
46+ header . PartitionArrayCRC32 = CreateCRC32 ( entryArray ) ;
3347 var entrySectors = entryArray . Length / ( int ) sectorSize ;
3448
3549 for ( int i = 0 ; i < entrySectors ; i ++ )
0 commit comments