summaryrefslogtreecommitdiff
path: root/part/part.ha
diff options
context:
space:
mode:
authorAlejandro Sior <aho@sior.be>2022-06-21 10:38:45 +0200
committerAlejandro Sior <aho@sior.be>2022-06-21 10:38:45 +0200
commitc99646423f311c9238ace86be17caf531fe61c44 (patch)
treeb17f04f09ce6eb918e71983c8e7b1589eb0ec87f /part/part.ha
parentfd2f5a94d6ad595e8bed354eca168a82b882e8b4 (diff)
gptman: partition info
Diffstat (limited to 'part/part.ha')
-rw-r--r--part/part.ha55
1 files changed, 55 insertions, 0 deletions
diff --git a/part/part.ha b/part/part.ha
new file mode 100644
index 0000000..46c6546
--- /dev/null
+++ b/part/part.ha
@@ -0,0 +1,55 @@
+use fmt;
+use strconv;
+
+use gpt;
+use volume;
+
+
+export fn part(vol: str, args: []str) void = {
+ if (len(args) <= 1) {
+ list(vol, args[1..]);
+ return;
+ };
+
+ match (strconv::stou(args[1])) {
+ case let i: uint =>
+ const vol = volume::opengpt(vol);
+ defer gpt::finish(vol);
+ partinfo(vol, i);
+ return;
+ case =>
+ yield;
+ };
+
+ switch (args[1]) {
+ case "list" => list(vol, args[1..]);
+ };
+};
+
+export fn list(vol: str, args: []str) void = {
+ const vol = volume::opengpt(vol);
+ defer gpt::finish(vol);
+ const header = vol.primary.header;
+ const entries = vol.primary.entries;
+
+ for (let i = 0z; i < header.entries_len; i += 1) {
+ const entry = &entries[i];
+ if (entry.lba_begin == 0 && entry.lba_end == 0)
+ continue;
+
+ partinfo(vol, i);
+ };
+};
+
+fn partinfo(vol: *gpt::gpt, i: size) void = {
+ const entry = &vol.primary.entries[i];
+
+ fmt::printfln("# Partition {}", i)!;
+ fmt::printfln("entries[{}].part_type([{},{}])", i, entry.part_type[0], entry.part_type[1])!;
+ fmt::printfln("entries[{}].part([{},{}])", i, entry.part[0], entry.part[1])!;
+ fmt::printfln("entries[{}].lba_begin({})", i, entry.lba_begin)!;
+ fmt::printfln("entries[{}].lba_end({})", i, entry.lba_end)!;
+ fmt::printfln("entries[{}].attributes({})", i, entry.attributes)!;
+
+ // XXX name
+};