summaryrefslogtreecommitdiff
path: root/part/part.ha
blob: 46c65460567a4de808473aa68a0e672292e5a73d (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
};