diff --git a/xorriso/iso_img.c b/xorriso/iso_img.c index 66947e27..bffa1edb 100644 --- a/xorriso/iso_img.c +++ b/xorriso/iso_img.c @@ -375,7 +375,7 @@ int Xorriso_boot_item_status(struct XorrisO *xorriso, char *cat_path, char *filter, FILE *fp, int flag) { int is_default, no_defaults, i, is_default_id= 0, ret; - char *line, *bspec= NULL, zeros[28]; + char *line, *bspec= NULL, zeros[28], *partition_entry; off_t file_size; struct stat stbuf; @@ -407,7 +407,7 @@ int Xorriso_boot_item_status(struct XorrisO *xorriso, char *cat_path, "/boot/isolinux/boot.cat") == 0) strcpy(bspec, "dir=/boot/isolinux"); memset(zeros, 0, 28); - if(bspec[0] && platform_id == 0 && (patch_isolinux & 3) && + if(bspec[0] && platform_id == 0 && (patch_isolinux & 0x3ff) == 1 && load_size == 2048 && is_default_id && emul == 0) { sprintf(line, "-boot_image isolinux %s\n", bspec); Xorriso_status_result(xorriso,filter,fp,flag&2); @@ -419,7 +419,7 @@ int Xorriso_boot_item_status(struct XorrisO *xorriso, char *cat_path, if(ret == 0) file_size= ((stbuf.st_size / (off_t) 512) + !!(stbuf.st_size % (off_t) 512)) * 512; - if(platform_id == 0xef && !(patch_isolinux & 3) && + if(platform_id == 0xef && (patch_isolinux & 0x3ff) == 0 && load_size == file_size && is_default_id && emul == 0) { sprintf(line, "-boot_image any efi_path="); Text_shellsafe(bin_path, line, 1); @@ -489,6 +489,27 @@ int Xorriso_boot_item_status(struct XorrisO *xorriso, char *cat_path, strcat(line, "\n"); if(!(is_default && no_defaults)) Xorriso_status_result(xorriso,filter,fp,flag&2); + + is_default= 1; + partition_entry= ""; + if((patch_isolinux & 0x0fc) == (1 << 2)) + partition_entry= "gpt_basdat"; + else if((patch_isolinux & 0x0fc) == (2 << 2)) + partition_entry= "gpt_hfsplus"; + if(partition_entry[0]) { + sprintf(line, "-boot_image isolinux partition_entry=%s\n", partition_entry); + Xorriso_status_result(xorriso, filter, fp, flag & 2); + is_default= 0; + } + if(patch_isolinux & (1 << 8)) { + sprintf(line, "-boot_image isolinux partition_entry=apm_hfsplus\n"); + Xorriso_status_result(xorriso, filter, fp, flag & 2); + is_default= 0; + } + if(is_default && !no_defaults) { + sprintf(line, "-boot_image isolinux partition_entry=off\n"); + Xorriso_status_result(xorriso, filter, fp, flag & 2); + } ret= 1; ex:; @@ -1301,12 +1322,9 @@ reject:; Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); goto hint_revoke; } - if(!(flag & 1)) { + if(!(flag & 1)) xorriso->system_area_options= (xorriso->system_area_options & ~0x3cff) | ((sa_type << 2) & 0xfc) | (options & 0x3c03); - if(sa_type == 0) - xorriso->patch_system_area= xorriso->system_area_options; - } return(1); hint_revoke:; @@ -1354,6 +1372,722 @@ ex:; } +static int Xorriso_split_report_line(struct XorrisO *xorriso, char *line, + int num_limit, + char *name, char **contentpt, + double *num, int *num_count, + char **textpt, int flag) +{ + int i; + char *spt, *ept, *cpt; + + if(strlen(line) < 21) { +undigestible: + sprintf(xorriso->info_text, + "Undigestible report line with -report_* mode cmd: '%s'", line); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); + return(0); + } + if(line[19] != ':') + goto undigestible; + strncpy(name, line, 20); + name[20]= 0; + + for(spt= line + 20; *spt == ' '; spt++); + *textpt= *contentpt= spt; + *num_count= 0; + for(i= 0; i < num_limit; i++) { + /* Get word */ + for(spt= *textpt; *spt == ' '; spt++); + if(*spt == 0) { + *textpt= spt; + break; + } + for(ept= spt + 1; *ept != ' ' && *ept != 0; ept++); + /* Look for decimal number */ + if(ept - spt > 16) + break; + for(cpt= spt; cpt < ept; cpt++) + if(*cpt < '0' || *cpt > '9') + break; + if(cpt != ept) + break; + sscanf(spt, "%lf", num + *num_count); + (*num_count)++; + *textpt= ept; + } + /* Set *textpt to next non-blank */ + for(; **textpt == ' '; (*textpt)++); + return(1); +} + + +static int Xorriso_record_cmd_line(struct XorrisO *xorriso, char *buf, + char **cmds, int *cmd_count, int flag) +{ + int ret; + + if(flag & 1) { + (*cmd_count)++; + ret= 1; goto ex; + } + Xorriso_alloc_meM(cmds[*cmd_count], char, strlen(buf) + 1); + strcpy(cmds[*cmd_count], buf); + (*cmd_count)++; + ret= 1; +ex:; + return(ret); +} + + +/* @param flag bit0= do not record but only count +*/ +static int Xorriso_scan_report_lines(struct XorrisO *xorriso, + char **et_lines, int et_line_count, + char **sa_lines, int sa_line_count, + char **cmds, int *cmd_count, int flag) +{ + int ret= 0, i, num_count, mkisofs, line_count, idx, et_idx, isohybrid= 0; + int efi_boot_part= 0, first_efi, full_sparc_part= 0, have_sparc_part= 0; + unsigned long int sa_options= 0, partno, id_tag, perms, start_cyl, num_blocks; + char name[24], *textpt, *contentpt, *buf= NULL, *sa_summary= ""; + char **lines= NULL; + double num[8]; + char *cat_path= ""; + struct elto_img_par { + int n, ldsiz, boot_info_table, grub2_boot_info; + int do_gpt_basdat, do_gpt_hfsplus, do_apm_hfsplus; + unsigned int ld_seg, hdpt, platform_id; + unsigned long int lba; + char pltf[8], b[8], emul[8], boot_image_type[16]; + char *path, *id_string, *sel_crit; + }; + struct elto_img_par *et_imgs= NULL; + int elto_count= 0; + uint32_t img_blocks= 0; + + struct gpt_par { + int ptype; /* 0= unknown, 1= gpt-basdat, 2=gpt-hfsplus */ + }; + struct gpt_par *gpts= NULL; + int gpt_count= 0; + + struct apm_par { + int ptype; /* 0= unknown, 1= Apple_HFS */ + }; + struct apm_par *apms= NULL; + int apm_count= 0; +#define Xorriso_record_cmd_linE { \ + ret= Xorriso_record_cmd_line(xorriso, buf, cmds, cmd_count, flag & 1); \ + if(ret <= 0) \ + goto ex; \ + } + + mkisofs= !!(flag & 2); + + *cmd_count= 0; + line_count= et_line_count + sa_line_count; + if(line_count <= 0) + {ret= 1; goto ex;} + + Xorriso_alloc_meM(buf, char, 80 + SfileadrL); + Xorriso_alloc_meM(lines, char *, line_count); + for(i= 0; i < et_line_count; i++) + lines[i]= et_lines[i]; + for(i= 0; i < sa_line_count; i++) + lines[i + et_line_count]= sa_lines[i]; + + /* Pre-scan to establish context */ + for(i= 0; i < line_count; i++) { + ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt, + num, &num_count, &textpt, 0); + if(ret <= 0) + goto ex; + if(strcmp(name, "System area options:") == 0) { + sscanf(contentpt, "%lx", &sa_options); + + } else if(strcmp(name, "System area summary:") == 0) { + sa_summary= contentpt; + + } else if(strcmp(name, "El Torito boot img :") == 0) { + if(num[0] > elto_count) + elto_count= num[0]; + + } else if(strcmp(name, "GPT partition name :") == 0) { + if(num[0] > gpt_count) + gpt_count= num[0]; + + } else if(strcmp(name, "APM partition name :") == 0) { + if(num[0] > apm_count) + apm_count= num[0]; + + } else if(strcmp(name, "ISO image size/512 :") == 0) { + img_blocks= num[0]; + + } + } + + if(elto_count > 0) + Xorriso_alloc_meM(et_imgs, struct elto_img_par, elto_count); + if(gpt_count > 0) + Xorriso_alloc_meM(gpts, struct gpt_par, gpt_count); + if(apm_count > 0) + Xorriso_alloc_meM(apms, struct apm_par, apm_count); + + /* First pass: set up objects, record El Torito and info needed in 2nd pass */ + for(i= 0; i < line_count; i++) { + buf[0]= 0; + ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt, + num, &num_count, &textpt, 0); + if(ret <= 0) + goto ex; + + if(strcmp(name, "El Torito cat path :") == 0) { + cat_path= textpt; + + } else if(strcmp(name, "El Torito boot img :") == 0) { + /* Platform Id, bootability, emulation, load segment, + Hard disk emulation partition type, Load size + */ + idx= num[0] - 1; + sscanf(contentpt, "%d %s %s %s %x %x %d %lu", + &(et_imgs[idx].n), et_imgs[idx].pltf, et_imgs[idx].b, + et_imgs[idx].emul, &(et_imgs[idx].ld_seg), &(et_imgs[idx].hdpt), + &(et_imgs[idx].ldsiz), &(et_imgs[idx].lba)); + if(strcmp(et_imgs[idx].pltf, "BIOS") == 0) + et_imgs[idx].platform_id= 0; + else if(strcmp(et_imgs[idx].pltf, "PPC") == 0) + et_imgs[idx].platform_id= 1; + else if(strcmp(et_imgs[idx].pltf, "Mac") == 0) + et_imgs[idx].platform_id= 2; + else if(strcmp(et_imgs[idx].pltf, "UEFI") == 0) + et_imgs[idx].platform_id= 0xef; + else + sscanf(et_imgs[idx].pltf, "%x", &(et_imgs[idx].platform_id)); + + strcpy(et_imgs[idx].boot_image_type, "any"); + et_imgs[idx].boot_info_table= 0; + et_imgs[idx].grub2_boot_info= 0; + et_imgs[idx].path= et_imgs[idx].id_string= et_imgs[idx].sel_crit= ""; + et_imgs[idx].do_gpt_basdat= et_imgs[idx].do_gpt_hfsplus= 0; + et_imgs[idx].do_apm_hfsplus= 0; + + } else if(strcmp(name, "El Torito img path :") == 0) { + idx= num[0] - 1; + et_imgs[idx].path= textpt; + + } else if(strcmp(name, "El Torito img opts :") == 0) { + idx= num[0] - 1; + if(strstr(textpt, "boot-info-table") != NULL) + et_imgs[idx].boot_info_table= 1; + if(strstr(textpt, "isohybrid-suitable") != NULL) + strcpy(et_imgs[idx].boot_image_type, "isolinux"); + if(strstr(textpt, "grub2-boot-info") != NULL) { + strcpy(et_imgs[idx].boot_image_type, "grub"); + et_imgs[idx].grub2_boot_info= 1; + } + + } else if(strcmp(name, "El Torito id string:") == 0) { + idx= num[0] - 1; + et_imgs[idx].id_string= textpt; + + } else if(strcmp(name, "El Torito sel crit :") == 0) { + idx= num[0] - 1; + et_imgs[idx].sel_crit= textpt; + + } else if(strcmp(name, "GPT type GUID :") == 0) { + idx= num[0] - 1; + if(strcmp(textpt, "a2a0d0ebe5b9334487c068b6b72699c7") == 0) + gpts[idx].ptype= 1; /* Basic data */ + else if(strcmp(textpt, "005346480000aa11aa1100306543ecac") == 0) + gpts[idx].ptype= 2; /* HFS+ */ + else + gpts[idx].ptype= 0; + + } else if(strcmp(name, "APM partition type :") == 0) { + idx= num[0] - 1; + if(strcmp(textpt, "Apple_HFS") == 0) + apms[idx].ptype= 1; + else + apms[idx].ptype= 0; + + } + } + + /* Second pass: scan for System Area info */ + for(i= 0; i < line_count; i++) { + buf[0]= 0; + ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt, + num, &num_count, &textpt, 0); + if(ret <= 0) + goto ex; + + if(strcmp(name, "System area options:") == 0) { + if((sa_options & 0x3c00) == 0x0400) { + if(mkisofs) + sprintf(buf, "-chrp-boot-part "); + else + sprintf(buf, "-boot_image any chrp_boot_part=on "); + } + + } else if(strcmp(name, "System area summary:") == 0) { + if(strstr(textpt, "isohybrid") != NULL) { + isohybrid= 1; + if(mkisofs) + sprintf(buf, "-isohybrid-mbr ."); + else + sprintf(buf, "-boot_image isolinux partition_table=on"); + Xorriso_record_cmd_linE + } + if(strstr(textpt, "grub2-mbr") != NULL) { + if(mkisofs) + sprintf(buf, "--grub2-mbr ."); + else + sprintf(buf, "-boot_image grub grub2_mbr=."); + Xorriso_record_cmd_linE + } + if(strstr(textpt, "protective-msdos-label") != NULL) { + if(mkisofs) + sprintf(buf, "--protective-msdos-label"); + else + sprintf(buf, "-boot_image any partition_table=on"); + Xorriso_record_cmd_linE + } + if(strstr(textpt, "cyl-align-off") != NULL) { + if(mkisofs) + sprintf(buf, "-partition_cyl_align off"); + else + sprintf(buf, "-boot_image any partition_cyl_align=off"); + } else if(strstr(textpt, "cyl-align-all") != NULL) { + if(mkisofs) + sprintf(buf, "-partition_cyl_align all"); + else + sprintf(buf, "-boot_image any partition_cyl_align=all"); + } else if(strstr(textpt, "cyl-align-") != NULL) { + if(mkisofs) + sprintf(buf, "-partition_cyl_align on"); + else + sprintf(buf, "-boot_image any partition_cyl_align=on"); + } else + buf[0]= 0; + + } else if(strcmp(name, "Partition offset :") == 0 && + (num[0] == 0 || num[0] == 16)) { + if(mkisofs) + sprintf(buf, "-partition_offset %.f", num[0]); + else + sprintf(buf, "-boot_image any partition_offset=%.f", num[0]); + + } else if(strcmp(name, "MBR heads per cyl :") == 0 && + (num[0] > 0 && num[0] <= 255)) { + if(mkisofs) + sprintf(buf, "-partition_hd_cyl %.f", num[0]); + else + sprintf(buf, "-boot_image any partition_hd_cyl=%.f", num[0]); + + } else if(strcmp(name, "MBR secs per head :") == 0 && + (num[0] > 0 && num[0] <= 63)) { + if(mkisofs) + sprintf(buf, "-partition_sec_hd %.f", num[0]); + else + sprintf(buf, "-boot_image any partition_sec_hd=%.f", num[0]); + + } else if(strcmp(name, "MBR partition :") == 0) { + + /* >>> ??? is this an independent partition ? */; + + } else if(strcmp(name, "MBR partition path :") == 0) { + + /* >>> ??? are there independent partition paths ? */; + + } else if(strcmp(name, "PReP boot partition:") == 0) { + + /* >>> -boot_image any prep_boot_part= + needs opportunity to set a prep path in the input ISO */; + + } else if(strcmp(name, "GPT disk GUID :") == 0) { + + /* >>> ??? need command to set disk GUID */; + + } else if(strcmp(name, "GPT partition name :") == 0) { + + /* >>> ??? need command to set partition name for partition number */; + + } else if(strcmp(name, "GPT partition GUID :") == 0) { + + /* >>> ??? need command to set partition GUID for partition number */; + + } else if(strcmp(name, "GPT partition flags:") == 0) { + + /* >>> check whether 0x1000000000000001 . Else: complain */; + + } else if(strcmp(name, "GPT partition path :") == 0) { + idx= num[0] - 1; + /* Check El Torito boot images for same path */ + first_efi= 1; + for(et_idx= 0; et_idx < elto_count; et_idx++) { + if(strcmp(et_imgs[et_idx].path, textpt) != 0) + continue; + if(isohybrid) { + if(gpts[idx].ptype == 1) + et_imgs[et_idx].do_gpt_basdat= 1; + else if(gpts[idx].ptype == 2) + et_imgs[et_idx].do_gpt_hfsplus= 1; + break; + } else if(first_efi && et_imgs[et_idx].platform_id == 0xef) { + efi_boot_part= 1; + break; + } + if(et_imgs[et_idx].platform_id == 0xef) + first_efi= 0; + } + + /* >>> ??? Are there independent GPT partition paths ? */; + + } else if(strcmp(name, "APM block size :") == 0) { + if(mkisofs) + sprintf(buf, "-apm-block-size %.f", num[0]); + else + sprintf(buf, "-boot_image any apm_block_size=%.f", num[0]); + + } else if(strcmp(name, "APM partition name :") == 0) { + + /* >>> ??? need command to set APM partition name for partition number */; + + } else if(strcmp(name, "APM partition path :") == 0) { + idx= num[0] - 1; + /* Check El Torito EFI boot images for same path */ + for(et_idx= 0; isohybrid && et_idx < elto_count; et_idx++) + if(strcmp(et_imgs[et_idx].path, textpt) == 0) { + if(apms[idx].ptype == 1) + et_imgs[et_idx].do_apm_hfsplus= 1; + break; + } + + } else if(strcmp(name, "MIPS-BE boot path :") == 0) { + if(mkisofs) + sprintf(buf, "-mips-boot "); + else + sprintf(buf, "-boot_image any mips_path="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "MIPS-LE boot path :") == 0) { + if(mkisofs) + sprintf(buf, "-mipsel-boot "); + else + sprintf(buf, "-boot_image any mipsel_path="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "SUN SPARC disklabel:") == 0) { + if(mkisofs) + sprintf(buf, "-sparc-label "); + else + sprintf(buf, "-boot_image any sparc_label="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "SPARC GRUB2 path :") == 0) { + if(mkisofs) + sprintf(buf, "--grub2-sparc-core "); + else + sprintf(buf, "-boot_image grub grub2_sparc_core="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "SUN SPARC partition:") == 0) { + have_sparc_part= 1; + partno= id_tag= perms= num_blocks= 0; + start_cyl= 0xffffffff; + sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu", + &partno, &id_tag, &perms, &start_cyl, &num_blocks); + if(partno > 0 && partno < 9 && start_cyl == 0 && num_blocks == img_blocks + && ((partno == 1 && id_tag == 4) || (partno > 1 && id_tag == 2))) + full_sparc_part|= (1 << (partno - 1)); + + } else if(strcmp(name, "PALO header version:") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-hdrversion %.f", num[0]); + else + sprintf(buf, "-boot_image any hppa_hdrversion=%.f", num[0]); + + } else if(strcmp(name, "HP-PA cmdline :") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-cmdline "); + else + sprintf(buf, "-boot_image any hppa_cmdline="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "HP-PA 32-bit kernel:") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-kernel-32 "); + else + sprintf(buf, "-boot_image any hppa_kernel_32="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "HP-PA 64-bit kernel:") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-kernel-64 "); + else + sprintf(buf, "-boot_image any hppa_kernel_64="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "HP-PA ramdisk :") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-ramdisk "); + else + sprintf(buf, "-boot_image any hppa_ramdisk="); + Text_shellsafe(textpt, buf, 1); + + } else if(strcmp(name, "HP-PA bootloader :") == 0) { + if(mkisofs) + sprintf(buf, "-hppa-bootloader "); + else + sprintf(buf, "-boot_image any hppa_bootloader="); + Text_shellsafe(textpt, buf, 1); + + } + + if(buf[0]) + Xorriso_record_cmd_linE + } + + if(have_sparc_part) { + if(full_sparc_part == 255) { + if(mkisofs) { + sprintf(buf, "-G ."); + Xorriso_record_cmd_linE + sprintf(buf, "-B ..."); + Xorriso_record_cmd_linE + } else { + sprintf(buf, "-boot_image any system_area=."); + Xorriso_record_cmd_linE + for(i= 2; i <= 8; i++) { + sprintf(buf, "-append_partition %d 0x00 .", i); + Xorriso_record_cmd_linE + } + } + } else { + + /* >>> Warn of non-trivial partition situation */; + + } + } + + /* >>> Issue commands related to El Torito */; + if(elto_count <= 0) + goto after_el_torito; + + if(efi_boot_part) { + if(mkisofs) + sprintf(buf, "-efi-boot-part --efi-boot-image"); + else + sprintf(buf, "-boot_image any efi_boot_part=--efi-boot-image"); + Xorriso_record_cmd_linE + } + if(cat_path[0]) { + if(mkisofs) + sprintf(buf, "-c "); + else + sprintf(buf, "-boot_image any cat_path="); + Text_shellsafe(cat_path, buf, 1); + } else { + if(mkisofs) + sprintf(buf, "--boot-catalog-hide"); + else + sprintf(buf, "-boot_image any cat_hidden=on"); + } + Xorriso_record_cmd_linE + for(idx= 0; idx < elto_count; idx++) { + if(et_imgs[idx].ld_seg != 0 && et_imgs[idx].ld_seg != 0x07c0) { + + /* >>> Warn that load segment cannot be represented */; + + continue; + } + if(idx > 0) { + if(mkisofs) + sprintf(buf, "-eltorito-alt-boot"); + else + sprintf(buf, "-boot_image any next"); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].platform_id == 0) { + if(mkisofs) + sprintf(buf, "-b "); + else + sprintf(buf, "-boot_image %s bin_path=", et_imgs[idx].boot_image_type); + } else if(et_imgs[idx].platform_id == 0xef) { + if(mkisofs) + sprintf(buf, "-e "); + else + sprintf(buf, "-boot_image %s efi_path=", et_imgs[idx].boot_image_type); + } else { + if(mkisofs) { + + /* >>> Warn that platform id cannot be represented by -as mkisofs */; + + continue; + } + } + if(et_imgs[idx].path[0] == 0) { + + /* >>> need way to eploit El Torito img blks : */; + + /* >>> Warn that no file was found which matches LBA of boot image */; + + continue; + } + Text_shellsafe(et_imgs[idx].path, buf, 1); + Xorriso_record_cmd_linE + if(!mkisofs) { + sprintf(buf, "-boot_image any platform_id=0x%2.2x", + et_imgs[idx].platform_id); + Xorriso_record_cmd_linE + } + if(strcmp(et_imgs[idx].emul, "none") == 0) { + if(mkisofs) + sprintf(buf, "-no-emul-boot"); + else + sprintf(buf, "-boot_image any emul_type=no_emulation"); + } else if(strcmp(et_imgs[idx].emul, "hd") == 0) { + if(mkisofs) + sprintf(buf, "-hard-disk-boot"); + else + sprintf(buf, "-boot_image any emul_type=hard_disk"); + } else { + if(mkisofs) + buf[0]= 0; + else + sprintf(buf, "-boot_image any emul_type=diskette"); + } + if(buf[0]) + Xorriso_record_cmd_linE + if(et_imgs[idx].ldsiz > 0) { + if(mkisofs) + sprintf(buf, "-boot-load-size %d", et_imgs[idx].ldsiz); + else + sprintf(buf, "-boot_image any load_size=%d", et_imgs[idx].ldsiz * 512); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].boot_info_table) { + if(mkisofs) + sprintf(buf, "-boot-info-table"); + else + sprintf(buf, "-boot_image any boot_info_table=on"); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].grub2_boot_info) { + if(mkisofs) + sprintf(buf, "--grub2-boot-info"); + else + sprintf(buf, "-boot_image grub grub2_boot_info=on"); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].id_string[0] != 0) { + if(mkisofs) + sprintf(buf, "-eltorito-id "); + else + sprintf(buf, "-boot_image any id_string="); + Text_shellsafe(et_imgs[idx].id_string, buf, 1); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].sel_crit[0] != 0) { + if(mkisofs) + sprintf(buf, "-eltorito-selcrit "); + else + sprintf(buf, "-boot_image any sel_crit="); + Text_shellsafe(et_imgs[idx].sel_crit, buf, 1); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].do_gpt_basdat) { + if(mkisofs) + sprintf(buf, "-isohybrid-gpt-basdat"); + else + sprintf(buf, "-boot_image isolinux partition_entry=gpt_basdat"); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].do_gpt_hfsplus) { + if(mkisofs) + sprintf(buf, "-isohybrid-gpt-hfsplus"); + else + sprintf(buf, "-boot_image isolinux partition_entry=gpt_hfsplus"); + Xorriso_record_cmd_linE + } + if(et_imgs[idx].do_apm_hfsplus) { + if(mkisofs) + sprintf(buf, "-isohybrid-apm-hfsplus"); + else + sprintf(buf, "-boot_image isolinux partition_entry=apm_hfsplus"); + Xorriso_record_cmd_linE + } + } +after_el_torito: + + ret= 1; +ex: + Xorriso_free_meM(apms); + Xorriso_free_meM(gpts); + Xorriso_free_meM(et_imgs); + Xorriso_free_meM(lines); + Xorriso_free_meM(buf); + return(ret); + +#undef Xorriso_record_cmd_linE + +} + + +/* @param flag bit0= currently not significant: + report is about El Torito rather than System Area + bit1= report -as mkisofsoptions + bit15= dispose cmds +*/ +static int Xorriso_report_to_cmd(struct XorrisO *xorriso, + char **et_lines, int et_line_count, + char **sa_lines, int sa_line_count, + char ***cmds, int *cmd_count, int flag) +{ + int ret= 0, i; + + if(flag & (1 << 15)) + {ret= 1; goto ex;} + *cmds= NULL; + *cmd_count= 0; + + /* Count commands */ + ret= Xorriso_scan_report_lines(xorriso, et_lines, et_line_count, + sa_lines, sa_line_count, *cmds, cmd_count, + 1 | (flag & 2)); + if(ret <= 0) + goto ex; + + if(*cmd_count <= 0) + {ret= 2; goto ex;} + Xorriso_alloc_meM(*cmds, char *, *cmd_count); + for(i= 0; i < *cmd_count; i++) + (*cmds)[i]= NULL; + + /* Record commands */ + ret= Xorriso_scan_report_lines(xorriso, et_lines, et_line_count, + sa_lines, sa_line_count, *cmds, cmd_count, + flag & 2); + if(ret <= 0) + goto ex; + + ret= 1; +ex: + if(ret <= 0 || (flag & (1 << 15))) { + if(*cmds != NULL) { + for(i= 0; i < *cmd_count; i++) + if((*cmds)[i] != NULL) + Xorriso_free_meM((*cmds)[i]); + Xorriso_free_meM(*cmds); + *cmds= NULL; + } + } + return(ret); +} + + + static void Xorriso_report_lines(struct XorrisO *xorriso, char **lines, int line_count) { @@ -1367,18 +2101,25 @@ static void Xorriso_report_lines(struct XorrisO *xorriso, /* @param flag bit0= report El Torito rather than System Area + >>> bit1= with form "cmd" do not report but rather execute */ int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag) { - int ret, line_count; - char **lines = NULL; + int ret, line_count, cmd_count, et_line_count= 0, sa_line_count= 0; + int do_cmd= 0, as_mkisofs= 0; + char **lines = NULL, **et_lines= NULL, **sa_lines= NULL, **cmds= NULL; IsoImage *image; + if(strcmp(form, "cmd") == 0 || strcmp(form, "as_mkisofs") == 0 || (flag & 2)) + do_cmd= 1; + if(strcmp(form, "as_mkisofs") == 0) + as_mkisofs= 1; + if(strcmp(form, "help") == 0) { if(flag & 1) - ret= iso_image_report_el_torito(NULL, &lines, &line_count, 1); + ret= iso_image_report_el_torito(NULL, &et_lines, &et_line_count, 1); else - ret= iso_image_report_system_area(NULL, &lines, &line_count, 1); + ret= iso_image_report_system_area(NULL, &sa_lines, &sa_line_count, 1); if(ret <= 0) goto ex; sprintf(xorriso->result_line, @@ -1395,15 +2136,25 @@ int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag) sprintf(xorriso->result_line, "\n"); Xorriso_result(xorriso, 0); - } else if(strcmp(form, "") == 0 || strcmp(form, "plain") == 0) { + } else if(strcmp(form, "") == 0 || strcmp(form, "plain") == 0 || do_cmd) { ret= Xorriso_get_volume(xorriso, &image, 0); if(ret <= 0) goto ex; - if(flag & 1) - ret= iso_image_report_el_torito(image, &lines, &line_count, 0); - else - ret= iso_image_report_system_area(image, &lines, &line_count, 0); - + if(do_cmd || (flag & 1)) + ret= iso_image_report_el_torito(image, &et_lines, &et_line_count, 0); + if(ret < 0) + goto ex; + if(do_cmd || !(flag & 1)) + ret= iso_image_report_system_area(image, &sa_lines, &sa_line_count, 0); + if(ret < 0) + goto ex; + if(do_cmd) { + ret= Xorriso_report_to_cmd(xorriso, et_lines, et_line_count, + sa_lines, sa_line_count, &cmds, &cmd_count, + (flag & 1) | (as_mkisofs << 1)); + if(ret <= 0) + goto ex; + } } else if(strncmp(form, "gpt_crc_of:", 11) == 0 && !(flag & 1)) { ret = Xorriso_gpt_crc(xorriso, form + 11, 0); goto ex; @@ -1418,31 +2169,47 @@ int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag) } if(ret < 0) goto ex; - if(lines == NULL || ret == 0) { - if(flag & 1) - strcpy(xorriso->info_text, "No El Torito information was loaded"); - else - strcpy(xorriso->info_text, "No System Area was loaded"); - Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0); - ret= 2; goto ex; + if(flag & 1) { + lines= et_lines; + line_count= et_line_count; + } else { + lines= sa_lines; + line_count= sa_line_count; } - if(line_count == 0) { - if(flag & 1) - strcpy(xorriso->info_text, "No El Torito information available"); - else - strcpy(xorriso->info_text, "System Area only contains 0-bytes"); - Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0); - ret= 2; goto ex; + if(!do_cmd) { + if(lines == NULL || ret == 0) { + if(flag & 1) + strcpy(xorriso->info_text, "No El Torito information was loaded"); + else + strcpy(xorriso->info_text, "No System Area was loaded"); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0); + ret= 2; goto ex; + } + if(line_count == 0) { + if(flag & 1) + strcpy(xorriso->info_text, "No El Torito information available"); + else + strcpy(xorriso->info_text, "System Area only contains 0-bytes"); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0); + ret= 2; goto ex; + } + } + if(flag & 2) { + + /* >>> execute commands */; + + } else if(do_cmd) { + Xorriso_report_lines(xorriso, cmds, cmd_count); + } else { + Xorriso_report_lines(xorriso, lines, line_count); } - Xorriso_report_lines(xorriso, lines, line_count); ret= 1; ex:; - if(lines != NULL) { - if(flag & 1) - iso_image_report_el_torito(NULL, &lines, &line_count, 1 << 15); - else - iso_image_report_system_area(NULL, &lines, &line_count, 1 << 15); - } + Xorriso_report_to_cmd(xorriso, NULL, 0, NULL, 0, &cmds, &cmd_count, 1 << 15); + if(et_lines != NULL) + iso_image_report_el_torito(NULL, &et_lines, &et_line_count, 1 << 15); + if(sa_lines != NULL) + iso_image_report_system_area(NULL, &sa_lines, &sa_line_count, 1 << 15); return(ret); } diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index f4842e09..906db953 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2014.10.03.180649" +#define Xorriso_timestamP "2014.10.28.140220"