@@ -159,15 +159,15 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
159
159
160
160
var pe_ofs : usize = 0 ;
161
161
162
- var next_lba : u64 = 2 + ( std . math . divCeil ( u64 , table .partitions .len * 0x80 , block_size ) catch | e | switch ( e ) {
163
- error . DivisionByZero = > unreachable ,
164
- inline else = > | e2 | return e2 ,
165
- });
166
- const pe_end_plus_one_lba = next_lba ;
162
+ if ( table .partitions .len > 0x80 ) {
163
+ std . log . err ( "gpt with {} (> 128) partitions is not supported by most implementations" , .{ table . partitions . len });
164
+ }
165
+
166
+ const pe_end_plus_one_lba = 33 ;
167
167
for (table .partitions [0.. ], 0.. ) | partition , i | {
168
168
@memset (& pe_block , 0 );
169
169
170
- const offset = partition .offset orelse next_lba * block_size ;
170
+ const offset = partition .offset orelse 33 * block_size ;
171
171
const size = partition .size orelse if (i == table .partitions .len - 1 )
172
172
((max_partition_lba + 1 ) * block_size ) - offset
173
173
else
@@ -210,9 +210,18 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
210
210
var sub_view = try stream .slice (offset , size );
211
211
try partition .contains .render (& sub_view );
212
212
213
- next_lba = end_lba + 1 ;
214
213
pe_ofs += 0x80 ;
215
214
}
215
+ if (table .partitions .len < 0x80 ) {
216
+ @branchHint (.likely );
217
+ @memset (& pe_block , 0 );
218
+ for (table .partitions .len .. 0x80) | _ | {
219
+ pe_crc .update (& pe_block );
220
+ try stream .write (block_size * 2 + pe_ofs , & pe_block );
221
+ try stream .write (block_size * secondary_pe_array_lba + pe_ofs , & pe_block );
222
+ pe_ofs += 0x80 ;
223
+ }
224
+ }
216
225
217
226
const pe_array_crc32 = pe_crc .final ();
218
227
@@ -241,7 +250,7 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
241
250
std .mem .writeInt (u64 , gpt_header [0x30.. 0x38], max_partition_lba , .little ); // Last usable LBA
242
251
(table .disk_id orelse Guid .rand (random )).write (gpt_header [0x38.. 0x48]);
243
252
std .mem .writeInt (u64 , gpt_header [0x48.. 0x50], 2 , .little ); // First LBA of the partition entry array
244
- std .mem .writeInt (u32 , gpt_header [0x50.. 0x54], @intCast ( table . partitions . len ) , .little ); // Number of partition entries
253
+ std .mem .writeInt (u32 , gpt_header [0x50.. 0x54], 0x80 , .little ); // Number of partition entries
245
254
std .mem .writeInt (u32 , gpt_header [0x54.. 0x58], 0x80 , .little ); // Size of a partition entry
246
255
247
256
var backup_gpt_header_block : [block_size ]u8 = gpt_header_block ;
0 commit comments