Skip to content

Commit c11cc71

Browse files
committed
Implement GPT support
1 parent 9cc8866 commit c11cc71

File tree

5 files changed

+450
-46
lines changed

5 files changed

+450
-46
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,23 @@ A complete list can be [found on Wikipedia](https://en.wikipedia.org/wiki/Partit
109109
### GPT Partition Table (`gpt-part`)
110110

111111
```plain
112+
gpt-part
113+
[disk-id <guid>] # optional, random guid used
114+
[part <…>] # partition 1
115+
[part <…>] # partition 2
116+
[…] # up to 128 partitions total
117+
endgpt
118+
```
112119

120+
```plain
121+
part
122+
type <type-id|guid>
123+
[part-id <guid>] # optional, random guid used
124+
[size <bytes>]
125+
[offset <bytes>]
126+
[name <string>]
127+
contains <content>
128+
endpart
113129
```
114130

115131
### FAT File System (`vfat`)

src/BuildInterface.zig

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,40 @@ const ContentWriter = struct {
152152
}
153153
},
154154

155+
.gpt_part_table => |data| {
156+
try cw.code.writeAll("gpt-part\n");
157+
158+
for (data.partitions) |part| {
159+
try cw.code.writeAll(" part\n");
160+
try cw.code.writeAll(" type ");
161+
switch (part.type) {
162+
.name => |name| {
163+
try cw.code.writeAll(@tagName(name));
164+
},
165+
.guid => |guid_text| {
166+
try cw.code.writeAll(&guid_text);
167+
},
168+
}
169+
try cw.code.writeByte('\n');
170+
171+
if (part.name) |name| {
172+
try cw.code.print(" name {s}\n", .{name});
173+
}
174+
if (part.offset) |offset| {
175+
try cw.code.print(" offset {d}\n", .{offset});
176+
}
177+
if (part.size) |size| {
178+
try cw.code.print(" size {d}\n", .{size});
179+
}
180+
try cw.code.writeAll(" contains");
181+
try cw.render(part.data);
182+
try cw.code.writeAll("\n");
183+
try cw.code.writeAll(" endpart\n");
184+
}
185+
186+
try cw.code.writeAll("endgpt");
187+
},
188+
155189
.vfat => |data| {
156190
try cw.code.print("vfat {s}\n", .{
157191
@tagName(data.format),
@@ -291,6 +325,7 @@ pub const Content = union(enum) {
291325
fill: u8,
292326
paste_file: std.Build.LazyPath,
293327
mbr_part_table: MbrPartTable,
328+
gpt_part_table: GptPartTable,
294329
vfat: FatFs,
295330
};
296331

@@ -317,6 +352,24 @@ pub const MbrPartTable = struct {
317352
};
318353
};
319354

355+
pub const GptPartTable = struct {
356+
partitions: []const Partition,
357+
358+
pub const Partition = struct {
359+
type: union(enum) {
360+
name: enum {
361+
unused,
362+
@"efi-system",
363+
},
364+
guid: [36]u8,
365+
},
366+
name: ?[]const u8 = null,
367+
size: ?u64 = null,
368+
offset: ?u64 = null,
369+
data: Content,
370+
};
371+
};
372+
320373
pub const FatFs = struct {
321374
format: enum {
322375
fat12,

0 commit comments

Comments
 (0)