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)!; };