New -boot_image setting mbr_force_bootable=, -as mkisofs --mbr-force-bootable

This commit is contained in:
2016-01-01 17:28:46 +00:00
parent 631c2aa00f
commit 0fd1023809
13 changed files with 264 additions and 121 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2015 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -1573,6 +1573,7 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
int appended_as_gpt= 0, have_prep= 0, did_sysarea= 0, cared_for_apm= 0;
int cared_for_sparc= 0, have_hfsplus= 0;
int have_sysarea= 0, ptable_killer, imported_iso, have_alpha_ldr_path= 0;
int have_protective_msdos= 0;
unsigned long int sa_options= 0, partno, id_tag, perms, start_cyl, num_blocks;
unsigned long int part_status, part_type, start_block;
char name[24], *textpt, *contentpt, *buf= NULL;
@ -1581,14 +1582,18 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
char *cat_path= "";
struct elto_img_par *et_imgs= NULL;
int elto_count= 0;
uint32_t img_blocks= 0;
uint32_t img_blocks= 0, mbr_parts_end= 0;
struct FindjoB *job= NULL;
struct stat dir_stbuf;
IsoImage *image;
char *volid, *crt, *mdt, *ext, *eft, uuid[17];
char **app_pseudo_paths= NULL;
struct mbr_par {
uint8_t ptype;
uint64_t start_block;
uint64_t block_count;
int appended;
};
struct mbr_par *mbrpts= NULL;
int mbr_count= 0;
@ -1672,6 +1677,13 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
et_imgs[et_idx].path= NULL;
et_imgs[et_idx].ldsiz= -1;
}
Xorriso_alloc_meM(app_pseudo_paths, char *, elto_count);
for(i= 0; i < elto_count; i++)
app_pseudo_paths[i]= NULL;
for(i= 0; i < elto_count; i++) {
Xorriso_alloc_meM(app_pseudo_paths[i], char, 80);
app_pseudo_paths[i][0]= 0;
}
}
if(mbr_count > 0)
Xorriso_alloc_meM(mbrpts, struct mbr_par, mbr_count);
@ -1785,11 +1797,19 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
idx= num[0] - 1;
et_imgs[idx].sel_crit= textpt;
} else if(strcmp(name, "System area summary:") == 0) {
if(strstr(textpt, "protective-msdos-label") != NULL)
have_protective_msdos= 1;
} else if(strcmp(name, "MBR partition :") == 0) {
sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu",
&partno, &part_status, &part_type, &start_block, &num_blocks);
idx= partno - 1;
mbrpts[idx].ptype= part_type;
mbrpts[idx].start_block= start_block;
mbrpts[idx].block_count= num_blocks;
if(num_blocks > 0 && start_block + num_blocks > mbr_parts_end)
mbr_parts_end= start_block + num_blocks;
} else if(strcmp(name, "GPT type GUID :") == 0) {
idx= num[0] - 1;
@ -1921,12 +1941,17 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
} else if(strcmp(name, "MBR partition :") == 0) {
sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu",
&partno, &part_status, &part_type, &start_block, &num_blocks);
if(img_blocks <= start_block && num_blocks > 0) {
if(num_blocks > 0 && part_type != 0x00 && part_type != 0xee &&
(img_blocks <= start_block ||
(have_protective_msdos && img_blocks == mbr_parts_end &&
partno > 1))) {
if(!appended_as_gpt) {
sprintf(buf, "-append_partition %lu 0x%lx ", partno, part_type);
Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) start_block,
((uint64_t) start_block) + num_blocks - 1, "d",
imported_iso);
if(partno >= 1 && (int) partno <= mbr_count)
mbrpts[partno - 1].appended= 1;
}
} else if(part_type == 0x41 && have_prep) {
if(mkisofs) {
@ -1937,8 +1962,13 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) start_block,
((uint64_t) start_block) + num_blocks - 1, "d",
imported_iso);
} else if((part_status & 0x80) && part_type == 0x00 &&
start_block == 0 && num_blocks == 1) {
if(mkisofs)
sprintf(buf, "--mbr-force-bootable");
else
sprintf(buf, "-boot_image any mbr_force_bootable=on");
}
} else if(strcmp(name, "MBR partition path :") == 0) {
idx= num[0] - 1;
if(mbrpts[idx].ptype == 0x41) {
@ -2303,14 +2333,31 @@ static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
/* >>> need way to eploit El Torito img blks : */;
if(!(flag & 1)) {
sprintf(xorriso->info_text,
/* Check whether appended partition */;
for(i= 0; i < mbr_count; i++)
if(mbrpts[i].appended &&
mbrpts[i].start_block == ((uint64_t) et_imgs[idx].lba) * 4 &&
(mbrpts[i].block_count == (uint64_t) et_imgs[idx].ldsiz ||
et_imgs[idx].ldsiz == 0 || et_imgs[idx].ldsiz == 1))
break;
if (i < mbr_count) {
sprintf(app_pseudo_paths[idx],
"--interval:appended_partition_%d_start_%lud_size_%lud:all::",
i + 1,
(unsigned long) mbrpts[i].start_block,
(unsigned long) mbrpts[i].block_count);
et_imgs[idx].path= app_pseudo_paths[idx];
} else {
if(!(flag & 1)) {
sprintf(xorriso->info_text,
"Cannot enable EL Torito boot image #%d because it is not a data file in the ISO filesystem",
idx + 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
buf[0]= 0;
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
buf[0]= 0;
continue;
}
}
Text_shellsafe(et_imgs[idx].path, buf, 1);
Xorriso_record_cmd_linE
@ -2411,6 +2458,12 @@ ex:
Xorriso_free_meM(apms);
Xorriso_free_meM(gpts);
Xorriso_free_meM(mbrpts);
if(app_pseudo_paths != NULL) {
for(i= 0; i < elto_count; i++)
if(app_pseudo_paths[i] != NULL)
Xorriso_free_meM(app_pseudo_paths[i]);
Xorriso_free_meM(app_pseudo_paths);
}
Xorriso_free_meM(et_imgs);
Xorriso_free_meM(lines);
Xorriso_free_meM(buf);