aboutsummaryrefslogtreecommitdiffstats
path: root/src/pmbr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pmbr.c')
-rw-r--r--src/pmbr.c60
1 files changed, 18 insertions, 42 deletions
diff --git a/src/pmbr.c b/src/pmbr.c
index a958f83..b110850 100644
--- a/src/pmbr.c
+++ b/src/pmbr.c
@@ -12,7 +12,8 @@ mbr_entry_show (MBR_entry * e)
printf (" system %02x end chs %5d/%3d/%2d end sector %10d\n",
e->system,
MBR_CYLINDER (e->chs_end.cs),
- e->chs_end.head, MBR_SECTOR (e->chs_end.cs), e->size + e->start);
+ e->chs_end.head, MBR_SECTOR (e->chs_end.cs),
+ e->size + e->start - 1);
}
void
@@ -93,26 +94,23 @@ sector_to_chs (uint32_t lba)
return ret;
}
-void
-mbr_set_entry0_from_gpt_header (MBR_entry * m, GPT_header * h)
+static CHS
+invalid_chs (void)
{
- MBR ret = { 0 };
- uint32_t start = 1;
- uint32_t end = h->first_usable_lba - 1;
+ CHS ret;
+
+ ret.head = 254;
+ ret.cs = MBR_CS (1023, 63);
+ return ret;
+}
+
- 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_entry_from_gpt_entry (MBR_entry * m, GPT_header * h, GPT_entry * g,
+ int bootable, uint8_t type)
{
MBR ret = { 0 };
uint32_t start = g->start;
@@ -121,37 +119,15 @@ mbr_entry_from_gpt_entry (MBR_entry * m, GPT_entry * g, int bootable,
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->chs_start = invalid_chs ();
+ m->chs_end = invalid_chs ();
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))
+ if (type == MBR_PARTITION_TYPE_EFI)
{
- s++;
- if (s == 64)
- {
- s = 1;
- h++;
- if (h == 255)
- {
- c++;
- h = 0;
- }
- }
- m->size++;
+ m->size += m->start -1;
+ m->start = 1;
}
- m->chs_end.head = h;
- m->chs_end.cs = MBR_CS (c, s);
}