From 24c1249c07254fc8357a97c0be65267826d74eb8 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 12 Nov 2007 13:28:04 +0000 Subject: *** empty log message *** --- src/pmbr.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'src/pmbr.c') diff --git a/src/pmbr.c b/src/pmbr.c index a9bbfb8..a958f83 100644 --- a/src/pmbr.c +++ b/src/pmbr.c @@ -62,3 +62,96 @@ mbr_new (uint64_t lbas) return ret; } + + +static CHS +sector_to_chs (uint32_t lba) +{ + CHS ret; + int c; + int h; + int s; + + c = lba / (63 * 255); + + if (c > 1023) + { + ret.head = 254; + ret.cs = MBR_CS (1023, 63); + return ret; + } + + lba -= (c * 63 * 255); + h = lba / 63; + lba -= (h * 63); + s = lba + 1; + + + ret.head = h; + ret.cs = MBR_CS (c, s); + + return ret; +} + +void +mbr_set_entry0_from_gpt_header (MBR_entry * m, GPT_header * h) +{ + MBR ret = { 0 }; + uint32_t start = 1; + uint32_t end = h->first_usable_lba - 1; + + + m->bootable = 0; + m->chs_start = sector_to_chs (start); + m->system = MBR_PARTITION_TYPE_EFI; + m->chs_end = sector_to_chs (end); + m->start = start; + m->size = (end - start) + 1; + +} + +void +mbr_entry_from_gpt_entry (MBR_entry * m, GPT_entry * g, int bootable, + uint8_t type) +{ + MBR ret = { 0 }; + uint32_t start = g->start; + uint32_t end = g->end; + + + m->system = type; + m->bootable = bootable ? MBR_PARTITION_BOOTABLE : 0x00; + m->chs_start = sector_to_chs (start); + m->chs_end = sector_to_chs (end); + m->start = start; + m->size = (end - start) + 1; +} + +void +mbr_wedge_entry (MBR_entry * m) +{ + MBR ret = { 0 }; + + int c = MBR_CYLINDER (m->chs_end.cs); + int s = MBR_SECTOR (m->chs_end.cs); + int h = m->chs_end.head; + + while ((s != 63) || (h != 254)) + { + s++; + if (s == 64) + { + s = 1; + h++; + if (h == 255) + { + c++; + h = 0; + } + } + m->size++; + } + + m->chs_end.head = h; + m->chs_end.cs = MBR_CS (c, s); +} -- cgit v1.2.3