From 5600f3d726cbe202675aaf6300a2d655396bf053 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 27 Feb 2017 18:27:59 +0100 Subject: [PATCH] When deciding boot flag, consider MBR partition slot empty only if entirely 0 --- libisofs/system_area.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libisofs/system_area.c b/libisofs/system_area.c index 1dda499..d411ebd 100644 --- a/libisofs/system_area.c +++ b/libisofs/system_area.c @@ -192,6 +192,19 @@ int iso_compute_append_partitions(Ecma119Image *t, int flag) } +static int mbr_part_slot_is_unused(uint8_t *slot) +{ + int i; + + for (i = 0; i < 16; i++) + if (slot[i] != 0) + break; + if (i >= 16) + return 1; + return 0; +} + + /* @param flag bit1= partition_offset and partition_size are counted in blocks of 512 rather than 2048 @@ -1777,7 +1790,7 @@ static void iso_dummy_mbr_partition(uint8_t *buf, int mode) 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 }; for (i = 0; i < 4; i++) { - if (buf[446 + 16 * i + 4] == 0x00) { + if (mbr_part_slot_is_unused(buf + 446 + 16 * i)) { memcpy(buf + 446 + 16 * i, dummy_entry, 16); return; } @@ -2125,7 +2138,7 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) break; if (i >= 4) { /* no bootable/active flag set yet */ for (i = 0; i < 4; i++) { - if (buf[446 + 16 * i + 4] != 0x00 && + if ((!mbr_part_slot_is_unused(buf + 446 + 16 * i)) && buf[446 + 16 * i + 4] != 0xee && buf[446 + 16 * i + 4] != 0xef) { buf[446 + 16 * i] |= 0x80;