@@ -88,7 +88,7 @@ fn parse_partition(ctx: dim.Context) !Partition {
88
88
.offset = null ,
89
89
.size = null ,
90
90
.bootable = false ,
91
- .type = .empty ,
91
+ .type = 0x00 ,
92
92
.contains = .empty ,
93
93
};
94
94
@@ -108,7 +108,19 @@ fn parse_partition(ctx: dim.Context) !Partition {
108
108
endpart ,
109
109
});
110
110
try switch (kw ) {
111
- .type = > updater .set (.type , try ctx .parse_enum (PartitionType )),
111
+ .type = > {
112
+ const part_name = try ctx .parse_string ();
113
+
114
+ const encoded = if (std .fmt .parseInt (u8 , part_name , 0 )) | value |
115
+ value
116
+ else | _ |
117
+ known_partition_types .get (part_name ) orelse blk : {
118
+ try ctx .report_nonfatal_error ("unknown partition type '{}'" , .{std .zig .fmtEscapes (part_name )});
119
+ break :blk 0x00 ;
120
+ };
121
+
122
+ try updater .set (.type , encoded );
123
+ },
112
124
.bootable = > updater .set (.bootable , true ),
113
125
.size = > updater .set (.size , try ctx .parse_mem_size ()),
114
126
.offset = > updater .set (.offset , try ctx .parse_mem_size ()),
@@ -212,7 +224,7 @@ fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderError!
212
224
desc [0 ] = if (part .bootable ) 0x80 else 0x00 ;
213
225
214
226
desc [1.. 4].* = encodeMbrChsEntry (lba ); // chs_start
215
- desc [4 ] = @intFromEnum ( part .type ) ;
227
+ desc [4 ] = part .type ;
216
228
desc [5.. 8].* = encodeMbrChsEntry (lba + size - 1 ); // chs_end
217
229
std .mem .writeInt (u32 , desc [8.. 12], lba , .little ); // lba_start
218
230
std .mem .writeInt (u32 , desc [12.. 16], size , .little ); // block_count
@@ -241,57 +253,28 @@ pub const Partition = struct {
241
253
size : ? u64 ,
242
254
243
255
bootable : bool ,
244
- type : PartitionType ,
256
+ type : u8 ,
245
257
246
258
contains : dim.Content ,
247
259
};
248
260
249
- /// https://en.wikipedia.org/wiki/Partition_type
250
- pub const PartitionType = enum (u8 ) {
251
- empty = 0x00 ,
252
-
253
- fat12 = 0x01 ,
254
- ntfs = 0x07 ,
255
-
256
- fat32_chs = 0x0B ,
257
- fat32_lba = 0x0C ,
258
-
259
- fat16_lba = 0x0E ,
260
-
261
- linux_swap = 0x82 ,
262
- linux_fs = 0x83 ,
263
- linux_lvm = 0x8E ,
264
-
265
- // Output from fdisk (util-linux 2.38.1)
266
- // 00 Leer 27 Verst. NTFS Win 82 Linux Swap / So c1 DRDOS/sec (FAT-
267
- // 01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
268
- // 02 XENIX root 3c PartitionMagic 84 versteckte OS/2 c6 DRDOS/sec (FAT-
269
- // 03 XENIX usr 40 Venix 80286 85 Linux erweitert c7 Syrinx
270
- // 04 FAT16 <32M 41 PPC PReP Boot 86 NTFS Datenträge da Keine Dateisyst
271
- // 05 Erweiterte 42 SFS 87 NTFS Datenträge db CP/M / CTOS / .
272
- // 06 FAT16 4d QNX4.x 88 Linux Klartext de Dell Dienstprog
273
- // 07 HPFS/NTFS/exFAT 4e QNX4.x 2. Teil 8e Linux LVM df BootIt
274
- // 08 AIX 4f QNX4.x 3. Teil 93 Amoeba e1 DOS-Zugriff
275
- // 09 AIX bootfähig 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
276
- // 0a OS/2-Bootmanage 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
277
- // 0b W95 FAT32 52 CP/M a0 IBM Thinkpad Ru ea Linux erweitert
278
- // 0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS Dateisyste
279
- // 0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
280
- // 0f W95 Erw. (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
281
- // 10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC B
282
- // 11 Verst. FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
283
- // 12 Compaq Diagnost 61 SpeedStor ab Darwin Boot f4 SpeedStor
284
- // 14 Verst. FAT16 <3 63 GNU HURD oder S af HFS / HFS+ f2 DOS sekundär
285
- // 16 Verst. FAT16 64 Novell Netware b7 BSDi Dateisyste f8 EBBR geschützt
286
- // 17 Verst. HPFS/NTF 65 Novell Netware b8 BSDI Swap fb VMware VMFS
287
- // 18 AST SmartSleep 70 DiskSecure Mult bb Boot-Assistent fc VMware VMKCORE
288
- // 1b Verst. W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux RAID-Auto
289
- // 1c Verst. W95 FAT3 80 Altes Minix be Solaris Boot fe LANstep
290
- // 1e Verst. W95 FAT1 81 Minix / altes L bf Solaris ff BBT
291
- // 24 NEC DOS
292
-
293
- _ ,
294
- };
261
+ // TODO: Fill from https://en.wikipedia.org/wiki/Partition_type
262
+ const known_partition_types = std .StaticStringMap (u8 ).initComptime (.{
263
+ .{ "empty" , 0x00 },
264
+
265
+ .{ "fat12" , 0x01 },
266
+
267
+ .{ "ntfs" , 0x07 },
268
+
269
+ .{ "fat32-chs" , 0x0B },
270
+ .{ "fat32-lba" , 0x0C },
271
+
272
+ .{ "fat16-lba" , 0x0E },
273
+
274
+ .{ "linux-swap" , 0x82 },
275
+ .{ "linux-fs" , 0x83 },
276
+ .{ "linux-lvm" , 0x8E },
277
+ });
295
278
296
279
pub fn encodeMbrChsEntry (lba : u32 ) [3 ]u8 {
297
280
var chs = lbaToChs (lba );
0 commit comments