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
|
use fmt;
use fs;
use getopt;
use io;
use os;
use strconv;
use gpt;
use mbr;
use cmd;
export fn create(args: []str) void = {
// XXX this is a stub
const c = getopt::parse(args,
('f', "file", "specify another partition file to fit"),
('b', "bytes", "specify another length margin (bytes)"),
('s', "sectors", "specify another length margin (sectors, 512 bytes)")
);
defer getopt::finish(&c);
let length = 0z;
for (let i = 0z; i < len(c.opts); i += 1) {
const opt = c.opts[i];
switch (opt.0) {
case 'l' =>
length += (strconv::stoi(opt.1)! / 512 + 1): size;
case 's' =>
length += strconv::stoi(opt.1)!: size;
case 'f' =>
const stat = os::stat(opt.1)!;
length += stat.sz / 512 + 1;
};
};
const fd = cmd::mkfile();
defer io::close(fd)!;
const vol = gpt::create(fd, length);
defer {
gpt::chksums(vol);
gpt::commit(vol)!;
gpt::finish(vol);
};
vol.mbr.entries[3] = mbr::entry {
part_type = 0xEE,
lba_begin = 0,
length = -1: u32,
...
};
};
|