summaryrefslogtreecommitdiff
path: root/convert/convert.ha
blob: 98ad124f3cdd100405b6676a6556aacc4ffb5111 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use fmt;

use mbr;
use gpt;
use sector;

use os;
use io;
use fs;
use strings;
use errors;


export fn convert(args: []str) void = {
	if (len(args) < 2) {
		fmt::fatalf("gptman.convert: needs disk");
	};

	let file = os::open(args[1], fs::flags::RDWR)!;
	defer io::close(file)!;

	// let vol = gpt::create(file, 69);
	// gpt::mkbackup(vol);
	// defer {
	// 	gpt::chksums(vol);
	// 	gpt::commit(vol)!;
	// 	gpt::finish(vol);
	// };
	
	// vol.mbr.entries[0] = mbr::mbr_entry {
	// 	attributes = 0,
	// 	part_type = 0xEE,
	// 	lba_begin = 1,
	// 	lba_end = -1: u32,
	// };
	// vol.mbr.magic = 0xaa55;
	
	let vol = gpt::from(file)!;
	gpt::mkbackup(vol);
	defer {
		gpt::chksums(vol);
		gpt::commit(vol)!;
		gpt::finish(vol);
	};

	// fmt::printfln("rev {}", vol.primary.header.revision)!;

	// for (let i = 0z; i < 4; i += 1) {		
	// 	fmt::printfln("type {} from {} to {}", vol.mbr.entries[i].part_type, vol.mbr.entries[i].lba_begin, vol.mbr.entries[i].lba_end)!;
	// };

	// vol.primary.header.disk_guid[0] = 0xcafababe;
	// vol.primary.header.disk_guid[1] = 0xabababababababab;

	// // 516E7CB6-6ECF-11D6-8FF8-00022D09712B

	// vol.primary.entries[4].part_type[0] = 0x516E7CB66ECF;
	// vol.primary.entries[4].lba_begin = 35;
	// vol.primary.entries[4].lba_end = 37;
	// vol.primary.entries[5].part_type[0] = 0x516E7CB66ECF;
	// vol.primary.entries[5].lba_begin = 40;
	// vol.primary.entries[5].lba_end = 41;


	const much = 4z;
	const addr = gpt::findfree(vol, much);
	const where = gpt::findfreeentry(vol) as *gpt::entry;

	where.part_type = [0xCAFEBABE, 0xBABABA];
	where.lba_begin = addr;
	where.lba_end = addr + much: u64 - 1;

	fmt::printfln("fitting {}: {} and could be put at {}", much, addr, where)!;
};