1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use fmt;
use io;
use gpt;
export fn header(vol: io::file, args: []str) void = {
const vol = match (gpt::from(vol)) {
case let g: *gpt::gpt =>
yield g;
case gpt::nogpt =>
fmt::fatalf("gpt.header: disk {} does not have valid gpt", args[0]);
case =>
fmt::fatalf("gpt.header: could not access disk {}", args[0]);
};
defer gpt::finish(vol);
const header = vol.primary.header;
fmt::printfln("revision: \t\t{}", header.revision)!;
fmt::printfln("header_size: \t\t{}", header.header_size)!;
fmt::printfln("header_crc32: \t\t{}", header.header_crc32)!;
fmt::printfln("header_lba: \t\t{}", header.header_lba)!;
fmt::printfln("backup_header_lba: \t{}", header.backup_header_lba)!;
fmt::printfln("first_lba: \t\t{}", header.first_lba)!;
fmt::printfln("last_lba: \t\t{}", header.last_lba)!;
fmt::printfln("disk_guid: \t\t[{},{}]", header.disk_guid[0], header.disk_guid[1])!;
fmt::printfln("entries_lba: \t\t{}", header.entries_lba)!;
fmt::printfln("entries_len: \t\t{}", header.entries_len)!;
fmt::printfln("entry_size: \t\t{}", header.entry_size)!;
fmt::printfln("entries_crc32: \t\t{}", header.entries_crc32)!;
const primary_valid = gpt::header_crc32(header) == header.header_crc32 && gpt::entries_crc32(vol.primary.entries) == header.entries_crc32;
const backup_valid = 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: \t\t{}", primary_valid)!;
fmt::printfln("backup_sane: \t\t{}", backup_valid)!;
};
|