Skip to content

Commit c0411db

Browse files
authored
Refactors build interface to allow both predefined and custom partition types for MBR
1 parent e02f64d commit c0411db

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

src/BuildInterface.zig

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ const ContentWriter = struct {
132132
for (data.partitions) |mpart| {
133133
if (mpart) |part| {
134134
try cw.code.writeAll(" part\n");
135-
try cw.code.print(" type {s}\n", .{@tagName(part.type)});
135+
switch (part.type) {
136+
.named => |id| try cw.code.print(" type {s}\n", .{@tagName(id)}),
137+
.custom => |id| try cw.code.print(" type 0x{X:0>2}\n", .{id}),
138+
}
136139
if (part.bootable) {
137140
try cw.code.writeAll(" bootable\n");
138141
}
@@ -337,17 +340,29 @@ pub const MbrPartTable = struct {
337340
bootloader: ?*const Content = null,
338341
partitions: [4]?*const Partition,
339342

343+
pub const PartType = enum(u8) {
344+
empty,
345+
fat12,
346+
ntfs,
347+
@"fat32-chs",
348+
@"fat32-lba",
349+
@"fat16-lba",
350+
@"linux-swa",
351+
@"linux-fs",
352+
@"linux-lvm",
353+
};
354+
340355
pub const Partition = struct {
341-
type: enum {
342-
empty,
343-
fat12,
344-
ntfs,
345-
@"fat32-chs",
346-
@"fat32-lba",
347-
@"fat16-lba",
348-
@"linux-swa",
349-
@"linux-fs",
350-
@"linux-lvm",
356+
type: union(enum) {
357+
named: PartType,
358+
custom: u8,
359+
360+
pub fn predefined(value: PartType) @This() {
361+
return .{ .named = value };
362+
}
363+
pub fn id(value: u8) @This() {
364+
return .{ .custom = value };
365+
}
351366
},
352367
bootable: bool = false,
353368
size: ?u64 = null,

0 commit comments

Comments
 (0)