summaryrefslogtreecommitdiff
path: root/info/info.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 /info/info.ha
parentfd2f5a94d6ad595e8bed354eca168a82b882e8b4 (diff)
gptman: partition info
Diffstat (limited to 'info/info.ha')
-rw-r--r--info/info.ha36
1 files changed, 36 insertions, 0 deletions
diff --git a/info/info.ha b/info/info.ha
new file mode 100644
index 0000000..7df9ee2
--- /dev/null
+++ b/info/info.ha
@@ -0,0 +1,36 @@
+use fmt;
+use io;
+
+use gpt;
+use volume;
+
+fn booltonum(a: bool) str = if (a) { return "1"; } else { return "0"; };
+
+export fn info(vol: str, args: []str) void = {
+ const name = vol;
+ const vol = volume::opengpt(vol);
+ defer gpt::finish(vol);
+
+ const header = vol.primary.header;
+
+ fmt::printfln("# GPT header info {}", name)!;
+ fmt::printfln("revision({})", header.revision)!;
+ fmt::printfln("header_size({})", header.header_size)!;
+ fmt::printfln("header_crc32({})", header.header_crc32)!;
+ fmt::printfln("header_lba({})", header.header_lba)!;
+ fmt::printfln("backup_header_lba({})", header.backup_header_lba)!;
+ fmt::printfln("first_lba({})", header.first_lba)!;
+ fmt::printfln("last_lba({})", header.last_lba)!;
+ // XXX Add a comment output for the GUID written in normal form
+ fmt::printfln("disk_guid([{},{}])", header.disk_guid[0], header.disk_guid[1])!;
+ fmt::printfln("entries_lba({})", header.entries_lba)!;
+ fmt::printfln("entries_len({})", header.entries_len)!;
+ fmt::printfln("entry_size({})", header.entry_size)!;
+ fmt::printfln("entries_crc32({})", header.entries_crc32)!;
+
+ const primary_sane = gpt::header_crc32(header) == header.header_crc32 && gpt::entries_crc32(vol.primary.entries) == header.entries_crc32;
+ const backup_sane = gpt::header_crc32(vol.backup.header) == vol.backup.header.header_crc32 && gpt::entries_crc32(vol.backup.entries) == vol.backup.header.entries_crc32;
+
+ fmt::printfln("primary_sane({})", booltonum(primary_sane))!;
+ fmt::printfln("backup_sane({})", booltonum(backup_sane))!;
+};