Skip to content

Commit 481e0ce

Browse files
authored
Merge pull request #12 from bnuuydev/gpt
Implement GPT support
2 parents 9cc8866 + 71186e7 commit 481e0ce

File tree

5 files changed

+462
-46
lines changed

5 files changed

+462
-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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,44 @@ const ContentWriter = struct {
152152
}
153153
},
154154

155+
.gpt_part_table => |data| {
156+
try cw.code.writeAll("gpt-part\n");
157+
158+
if(data.legacy_bootable) {
159+
try cw.code.writeAll(" legacy-bootable\n");
160+
}
161+
162+
for (data.partitions) |part| {
163+
try cw.code.writeAll(" part\n");
164+
try cw.code.writeAll(" type ");
165+
switch (part.type) {
166+
.name => |name| {
167+
try cw.code.writeAll(@tagName(name));
168+
},
169+
.guid => |guid_text| {
170+
try cw.code.writeAll(&guid_text);
171+
},
172+
}
173+
try cw.code.writeByte('\n');
174+
175+
if (part.name) |name| {
176+
try cw.code.print(" name {s}\n", .{name});
177+
}
178+
if (part.offset) |offset| {
179+
try cw.code.print(" offset {d}\n", .{offset});
180+
}
181+
if (part.size) |size| {
182+
try cw.code.print(" size {d}\n", .{size});
183+
}
184+
try cw.code.writeAll(" contains");
185+
try cw.render(part.data);
186+
try cw.code.writeAll("\n");
187+
try cw.code.writeAll(" endpart\n");
188+
}
189+
190+
try cw.code.writeAll("endgpt");
191+
},
192+
155193
.vfat => |data| {
156194
try cw.code.print("vfat {s}\n", .{
157195
@tagName(data.format),
@@ -291,6 +329,7 @@ pub const Content = union(enum) {
291329
fill: u8,
292330
paste_file: std.Build.LazyPath,
293331
mbr_part_table: MbrPartTable,
332+
gpt_part_table: GptPartTable,
294333
vfat: FatFs,
295334
};
296335

@@ -317,6 +356,35 @@ pub const MbrPartTable = struct {
317356
};
318357
};
319358

359+
pub const GptPartTable = struct {
360+
legacy_bootable: bool = false,
361+
partitions: []const Partition,
362+
363+
pub const Partition = struct {
364+
type: union(enum) {
365+
name: enum {
366+
unused,
367+
@"efi-system",
368+
@"legacy-mbr",
369+
@"bios-boot",
370+
@"microsoft-basic-data",
371+
@"microsoft-reserved",
372+
@"windows-recovery",
373+
@"plan9",
374+
@"linux-swap",
375+
@"linux-fs",
376+
@"linux-reserved",
377+
@"linux-lvm",
378+
},
379+
guid: [36]u8,
380+
},
381+
name: ?[]const u8 = null,
382+
size: ?u64 = null,
383+
offset: ?u64 = null,
384+
data: Content,
385+
};
386+
};
387+
320388
pub const FatFs = struct {
321389
format: enum {
322390
fat12,

0 commit comments

Comments
 (0)