Avoided automatic MBR partition type 0x00 with iso_write_opts_set_part_like_isohybrid() if partitions do not overlap

This commit is contained in:
Thomas Schmitt 2022-05-13 10:52:39 +02:00
parent 011e2e85e6
commit ad55ec78e4
2 changed files with 37 additions and 12 deletions

View File

@ -639,16 +639,17 @@ static uint32_t iso_make_mbr_id(Ecma119Image *t, int flag)
* do not insert APM mockup head
* do not treat bytes before code as isohybrid MBR
* do not create MBR id
* bit3= replace fs_type 0x00 by 0x17 if appropriate
*/
int make_isolinux_mbr(uint32_t *img_blocks, Ecma119Image *t,
int part_offset, int part_number, int fs_type,
uint8_t *buf, int flag)
{
uint32_t id, part, nominal_part_size;
uint32_t id, part, nominal_part_size, mbr_part_start;
off_t hd_img_blocks, hd_boot_lba;
char *wpt;
char *wpt, *fs_type_wpt = NULL;
uint32_t boot_lba;
int head_count, sector_count, ret;
int head_count, sector_count, ret, part_is_in_img = 0;
int gpt_count = 0, gpt_idx[128], apm_count = 0, gpt_cursor, i;
if (t->bootsrc[0] == NULL)
@ -730,6 +731,13 @@ int make_isolinux_mbr(uint32_t *img_blocks, Ecma119Image *t,
if (ret < 0)
return ret;
}
/* Will this hit the part_number partition ? */
mbr_part_start = iso_read_lsb((uint8_t *) (wpt + 8), 4);
if (mbr_part_start > 0 &&
mbr_part_start < hd_img_blocks + part_offset)
part_is_in_img = 1;
wpt+= 16;
continue;
}
@ -745,6 +753,7 @@ int make_isolinux_mbr(uint32_t *img_blocks, Ecma119Image *t,
else
lsb_to_buf(&wpt, 0x80, 8, 0);
lba512chs_to_buf(&wpt, part_offset, head_count, sector_count);
fs_type_wpt = wpt;
lsb_to_buf(&wpt, fs_type, 8, 0);
lba512chs_to_buf(&wpt, hd_img_blocks - 1, head_count, sector_count);
lsb_to_buf(&wpt, part_offset, 32, 0);
@ -759,6 +768,17 @@ int make_isolinux_mbr(uint32_t *img_blocks, Ecma119Image *t,
*/
lsb_to_buf(&wpt, 0xaa55, 16, 0);
/* Check whether automatically determined fs_type 0x00 can become 0x17 */
if ((flag & 8) && fs_type_wpt != NULL && fs_type == 0x00 &&
t->opts->iso_mbr_part_type != fs_type && !part_is_in_img) {
if (t->opts->iso_mbr_part_type >= 0 &&
t->opts->iso_mbr_part_type <= 255) {
lsb_to_buf(&fs_type_wpt, t->opts->iso_mbr_part_type, 8, 0);
} else {
lsb_to_buf(&fs_type_wpt, 0x17, 8, 0);
}
}
return(1);
}

View File

@ -2092,10 +2092,12 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf, int flag)
return ISO_ISOLINUX_CANT_PATCH;
}
if (gpt_count > 0 || apm_count > 0)
if (gpt_count > 0 || apm_count > 0) {
/* Decision can be revoked in make_isolinux_mbr if !do_isohybrid */
part_type = 0x00;
else
} else {
part_type = 0x17;
}
/* By tradition, real isohybrid insists in 0x00 if GPT or APM */
if (part_type != 0x00 || !do_isohybrid)
if (t->opts->iso_mbr_part_type >= 0 &&
@ -2109,13 +2111,16 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf, int flag)
no_boot_mbr = 2;
}
/* >>> ??? Why is partition_offset 0 here ?
/* ??? Why was partition_offset 0 here ?
It gets adjusted later by iso_offset_partition_start()
Would it harm to give the real offset here ?
*/;
ret = make_isolinux_mbr(&img_blocks, t, 0, 1, part_type, buf,
1 | no_boot_mbr | ((!do_isohybrid) << 2));
Does it harm to give the real offset here ?
Now this is really needed for checking whether partitions
are inside the ISO 9660 partition if !do_isohybrid
*/
ret = make_isolinux_mbr(&img_blocks, t, t->opts->partition_offset * 4,
1, part_type, buf,
1 | no_boot_mbr | ((!do_isohybrid) << 2) |
((!do_isohybrid) << 3));
if (ret != 1)
return ret;
} else if (sa_type == 1) {