"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.6/xorriso/iso_img.c" (28 Dec 2022, 107310 Bytes) of package /linux/misc/libisoburn-1.5.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "iso_img.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.4_vs_1.5.6.

    1 
    2 /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
    3 
    4    Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
    5 
    6    Provided under GPL version 2 or later.
    7 
    8    This file contains functions which operate on ISO images and their
    9    global properties.
   10 */
   11 
   12 #ifdef HAVE_CONFIG_H
   13 #include "../config.h"
   14 #endif
   15 
   16 #include <ctype.h>
   17 #include <sys/types.h>
   18 #include <unistd.h>
   19 #include <stdlib.h>
   20 #include <stdio.h>
   21 #include <string.h>
   22 #include <sys/stat.h>
   23 #include <sys/time.h>
   24 #include <time.h>
   25 #include <errno.h>
   26 
   27 #include <sys/wait.h>
   28 
   29 #include "xorriso.h"
   30 #include "xorriso_private.h"
   31 #include "xorrisoburn.h"
   32 
   33 #include "lib_mgt.h"
   34 #include "iso_img.h"
   35 #include "iso_tree.h"
   36 #include "drive_mgt.h"
   37 
   38 
   39 int Xorriso_set_ignore_aclea(struct XorrisO *xorriso, int flag)
   40 {
   41  int ret, hflag;
   42  IsoImage *volume;
   43 
   44  ret= Xorriso_get_volume(xorriso, &volume, 1); 
   45  if(ret<=0)
   46    return(ret);
   47  hflag= (~xorriso->do_aaip) & 1;
   48  if((xorriso->ino_behavior & (1 | 2)) && !(xorriso->do_aaip & (4 | 16)))
   49    hflag|= 2; 
   50  if(xorriso->do_aaip & 1024)
   51    hflag|= 8;
   52  iso_image_set_ignore_aclea(volume, hflag);
   53  return(1);
   54 }
   55 
   56 
   57 int Xorriso_update_volid(struct XorrisO *xorriso, int flag)
   58 {
   59  int gret, sret= 1;
   60 
   61  gret= Xorriso_get_volid(xorriso, xorriso->loaded_volid, 0);
   62  if(gret<=0 || (!xorriso->volid_default) || xorriso->loaded_volid[0]==0)
   63    sret= Xorriso_set_volid(xorriso, xorriso->volid, 1);
   64  return(gret>0 && sret>0);
   65 } 
   66  
   67 
   68 int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
   69 {
   70  int ret;
   71  IsoImage *volset;
   72  struct isoburn_read_opts *ropts;
   73  struct burn_drive_info *dinfo= NULL;
   74  struct burn_drive *drive= NULL;
   75 
   76  if(xorriso->out_drive_handle != NULL) {
   77    ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
   78                                   "on attempt to attach volset to drive", 2);
   79    if(ret<=0)
   80      return(ret);
   81  }
   82  if(xorriso->in_volset_handle!=NULL) {
   83    iso_image_unref((IsoImage *) xorriso->in_volset_handle);
   84    xorriso->in_volset_handle= NULL;
   85    Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
   86    Xorriso_destroy_di_array(xorriso, 0);
   87    Xorriso_destroy_hln_array(xorriso, 0);
   88    xorriso->loaded_volid[0]= 0;
   89    xorriso->volset_change_pending= 0;
   90    xorriso->boot_count= 0;
   91    xorriso->no_volset_present= 0;
   92  }
   93 
   94  ret= isoburn_ropt_new(&ropts, 0);
   95  if(ret<=0)
   96    return(ret);
   97  /* Note: no return before isoburn_ropt_destroy() */
   98  isoburn_ropt_set_extensions(ropts, isoburn_ropt_pretend_blank);
   99  isoburn_ropt_set_input_charset(ropts, xorriso->in_charset);
  100  isoburn_ropt_set_data_cache(ropts, 1, 1, 0);
  101  isoburn_set_read_pacifier(drive, NULL, NULL);
  102  isoburn_ropt_set_truncate_mode(ropts, 1, xorriso->file_name_limit);
  103 
  104  ret= isoburn_read_image(drive, ropts, &volset);
  105  Xorriso_process_msg_queues(xorriso,0);
  106  isoburn_ropt_destroy(&ropts, 0);
  107  if(ret<=0) {
  108    sprintf(xorriso->info_text, "Failed to create new empty ISO image object");
  109    Xorriso_report_iso_error(xorriso, "", ret, xorriso->info_text, 0, "FATAL",
  110                             0);
  111    return(-1);
  112  }
  113  xorriso->in_volset_handle= (void *) volset;
  114  xorriso->in_sector_map= NULL;
  115  Xorriso_update_volid(xorriso, 0);
  116  xorriso->volset_change_pending= 0;
  117  xorriso->boot_count= 0;
  118  xorriso->system_area_clear_loaded=
  119                     (strcmp(xorriso->system_area_disk_path, "/dev/zero") == 0);
  120  xorriso->no_volset_present= 0;
  121  return(1);
  122 }
  123 
  124 
  125 int Xorriso_record_boot_info(struct XorrisO *xorriso, int flag)
  126 {
  127  int ret;
  128  struct burn_drive_info *dinfo;
  129  struct burn_drive *drive;
  130  IsoImage *image;
  131  ElToritoBootImage *bootimg;
  132  IsoFile *bootimg_node;
  133  IsoBoot *bootcat_node;
  134 
  135  xorriso->loaded_boot_bin_lba= -1;
  136  xorriso->loaded_boot_cat_path[0]= 0;
  137  ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
  138                                 "on attempt to record boot LBAs", 0);
  139  if(ret<=0)
  140    return(0);
  141  image= isoburn_get_attached_image(drive);
  142  if(image == NULL)
  143    return(0);
  144  ret= iso_image_get_boot_image(image, &bootimg,
  145                                &bootimg_node, &bootcat_node);
  146  iso_image_unref(image); /* release obtained reference */
  147  if(ret != 1)
  148    return(0);
  149  if(bootimg_node != NULL)
  150    Xorriso__file_start_lba((IsoNode *) bootimg_node,
  151                            &(xorriso->loaded_boot_bin_lba), 0);
  152  if(bootcat_node != NULL)
  153    Xorriso_path_from_lba(xorriso, (IsoNode *) bootcat_node, 0,
  154                          xorriso->loaded_boot_cat_path, 0);
  155  return(1);
  156 }
  157 
  158 
  159 int Xorriso_assert_volid(struct XorrisO *xorriso, int msc1, int flag)
  160 {
  161  int ret, image_blocks;
  162  char volid[33];
  163  struct burn_drive_info *dinfo;
  164  struct burn_drive *drive;
  165 
  166  if(xorriso->assert_volid[0] == 0)
  167    return(1);
  168  ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
  169                                 "on attempt to perform -assert_volid", 0);
  170  if(ret<=0)
  171    return(0);
  172  ret= isoburn_read_iso_head(drive, msc1, &image_blocks, volid, 1);
  173  Xorriso_process_msg_queues(xorriso,0);
  174  if(ret <= 0) {
  175    sprintf(xorriso->info_text,
  176            "-assert_volid: Cannot determine Volume Id at LBA %d.", msc1);
  177    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
  178                        xorriso->assert_volid_sev, 0);
  179    return(0);
  180  }
  181  ret= Sregex_match(xorriso->assert_volid, volid, 0);
  182  if(ret < 0)
  183    return(2);
  184  if(ret == 0) {
  185    strcpy(xorriso->info_text,
  186           "-assert_volid: Volume id does not match pattern: ");
  187    Text_shellsafe(xorriso->assert_volid, xorriso->info_text, 1);
  188    strcat(xorriso->info_text, " <> ");
  189    Text_shellsafe(volid, xorriso->info_text, 1);
  190    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
  191                        xorriso->assert_volid_sev, 0);
  192    return(0);
  193  }
  194  return(ret);
  195 }
  196 
  197 
  198 /* @return <0 yes , 0 no , <0 error */
  199 int Xorriso_is_isohybrid(struct XorrisO *xorriso, IsoFile *bootimg_node,
  200                          int flag)
  201 {
  202  int ret;
  203  unsigned char buf[68];
  204  void *data_stream= NULL;
  205 
  206  ret= Xorriso_iso_file_open(xorriso, "", (void *) bootimg_node,
  207                             &data_stream, 1);
  208  if(ret <= 0)
  209    return(-1);
  210  ret= Xorriso_iso_file_read(xorriso, data_stream, (char *) buf, 68, 0);
  211  Xorriso_iso_file_close(xorriso, &data_stream, 0);
  212  if(ret <= 0)
  213    return(0);
  214  if(buf[64] == 0xfb && buf[65] == 0xc0 && buf[66] == 0x78 && buf[67] == 0x70)
  215    return(1);
  216  return(0);
  217 }
  218 
  219 
  220 int Xorriso_image_has_md5(struct XorrisO *xorriso, int flag)
  221 {
  222  int ret;
  223  IsoImage *image;
  224  uint32_t start_lba, end_lba;
  225  char md5[16];
  226 
  227  ret= Xorriso_get_volume(xorriso, &image, 0);
  228  if(ret<=0)
  229    return(ret);
  230  ret= iso_image_get_session_md5(image, &start_lba, &end_lba, md5, 0);
  231  Xorriso_process_msg_queues(xorriso,0);
  232  if(ret <= 0)
  233    return(0);
  234  return(1);
  235 }
  236 
  237 
  238 static const char *un0(const char *text)
  239 {
  240  if(text == NULL)
  241    return("");
  242  return(text);
  243 }
  244 
  245 
  246 static int Xorriso_report_pvd_time(struct XorrisO *xorriso, char *head,
  247                                    char *pvd_time, int flag)
  248 {
  249  char *msg, hr[17];
  250  int at;
  251 
  252  msg= xorriso->result_line;
  253  strncpy(hr, pvd_time, 16);
  254  hr[16]= 0;
  255  sprintf(msg, "%s %s\n", head, hr);
  256  Xorriso_result(xorriso,0);
  257  if(pvd_time[16] != 0) {
  258    at= abs(pvd_time[16]);
  259    sprintf(msg, "%2.2s. Time Zone: %c%-2.2d:%-2.2d\n", head,
  260            pvd_time[16] > 0 ? '+' : '-', at / 4, (at - (at / 4) * 4) * 15);
  261    Xorriso_result(xorriso,0);
  262  }
  263  return(1);
  264 }
  265 
  266 
  267 int Xorriso_pvd_info(struct XorrisO *xorriso, int flag)
  268 {
  269  int ret, msc1= -1, msc2, i;
  270  IsoImage *image;
  271  struct burn_drive_info *dinfo;
  272  struct burn_drive *drive;
  273  char *msg, block_head[8], *crt, *mdt, *ext, *eft;
  274  off_t head_count;
  275 
  276  msg= xorriso->result_line;
  277  ret= Xorriso_get_volume(xorriso, &image, 0);
  278  if(ret<=0)
  279    return(ret);
  280  ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive, "", 16);
  281  if(ret > 0) {
  282    ret= Xorriso_msinfo(xorriso, &msc1, &msc2, 1 | 4);
  283    if(ret<0)
  284      return(ret);
  285    Xorriso_toc(xorriso, 128);
  286    if(msc1 >= 0) {
  287      for(i = msc1 + 16; i < msc1 + 32; i++) {
  288        ret= burn_read_data(drive, (off_t) i * (off_t) 2048, block_head,
  289                            (off_t) sizeof(block_head), &head_count, 2);
  290        if(ret <= 0) {
  291          i= msc1 + 32;
  292      break;
  293        }
  294        if(block_head[0] == 1 && strncmp(block_head + 1, "CD001", 5) == 0)
  295      break;
  296      }
  297      if(i < msc1 + 32) {
  298        sprintf(msg, "PVD address  : %ds\n", i);
  299        Xorriso_result(xorriso,0);
  300      }
  301    }
  302  }
  303  sprintf(msg, "Volume Id    : %s\n", un0(iso_image_get_volume_id(image)));
  304  Xorriso_result(xorriso,0);
  305  sprintf(msg, "Volume Set Id: %s\n", xorriso->volset_id);
  306  Xorriso_result(xorriso,0);
  307  sprintf(msg, "Publisher Id : %s\n", xorriso->publisher);
  308  Xorriso_result(xorriso,0);
  309  sprintf(msg, "Preparer Id  : %s\n",
  310          un0(iso_image_get_data_preparer_id(image)));
  311  Xorriso_result(xorriso,0);
  312  sprintf(msg, "App Id       : %s\n", xorriso->application_id);
  313  Xorriso_result(xorriso,0);
  314  sprintf(msg, "System Id    : %s\n", xorriso->system_id);
  315  Xorriso_result(xorriso,0);
  316  sprintf(msg, "CopyrightFile: %s\n", xorriso->copyright_file);
  317  Xorriso_result(xorriso,0);
  318  sprintf(msg, "Abstract File: %s\n", xorriso->abstract_file);
  319  Xorriso_result(xorriso,0);
  320  sprintf(msg, "Biblio File  : %s\n", xorriso->biblio_file);
  321  Xorriso_result(xorriso,0);
  322 
  323  ret= iso_image_get_pvd_times(image, &crt, &mdt, &ext, &eft);
  324  if(ret != ISO_SUCCESS)
  325    crt= mdt= ext= eft= "                "; /* Need 17 bytes. Last byte 0. */
  326  Xorriso_report_pvd_time(xorriso, "Creation Time:", crt, 0);
  327  Xorriso_report_pvd_time(xorriso, "Modif. Time  :", mdt, 0);
  328  Xorriso_report_pvd_time(xorriso, "Expir. Time  :", ext, 0);
  329  Xorriso_report_pvd_time(xorriso, "Eff. Time    :", eft, 0);
  330  return(1);
  331 }
  332 
  333 
  334 /* @param flag bit0= do not mark image as changed */
  335 int Xorriso_set_volid(struct XorrisO *xorriso, char *volid, int flag)
  336 {
  337  int ret;
  338  IsoImage *volume;
  339 
  340  if(xorriso->in_volset_handle == NULL)
  341    return(2);
  342  ret= Xorriso_get_volume(xorriso, &volume, 0);
  343  if(ret<=0)
  344    return(ret);
  345  if(iso_image_get_volume_id(volume) == NULL ||
  346     strcmp(iso_image_get_volume_id(volume), volid) != 0)
  347    if(!(flag&1))
  348      Xorriso_set_change_pending(xorriso, 1);
  349  iso_image_set_volume_id(volume, volid);
  350  Xorriso_process_msg_queues(xorriso,0);
  351  sprintf(xorriso->info_text,"Volume ID: '%s'",iso_image_get_volume_id(volume));
  352  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
  353  return(1);
  354 }
  355 
  356 
  357 int Xorriso_get_volid(struct XorrisO *xorriso, char volid[33], int flag)
  358 {
  359  int ret;
  360  IsoImage *volume;
  361 
  362  ret= Xorriso_get_volume(xorriso, &volume, 0);
  363  if(ret<=0)
  364    return(ret);
  365  strncpy(volid, iso_image_get_volume_id(volume), 32);
  366  volid[32]= 0;
  367  return(1);
  368 }
  369 
  370 
  371 /* 
  372  bit0= do only report non-default settings
  373  bit1= do only report to fp
  374  bit2= is_default
  375  bit3= append -boot_image any next
  376  bit4= concentrate boot options
  377  bit5= override load_size by "full"
  378 */
  379 int Xorriso_boot_item_status(struct XorrisO *xorriso, char *cat_path,
  380                              char *bin_path, int platform_id,
  381                              int patch_isolinux, int emul, off_t load_size,
  382                              unsigned char *id_string,
  383                              unsigned char *selection_crit, char *form,
  384                              char *filter, FILE *fp, int flag)
  385 {
  386  int is_default, no_defaults, i, is_default_id= 0, ret;
  387  char *line, *bspec= NULL, zeros[28], *partition_entry;
  388  off_t file_size;
  389  struct stat stbuf;
  390 
  391  Xorriso_alloc_meM(bspec, char, SfileadrL + 80);
  392 
  393  no_defaults= flag & 1;
  394  line= xorriso->result_line;
  395  if(flag & 32)
  396    load_size= -1;
  397 
  398  if((flag & 16) && bin_path[0] != 0) {
  399    /* Concentrate boot options. */
  400    memset(zeros, 0, 28);
  401    if(memcmp(id_string, zeros, 28) == 0 &&
  402       memcmp(selection_crit, zeros, 20) == 0)
  403      is_default_id= 1;
  404 
  405    /* -boot_image isolinux dir= ... */
  406    bspec[0]= 0;
  407    if(strcmp(form, "isolinux") != 0 && strcmp(form, "any") != 0)
  408      ;
  409    else if(strcmp(bin_path, "/isolinux.bin") == 0 &&
  410       strcmp(cat_path, "/boot.cat") == 0)
  411      strcpy(bspec, "dir=/");
  412    else if(strcmp(bin_path, "/isolinux/isolinux.bin") == 0 &&
  413            strcmp(cat_path, "/isolinux/boot.cat") == 0)
  414      strcpy(bspec, "dir=/isolinux");
  415    else if(strcmp(xorriso->boot_image_bin_path,
  416                   "/boot/isolinux/isolinux.bin") == 0
  417            && strcmp(xorriso->boot_image_cat_path,
  418                      "/boot/isolinux/boot.cat") == 0)
  419      strcpy(bspec, "dir=/boot/isolinux");
  420    memset(zeros, 0, 28);
  421    if(bspec[0] && platform_id == 0 && (patch_isolinux & 0x3ff) == 1 &&
  422       load_size == 2048 && is_default_id && emul == 0) {
  423      sprintf(line, "-boot_image isolinux %s\n", bspec);
  424      Xorriso_status_result(xorriso,filter,fp,flag&2); 
  425      {ret= 1; goto ex;};
  426    }
  427 
  428    file_size= 0;
  429    if(strncmp(bin_path, "--interval:appended_partition_", 30) == 0) {
  430      ret= -1;
  431    } else {
  432      ret= Xorriso_iso_lstat(xorriso, bin_path, &stbuf, 2 | 4);
  433    }
  434    if(ret == 0) {
  435      file_size= ((stbuf.st_size / (off_t) 512) +
  436                 !!(stbuf.st_size % (off_t) 512)) * 512;
  437      if(flag & 32)
  438        load_size= file_size * 512;
  439    }
  440    if(platform_id == 0xef && (patch_isolinux & 0x3ff) == 0 &&
  441       load_size / 512 == file_size && is_default_id && emul == 0) {
  442      sprintf(line, "-boot_image any efi_path=");
  443      Text_shellsafe(bin_path, line, 1);
  444      strcat(line, "\n");
  445      Xorriso_status_result(xorriso,filter,fp,flag&2);
  446      {ret= 1; goto ex;};
  447    }
  448  }
  449 
  450  is_default= (bin_path[0] == 0) || (flag & 4);
  451  sprintf(line, "-boot_image %s bin_path=", form);
  452  Text_shellsafe(bin_path, line, 1);
  453  strcat(line, "\n");
  454  if(!(is_default && no_defaults))
  455    Xorriso_status_result(xorriso,filter,fp,flag&2);
  456 
  457  is_default= (emul == 0);
  458  sprintf(line, "-boot_image %s emul_type=%s\n",
  459       form, emul == 2 ? "diskette" : emul == 1 ? "hard_disk" : "no_emulation");
  460  if(!(is_default && no_defaults))
  461    Xorriso_status_result(xorriso,filter,fp,flag&2);
  462  
  463  is_default= (platform_id == 0 || (flag & 4));
  464  sprintf(line, "-boot_image %s platform_id=0x%-2.2x\n", form, platform_id);
  465  if(!(is_default && no_defaults))
  466    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  467 
  468  is_default= ((patch_isolinux & 1) == 0 || bin_path[0] == 0 || (flag & 4));
  469  sprintf(line, "-boot_image %s boot_info_table=%s\n",
  470                (patch_isolinux & 2) ? "grub" : form,
  471                (patch_isolinux & 1) ? "on" : "off");
  472  if(!(is_default && no_defaults))
  473    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  474  
  475  is_default= ((patch_isolinux & 512) == 0 || bin_path[0] == 0 || (flag & 4));
  476  sprintf(line, "-boot_image grub grub2_boot_info=%s\n",
  477                (patch_isolinux & 512) ? "on" : "off");
  478  if(!(is_default && no_defaults))
  479    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  480  
  481  if(flag & 32) {
  482    is_default= 0;
  483    sprintf(line, "-boot_image %s load_size=full", form);
  484  } else {
  485    is_default= (load_size == 2048 || (flag & 4));
  486    sprintf(line, "-boot_image %s load_size=%lu\n",
  487            form, (unsigned long) load_size);
  488  }
  489  if(!(is_default && no_defaults))
  490    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  491 
  492  is_default= 1;
  493  if(!(flag & 4))
  494    for(i= 0; i < 20; i++)
  495      if(selection_crit[i])
  496        is_default= 0;
  497  sprintf(line, "-boot_image %s sel_crit=", form);
  498  for(i= 0; i < 20; i++)
  499    sprintf(line + strlen(line), "%-2.2X", (unsigned int) selection_crit[i]);
  500  strcat(line, "\n");
  501  if(!(is_default && no_defaults))
  502    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  503 
  504  is_default= 1;
  505  if(!(flag & 4))
  506    for(i= 0; i < 28; i++)
  507      if(id_string[i])
  508        is_default= 0;
  509  sprintf(line, "-boot_image %s id_string=", form);
  510  for(i= 0; i < 28; i++)
  511    sprintf(line + strlen(line), "%-2.2X", (unsigned int) id_string[i]);
  512  strcat(line, "\n");
  513  if(!(is_default && no_defaults))
  514    Xorriso_status_result(xorriso,filter,fp,flag&2); 
  515 
  516  is_default= 1;
  517  partition_entry= "";
  518  if((patch_isolinux & 0x0fc) == (1 << 2))
  519    partition_entry= "gpt_basdat";
  520  else if((patch_isolinux & 0x0fc) == (2 << 2))
  521    partition_entry= "gpt_hfsplus";
  522  if(partition_entry[0]) {
  523    sprintf(line, "-boot_image isolinux partition_entry=%s\n", partition_entry);
  524    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  525    is_default= 0;
  526  }
  527  if(patch_isolinux & (1 << 8)) {
  528    sprintf(line, "-boot_image isolinux partition_entry=apm_hfsplus\n");
  529    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  530    is_default= 0;
  531  }
  532  if(is_default && !no_defaults) {
  533    sprintf(line, "-boot_image isolinux partition_entry=off\n");
  534    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  535  }
  536  
  537  ret= 1; 
  538 ex:;
  539  Xorriso_free_meM(bspec);
  540  return(ret); 
  541 }
  542 
  543 
  544 int Xorriso_status_hppa(struct XorrisO *xorriso, char *what, char *value,
  545                         char *filter, FILE *fp, int flag)
  546 {
  547  char *line;
  548 
  549  line= xorriso->result_line;
  550  if(value == NULL)
  551    return(1);
  552  sprintf(line, "-boot_image any hppa_%s=", what);
  553  Text_shellsafe(value, line, 1);
  554  strcat(line, "\n");
  555  Xorriso_status_result(xorriso, filter, fp, flag & 2);
  556  return(1);
  557 }
  558 
  559 
  560 /* 
  561  bit0= do only report non-default settings
  562  bit1= do only report to fp
  563 */
  564 int Xorriso_boot_status_non_mbr(struct XorrisO *xorriso, IsoImage *image,
  565                                 char *filter, FILE *fp, int flag)
  566 {
  567  int i, num_boots, sa_type;
  568  char *paths[15], *line;
  569  int ret;
  570  char num[4];
  571  char *cmdline, *bootloader, *kernel_32, *kernel_64, *ramdisk;
  572 
  573  line= xorriso->result_line;
  574 
  575  sa_type= (xorriso->system_area_options & 0xfc) >> 2;
  576  if(sa_type == 3) {
  577    sprintf(line, "-boot_image any sparc_label=");
  578    Text_shellsafe(xorriso->ascii_disc_label, line, 1);
  579    strcat(line, "\n");
  580    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  581    sprintf(line, "-boot_image grub grub2_sparc_core=");
  582    Text_shellsafe(xorriso->grub2_sparc_core, line, 1);
  583    strcat(line, "\n");
  584    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  585    return(0);
  586  } else if(sa_type == 1 || sa_type == 2) {
  587    num_boots= iso_image_get_mips_boot_files(image, paths, 0);
  588    Xorriso_process_msg_queues(xorriso, 0);
  589    if(num_boots > 0) {
  590      if(sa_type == 2)
  591        num_boots= 1;
  592      for(i= 0; i < num_boots; i++) {
  593        sprintf(line, "-boot_image any mips%s_path=", sa_type ==2 ? "el" : "");
  594        Text_shellsafe(paths[i], line, 1);
  595        strcat(line, "\n");
  596        Xorriso_status_result(xorriso, filter, fp, flag & 2);
  597      }
  598    }
  599    return(num_boots);
  600  } else if(sa_type == 4 || sa_type == 5) {
  601    ret= iso_image_get_hppa_palo(image, &cmdline, &bootloader, &kernel_32,
  602                                 &kernel_64, &ramdisk);
  603    if(ret == 1) {
  604      Xorriso_status_hppa(xorriso, "cmdline", cmdline, filter, fp, 0);
  605      Xorriso_status_hppa(xorriso, "bootloader", bootloader, filter, fp, 0);
  606      Xorriso_status_hppa(xorriso, "kernel_32", kernel_32, filter, fp, 0);
  607      Xorriso_status_hppa(xorriso, "kernel_64", kernel_64, filter, fp, 0);
  608      Xorriso_status_hppa(xorriso, "ramdisk", ramdisk, filter, fp, 0);
  609      sprintf(num, "%d", sa_type);
  610      Xorriso_status_hppa(xorriso, "hdrversion", num, filter, fp, 0);
  611    }
  612    return(0);
  613  } else if(sa_type == 6) {
  614    ret= iso_image_get_alpha_boot(image, &bootloader);
  615    if (ret == 1 && bootloader != NULL) {
  616      sprintf(line, "-boot_image any alpha_boot=");
  617      Text_shellsafe(bootloader, line, 1);
  618      strcat(line, "\n");
  619      Xorriso_status_result(xorriso, filter, fp, flag & 2);
  620    }
  621    return(0);
  622  }
  623  return(0);
  624 }
  625 
  626 
  627 /* 
  628  bit0= do only report non-default settings
  629  bit1= do only report to fp
  630 */
  631 int Xorriso_append_part_status(struct XorrisO *xorriso, IsoImage *image,
  632                              char *filter, FILE *fp, int flag)
  633 {
  634  int i, l, is_default;
  635 
  636  is_default= (xorriso->appended_as_gpt == 0);
  637  sprintf(xorriso->result_line, "-boot_image any appended_part_as=%s\n",
  638          xorriso->appended_as_gpt ? "gpt" : "mbr");
  639  if(!(is_default && (flag & 1)))
  640    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  641  for(i= 0; i < Xorriso_max_appended_partitionS; i++) {
  642    if(xorriso->appended_partitions[i] == NULL)
  643  continue;
  644    sprintf(xorriso->result_line, "-append_partition %d ", i + 1);
  645    l= strlen(xorriso->result_line);
  646    if(xorriso->appended_part_gpt_flags[i] & 1) {
  647      Xorriso__format_guid(xorriso->appended_part_type_guids[i],
  648                           xorriso->result_line + l, 0);
  649      strcpy(xorriso->result_line + l + 32, " ");
  650    } else {
  651      sprintf(xorriso->result_line + l, "0x%2.2x ",
  652              (unsigned int) xorriso->appended_part_types[i]);
  653    }
  654    Text_shellsafe(xorriso->appended_partitions[i], xorriso->result_line, 1);
  655    strcat(xorriso->result_line, "\n");
  656    Xorriso_status_result(xorriso, filter, fp, flag & 2);
  657  }
  658  return(1);
  659 }
  660 
  661 
  662 /* 
  663  bit0= do only report non-default settings
  664  bit1= do only report to fp
  665 */
  666 int Xorriso_boot_image_status(struct XorrisO *xorriso, char *filter, FILE *fp,
  667                               int flag)
  668 {
  669  int ret, i, num_boots, hflag;
  670  int is_default, no_defaults;
  671  char *path= NULL, *form= "any", *line, *hpt;
  672  struct burn_drive_info *dinfo;
  673  struct burn_drive *drive;
  674  IsoImage *image= NULL;
  675  ElToritoBootImage **boots = NULL;
  676  IsoFile **bootnodes = NULL;
  677  int platform_id, patch, load_size;
  678  enum eltorito_boot_media_type media_type;
  679  unsigned char id_string[29], sel_crit[21];
  680 
  681  Xorriso_alloc_meM(path, char, SfileadrL);
  682  line= xorriso->result_line;
  683  no_defaults= flag & 1;
  684 
  685  ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
  686                                 "on attempt to print boot info", 2 | 16);
  687  if(ret<=0)
  688    goto no_image;
  689  image= isoburn_get_attached_image(drive);
  690  Xorriso_process_msg_queues(xorriso,0);
  691  if(image == NULL) 
  692    goto no_image;
  693  
  694  ret= Xorriso_boot_status_non_mbr(xorriso, image, filter, fp, flag & 3);
  695  if(ret < 0) /* == 0 is normal */
  696    {ret= 0; goto ex;}
  697 
  698  if(xorriso->boot_count == 0 && xorriso->boot_image_bin_path[0] == 0) {
  699 no_image:;
  700    if(xorriso->patch_isolinux_image & 1) {
  701      sprintf(line, "-boot_image %s patch\n",
  702              xorriso->patch_isolinux_image & 2 ? "grub" : form);
  703      is_default= 0;
  704    } else if(xorriso->keep_boot_image) {
  705      sprintf(line, "-boot_image %s keep\n", form);
  706      is_default= 0;
  707    } else {
  708      sprintf(line, "-boot_image %s discard\n", form);
  709      is_default= 1;
  710    }
  711    if(!(is_default && no_defaults))
  712       Xorriso_status_result(xorriso,filter,fp,flag&2); 
  713    goto report_open_item;
  714  }
  715 
  716  is_default= (xorriso->boot_image_cat_path[0] == 0);
  717  sprintf(line,"-boot_image %s cat_path=", form);
  718  Text_shellsafe(xorriso->boot_image_cat_path, line, 1);
  719  strcat(line, "\n");
  720  if(!(is_default && no_defaults))
  721    Xorriso_status_result(xorriso,filter,fp,flag&2);
  722 
  723  is_default= !xorriso->boot_image_cat_hidden;
  724  hpt= Xorriso__hide_mode_text(xorriso->boot_image_cat_hidden & 63, 0);
  725  if(hpt != NULL)
  726    sprintf(line, "-boot_image %s cat_hidden=%s\n", form, hpt);
  727  Xorriso_free_meM(hpt);
  728  if(!(is_default && no_defaults))
  729    Xorriso_status_result(xorriso,filter,fp,flag&2);
  730 
  731  if(xorriso->boot_count > 0) {
  732 
  733    /* show attached boot image info */;
  734 
  735    ret= iso_image_get_all_boot_imgs(image, &num_boots, &boots, &bootnodes, 0);
  736    Xorriso_process_msg_queues(xorriso,0);
  737    if(ret == 1 && num_boots > 0) {
  738      for(i= 0; i < num_boots; i++) {
  739        ret= Xorriso_path_from_node(xorriso, (IsoNode *) bootnodes[i], path, 0);
  740        if(ret <= 0)
  741     continue;
  742        platform_id= el_torito_get_boot_platform_id(boots[i]);
  743        patch= el_torito_get_isolinux_options(boots[i], 0);
  744        el_torito_get_boot_media_type(boots[i], &media_type);
  745        load_size= el_torito_get_load_size(boots[i]) * 512;
  746        el_torito_get_id_string(boots[i], id_string);
  747        el_torito_get_selection_crit(boots[i], sel_crit);
  748        if(media_type == ELTORITO_FLOPPY_EMUL)
  749          media_type= 2;
  750        else if(media_type == ELTORITO_HARD_DISC_EMUL)
  751          media_type= 1;
  752        else
  753          media_type= 0;
  754        ret= Xorriso_boot_item_status(xorriso, xorriso->boot_image_cat_path,
  755                   path, platform_id, patch, media_type,
  756                   load_size, id_string, sel_crit, "any",
  757                   filter, fp, 16 | (flag & 3));
  758        if(ret <= 0)
  759      continue;
  760        sprintf(line,"-boot_image %s next\n", form);
  761        Xorriso_status_result(xorriso,filter,fp,flag&2);
  762      }
  763    }
  764  } 
  765 
  766  /* Show pending boot image info */
  767  if(strcmp(xorriso->boot_image_bin_form, "isolinux") == 0 ||
  768     strcmp(xorriso->boot_image_bin_form, "grub") == 0)
  769    form= xorriso->boot_image_bin_form;
  770 
  771  if(xorriso->boot_count > 0 &&
  772     xorriso->boot_platform_id == 0 &&
  773     xorriso->patch_isolinux_image == 0 &&
  774     xorriso->boot_image_bin_path[0] == 0 &&
  775     xorriso->boot_image_emul == 0 &&
  776     xorriso->boot_image_load_size == 4 * 512) {
  777    for(i= 0; i < 20; i++)
  778      if(xorriso->boot_selection_crit[i])
  779    break;
  780    if(i >= 20)
  781      for(i= 0; i < 28; i++)
  782        if(xorriso->boot_id_string[i])
  783      break;
  784    if(i >= 28)
  785      {ret= 1; goto ex;} /* Images registered, pending is still default */
  786  }
  787 
  788 report_open_item:;
  789  hflag= 16; 
  790  if(xorriso->boot_platform_id == 0xef && !xorriso->boot_efi_default)
  791    hflag= 0;
  792  ret= Xorriso_boot_item_status(xorriso, xorriso->boot_image_cat_path,
  793              xorriso->boot_image_bin_path, xorriso->boot_platform_id,
  794              xorriso->patch_isolinux_image, xorriso->boot_image_emul,
  795              xorriso->boot_image_load_size, xorriso->boot_id_string,
  796              xorriso->boot_selection_crit, form,
  797              filter, fp, hflag | (flag & 3));
  798  if(ret <= 0)
  799    goto ex;
  800 
  801  ret = Xorriso_append_part_status(xorriso, image, filter, fp, flag & 3);
  802  if(ret <= 0)
  803    goto ex;
  804 
  805  ret= 1;
  806 ex:
  807  if(boots != NULL)
  808    free(boots);
  809  if(bootnodes != NULL)
  810    free(bootnodes);
  811  if(image != NULL)
  812    iso_image_unref(image);
  813  Xorriso_free_meM(path);
  814  return(ret);
  815 }
  816 
  817 
  818 int Xorriso__append_boot_params(char *line, ElToritoBootImage *bootimg,
  819                                 int flag)
  820 {
  821  unsigned int platform_id;
  822 
  823  platform_id= el_torito_get_boot_platform_id(bootimg); 
  824  if(platform_id != 0)
  825    sprintf(line + strlen(line),
  826            " , platform_id=0x%-2.2X ", (unsigned int) platform_id);
  827  if(el_torito_seems_boot_info_table(bootimg, 0))
  828    sprintf(line + strlen(line), " , boot_info_table=on");
  829  if(el_torito_seems_boot_info_table(bootimg, 1))
  830    sprintf(line + strlen(line), " , grub2_boot_info=on");
  831  return(1);
  832 }
  833 
  834 
  835 /* @param flag bit0= no output if no boot record was found
  836                bit1= short form
  837                bit3= report to info channel (else to result channel)
  838 */
  839 int Xorriso_show_boot_info(struct XorrisO *xorriso, int flag)
  840 {
  841  int ret, bin_path_valid= 0, i, num_boots, sa_count;
  842  char *respt, *path= NULL, **sa_report= NULL, *sa_summary= NULL;
  843  unsigned char *lb0= NULL;
  844  struct burn_drive_info *dinfo;
  845  struct burn_drive *drive;
  846  IsoImage *image= NULL;
  847  ElToritoBootImage *bootimg, **boots = NULL;
  848  IsoFile *bootimg_node, **bootnodes = NULL;
  849  IsoBoot *bootcat_node;
  850 
  851  Xorriso_alloc_meM(path, char, SfileadrL);
  852  Xorriso_alloc_meM(lb0, unsigned char, 2048);
  853 
  854  respt= xorriso->result_line;
  855 
  856  if(xorriso->boot_count > 0) {
  857    if(!(flag & 1)) {
  858      sprintf(respt, "Boot record  : (overridden by -boot_image any next)\n");
  859      Xorriso_toc_line(xorriso, flag & 8);
  860    }
  861    ret= 1; goto ex;
  862  }
  863 
  864  ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
  865                                 "on attempt to print boot info", 16);
  866  if(ret<=0)
  867    goto no_boot;
  868  image= isoburn_get_attached_image(drive);
  869  if(image == NULL) {
  870    ret= 0;
  871 no_boot:;
  872    if(!(flag & 1)) {
  873      sprintf(respt, "Boot record  : none\n");
  874      Xorriso_toc_line(xorriso, flag & 8);
  875    }
  876    goto ex;
  877  }
  878 
  879  ret= iso_image_report_system_area(image, &sa_report, &sa_count, 0);
  880  if(ret > 0 && sa_report != NULL)
  881    for(i= 0; i < sa_count; i++)
  882      if(strncmp(sa_report[i], "System area summary: ", 21) == 0) {
  883        Xorriso_alloc_meM(sa_summary, char, strlen(sa_report[i] + 21) + 1);
  884        strcpy(sa_summary, sa_report[i] + 21);
  885    break;
  886      }
  887  if(sa_report != NULL)
  888    iso_image_report_system_area(image, &sa_report, &sa_count, 1 << 15);
  889  Xorriso_process_msg_queues(xorriso,0);
  890 
  891  /* Using the nodes with extreme care . They might be deleted meanwhile. */
  892  ret= iso_image_get_boot_image(image, &bootimg, &bootimg_node, &bootcat_node);
  893  if(ret != 1) {
  894    if(sa_summary == NULL)
  895      goto no_boot;
  896    sprintf(respt, "Boot record  : (system area only) , %s\n", sa_summary);
  897    Xorriso_toc_line(xorriso, flag & 8);
  898    ret= 1; goto ex;
  899  }
  900  ret= iso_image_get_all_boot_imgs(image, &num_boots, &boots, &bootnodes, 0);
  901  Xorriso_process_msg_queues(xorriso,0);
  902  if(ret != 1) {
  903    num_boots= 0;
  904  } else {
  905    ret= Xorriso_path_from_node(xorriso, (IsoNode *) bootnodes[0], path, 0);
  906    if(ret > 0)
  907      bin_path_valid= 1;
  908  }
  909  sprintf(respt, "Boot record  : El Torito");
  910  if(sa_summary != NULL)
  911    sprintf(respt + strlen(respt), " , %s", sa_summary);
  912 
  913  strcat(respt, "\n");
  914  Xorriso_toc_line(xorriso, flag & 8);
  915  if(flag & 2)
  916    {ret= 1; goto ex;}
  917 
  918  if(xorriso->loaded_boot_cat_path[0]) {
  919    sprintf(respt, "Boot catalog : ");
  920    Text_shellsafe(xorriso->loaded_boot_cat_path, respt, 1);
  921    strcat(respt, "\n");
  922  } else {
  923    sprintf(respt, "Boot catalog : -not-found-at-load-time-\n");
  924  }
  925  Xorriso_toc_line(xorriso, flag & 8);
  926 
  927  if(bin_path_valid) {
  928    sprintf(respt, "Boot image   : ");
  929    Text_shellsafe(path, respt, 1);
  930  } else if(xorriso->loaded_boot_bin_lba <= 0) {
  931    sprintf(respt, "Boot image   : -not-found-at-load-time-");
  932  } else {
  933    sprintf(respt, "Boot image   : -not-found-any-more-by-lba=%d",
  934            xorriso->loaded_boot_bin_lba);
  935  }
  936  Xorriso__append_boot_params(respt, bootimg, 0);
  937  strcat(respt, "\n");
  938  Xorriso_toc_line(xorriso, flag & 8);
  939 
  940  if(num_boots > 1) {
  941    for(i= 1; i < num_boots; i++) {
  942      ret= Xorriso_path_from_node(xorriso, (IsoNode *) bootnodes[i], path, 0);
  943      if(ret > 0) {
  944        sprintf(respt, "Boot image   : ");
  945        Text_shellsafe(path, respt, 1);
  946      } else
  947        sprintf(respt, "Boot image   : -not-found-any-more-");
  948      Xorriso__append_boot_params(respt, boots[i], 0);
  949      strcat(respt, "\n");
  950      Xorriso_toc_line(xorriso, flag & 8);
  951    }
  952  }
  953  ret= 1;
  954 ex:;
  955  if(boots != NULL)
  956    free(boots);
  957  if(bootnodes != NULL)
  958    free(bootnodes);
  959  if(image != NULL)
  960    iso_image_unref(image); /* release obtained reference */
  961  Xorriso_free_meM(path);
  962  Xorriso_free_meM(lb0);
  963  Xorriso_free_meM(sa_summary);
  964  return(ret);
  965 } 
  966 
  967 
  968 /* @param flag    bit0=silently return 0 if no volume/image is present
  969 */
  970 int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume,
  971                        int flag)
  972 {
  973  *volume= NULL;
  974  if(xorriso->in_volset_handle==NULL) {
  975    if(flag & 1)
  976      return(0);
  977    Xorriso_process_msg_queues(xorriso,0);
  978    sprintf(xorriso->info_text,"No ISO image present.");
  979    if(xorriso->indev[0]==0 && xorriso->outdev[0]==0)
  980      sprintf(xorriso->info_text+strlen(xorriso->info_text),
  981              " No -dev, -indev, or -outdev selected.");
  982    else
  983      sprintf(xorriso->info_text+strlen(xorriso->info_text),
  984              " Possible program error with drive '%s'.", xorriso->indev);
  985 
  986    if(!xorriso->no_volset_present)
  987      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  988    xorriso->no_volset_present= 1;
  989    return(0);
  990  }
  991  *volume= (IsoImage *) xorriso->in_volset_handle;
  992  xorriso->no_volset_present= 0;
  993  return(*volume != NULL);
  994 }
  995 
  996 
  997 /* @param flag bit0= do not return 1 on volset_change_pending != 1
  998 */
  999 int Xorriso_change_is_pending(struct XorrisO *xorriso, int flag)
 1000 {
 1001  if(flag & 1)
 1002    return(xorriso->volset_change_pending == 1);
 1003  return(!!xorriso->volset_change_pending);
 1004 }
 1005 
 1006 
 1007 /* @param flag bit0= do not set hln_change_pending */
 1008 int Xorriso_set_change_pending(struct XorrisO *xorriso, int flag)
 1009 {
 1010  int ret;
 1011  IsoImage *image;
 1012 
 1013  ret= Xorriso_get_volume(xorriso, &image, 1);
 1014  if(ret <= 0)
 1015    return ret;
 1016  /* Do not override mark of -as mkisofs -print-size */
 1017  if(xorriso->volset_change_pending != 2)
 1018     xorriso->volset_change_pending= 1;
 1019  if(!(flag & 1))
 1020    xorriso->hln_change_pending= 1;
 1021  return(1);
 1022 }
 1023 
 1024 
 1025 /**
 1026     @param flag bit0= print mount command to result channel rather than
 1027                       performing it 
 1028                 bit1= do not allow prefixes with cmd
 1029                 bit2= interpret unprefixed cmd as shell:
 1030 */
 1031 int Xorriso_mount(struct XorrisO *xorriso, char *dev, int adr_mode,
 1032                   char *adr_value, char *cmd, int flag)
 1033 {
 1034  int ret, lba, track, session, params_flag= 0, is_safe= 0, is_extra_drive= 0;
 1035  int give_up= 0, mount_chardev= 0, status, aquire_flag= 0;
 1036  char volid[33], *devadr, *mount_command= NULL, *adr_data= NULL, *adr_pt;
 1037  char *dev_path, *libburn_adr= NULL;
 1038  char *dpt, *sysname= "";
 1039  struct stat stbuf;
 1040  struct burn_drive_info *dinfo= NULL;
 1041  struct burn_drive *drive= NULL;
 1042 
 1043  Xorriso_alloc_meM(mount_command, char, SfileadrL);
 1044  Xorriso_alloc_meM(adr_data, char, 163);
 1045  Xorriso_alloc_meM(libburn_adr, char, BURN_DRIVE_ADR_LEN + SfileadrL);
 1046 
 1047  devadr= dev;
 1048  adr_pt= adr_value;
 1049  if(strcmp(dev, "indev") == 0) {
 1050    ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
 1051                                   "on attempt to perform -mount \"indev\"", 0);
 1052    if(ret<=0)
 1053      goto ex;
 1054    dev_path= devadr= xorriso->indev;
 1055    if(strncmp(dev_path, "stdio:", 6) == 0)
 1056      dev_path+= 6;
 1057    else if(strncmp(dev_path, "mmc:", 4) == 0)
 1058      dev_path+= 4;
 1059    if(xorriso->in_drive_handle == xorriso->out_drive_handle)
 1060      give_up= 3;
 1061    else
 1062      give_up= 1;
 1063  } else if(strcmp(dev, "outdev") == 0) {
 1064    ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
 1065                                   "on attempt to perform -mount \"outdev\"", 
 1066                                   2);
 1067    if(ret<=0)
 1068      goto ex;
 1069    dev_path= devadr= xorriso->outdev;
 1070    if(strncmp(dev_path, "stdio:", 6) == 0)
 1071      dev_path+= 6;
 1072    else if(strncmp(dev_path, "mmc:", 4) == 0)
 1073      dev_path+= 4;
 1074    if(xorriso->in_drive_handle == xorriso->out_drive_handle)
 1075      give_up= 3;
 1076    else
 1077      give_up= 2;
 1078  } else {
 1079    is_extra_drive= 1;
 1080    dev_path= dev;
 1081    if(strncmp(dev_path, "stdio:", 6) == 0)
 1082      dev_path+= 6;
 1083    else if(strncmp(dev_path, "mmc:", 4) == 0)
 1084      dev_path+= 4;
 1085 
 1086    /* do only accept regular files and block devices */
 1087    ret= stat(dev_path, &stbuf);
 1088    if(ret == -1) {
 1089      sprintf(xorriso->info_text, "Cannot determine properties of file ");
 1090      Text_shellsafe(dev_path, xorriso->info_text, 1);
 1091      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1092      ret= 0; goto ex;
 1093    }
 1094    ret= System_uname(&sysname, NULL, NULL, NULL, 0);
 1095    if(ret > 0 && strcmp(sysname, "FreeBSD") == 0)
 1096      mount_chardev= 1;
 1097    if(!(S_ISREG(stbuf.st_mode) || (S_ISBLK(stbuf.st_mode) && !mount_chardev)
 1098         || (S_ISCHR(stbuf.st_mode) && !mount_chardev))) {
 1099      sprintf(xorriso->info_text,
 1100              "File object is not suitable as mount device: ");
 1101      Text_shellsafe(dev_path, xorriso->info_text, 1);
 1102      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1103      ret= 0; goto ex;
 1104    }
 1105 
 1106    /* Acquire drive as direct libburn address or via stdio: prefix */
 1107    if(strncmp(dev, "mmc:", 4) == 0)
 1108      ret= burn_drive_convert_fs_adr(dev + 4, libburn_adr);
 1109    else
 1110      ret= burn_drive_convert_fs_adr(dev, libburn_adr);
 1111    Xorriso_process_msg_queues(xorriso,0);
 1112    if(ret < 0)
 1113      {ret= -1; goto ex;}
 1114    if(ret == 0 && strncmp(dev, "stdio:", 6) != 0 &&
 1115       strncmp(dev, "mmc:", 4) != 0)
 1116      sprintf(libburn_adr, "stdio:%s", dev);
 1117    burn_preset_device_open(
 1118            (xorriso->drives_exclusive && !(xorriso->mount_opts_flag & 1)) |
 1119            (xorriso->linux_scsi_dev_family << 2), 0, 0);
 1120    aquire_flag= 1;
 1121    if((xorriso->toc_emulation_flag & 2) && (adr_mode == 3 || adr_mode == 0))
 1122      aquire_flag|= 16; /* -rom_toc_scan emul_off with sbsector or auto */
 1123    if(xorriso->toc_emulation_flag & 4)
 1124      aquire_flag|= 128;
 1125    if(xorriso->toc_emulation_flag & 8)
 1126      aquire_flag|= 512;
 1127    ret= isoburn_drive_aquire(&dinfo, libburn_adr, aquire_flag);
 1128    burn_preset_device_open(1 | (xorriso->linux_scsi_dev_family << 2), 0, 0);
 1129    Xorriso_process_msg_queues(xorriso,0);
 1130    if(ret <= 0)
 1131      {ret= 0; goto ex;}
 1132    drive= dinfo[0].drive;
 1133  }
 1134 
 1135  if(adr_mode == 4 && strlen(adr_pt) <= 80) {
 1136    ret= Xorriso__bourne_to_reg(adr_pt, adr_data, 0);
 1137    if(ret == 1) {
 1138      params_flag|= 4;
 1139      adr_pt= adr_data;
 1140    }
 1141  }
 1142  ret= isoburn_get_mount_params(drive, adr_mode, adr_pt, &lba, &track,
 1143                                &session, volid, params_flag);
 1144  Xorriso_process_msg_queues(xorriso,0);
 1145  if(ret <= 0)
 1146    goto ex;
 1147  if(((session <= 0 || track <= 0) && !(aquire_flag & 16)) || ret == 2) {
 1148    Xorriso_msgs_submit(xorriso, 0,
 1149                 "-mount : Given address does not point to an ISO 9660 session",
 1150                 0, "FAILURE", 0);
 1151    ret= 0; goto ex;
 1152  }
 1153  if(strstr(devadr, "stdio:") == devadr)
 1154    devadr+= 6;
 1155  if(strstr(devadr, "mmc:") == devadr)
 1156    devadr+= 4;
 1157  ret= Xorriso_make_mount_cmd(xorriso, cmd, lba, track, session, volid, devadr,
 1158                           mount_command, (flag & (2 | 4)) | ((flag & 4) << 1));
 1159  if(ret <= 0)
 1160    goto ex;
 1161  if(ret == 2)
 1162    is_safe= 1;
 1163 
 1164  if(is_extra_drive) {
 1165    isoburn_drive_release(drive, 0);
 1166    burn_drive_info_free(dinfo);
 1167    drive= NULL;
 1168  } else if(give_up > 0 && !((flag & 1) || (xorriso->mount_opts_flag & 1))) {
 1169    ret= Xorriso_give_up_drive(xorriso, give_up);
 1170    if(ret <= 0)
 1171      goto ex;
 1172  }
 1173  Xorriso_process_msg_queues(xorriso,0);
 1174 
 1175  sprintf(xorriso->info_text, "Volume id    : ");
 1176  Text_shellsafe(volid, xorriso->info_text, 1);
 1177  strcat(xorriso->info_text, "\n");
 1178  Xorriso_info(xorriso, 0);
 1179  if(flag & 1) {
 1180    sprintf(xorriso->result_line, "%s\n", mount_command);
 1181    Xorriso_result(xorriso,0);
 1182  } else {
 1183    sprintf(xorriso->info_text, "Mount command: %s\n", mount_command);
 1184    Xorriso_info(xorriso, 0);
 1185    if(!is_safe) {
 1186      Xorriso_msgs_submit(xorriso, 0,
 1187   "-mount : Will not perform mount command which stems from command template.",
 1188        0, "SORRY", 0);
 1189      sprintf(xorriso->result_line, "%s\n", mount_command);
 1190      Xorriso_result(xorriso,0);
 1191    } else {
 1192      ret= Xorriso_execv(xorriso, mount_command, 0, NULL, "/bin:/sbin",
 1193                         NULL, NULL, NULL, &status, 1);
 1194      if(WIFEXITED(status) && WEXITSTATUS(status) != 0) {
 1195        sprintf(xorriso->info_text,
 1196                "-mount : mount command failed with exit value %d",
 1197                (int) WEXITSTATUS(status));
 1198        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1199        ret= 0; goto ex;
 1200      }
 1201      sprintf(xorriso->info_text, "\nMounted session %d of device ", session);
 1202      Text_shellsafe(dev_path, xorriso->info_text, 1);
 1203      dpt= strchr(cmd, ':');
 1204      if(dpt == NULL)
 1205        dpt= cmd ;
 1206      else
 1207        dpt++;
 1208      sprintf(xorriso->info_text + strlen(xorriso->info_text), " as directory ");
 1209      Text_shellsafe(dpt, xorriso->info_text, 1);
 1210      strcat(xorriso->info_text, "\n");
 1211      Xorriso_info(xorriso, 0);
 1212    }
 1213  }
 1214  ret= 1;
 1215 ex:;
 1216  if(is_extra_drive && drive != NULL) {
 1217    isoburn_drive_release(drive, 0);
 1218    burn_drive_info_free(dinfo);
 1219    Xorriso_process_msg_queues(xorriso,0);
 1220  }
 1221  Xorriso_free_meM(mount_command);
 1222  Xorriso_free_meM(adr_data);
 1223  Xorriso_free_meM(libburn_adr);
 1224  return(ret);
 1225 }
 1226 
 1227 
 1228 /* @param flag bit0= give up all boot file paths
 1229                bit1= refuse if already a path is added
 1230 */
 1231 int Xorriso_add_mips_boot_file(struct XorrisO *xorriso, char *path, int flag)
 1232 {
 1233  int ret;
 1234  IsoImage *image;
 1235  char *paths[15];
 1236 
 1237  ret= Xorriso_get_volume(xorriso, &image, 0);
 1238  if(ret <= 0)
 1239    return ret;
 1240  if(flag & 1) {
 1241    iso_image_give_up_mips_boot(image, 0);
 1242    Xorriso_process_msg_queues(xorriso,0);
 1243    return(1);
 1244  }
 1245  if(flag & 2) {
 1246    ret= iso_image_get_mips_boot_files(image, paths, 0);
 1247    Xorriso_process_msg_queues(xorriso,0);
 1248    if(ret < 0)
 1249      goto report_error;
 1250    if(ret > 0) {
 1251      Xorriso_msgs_submit(xorriso, 0,
 1252                          "There is already a boot image file registered.",
 1253                          0, "FAILURE", 0);
 1254      return(0);
 1255    }
 1256  }
 1257  ret = iso_image_add_mips_boot_file(image, path, 0);
 1258  Xorriso_process_msg_queues(xorriso,0);
 1259  if (ret < 0) {
 1260 report_error:;
 1261    Xorriso_report_iso_error(xorriso, "", ret,
 1262                             "Error when adding MIPS boot file",
 1263                             0, "FAILURE", 1);
 1264    return(0);
 1265  }
 1266  return(1);
 1267 }
 1268 
 1269 
 1270 /* @param flag bit0= Give up HP-PA boot parameters
 1271 */
 1272 int Xorriso_set_hppa_boot_parm(struct XorrisO *xorriso, char *text, char *what,
 1273                                int flag)
 1274 {
 1275  int ret;
 1276  IsoImage *image;
 1277  char *par[5];
 1278 
 1279  ret= Xorriso_get_volume(xorriso, &image, 0);
 1280  if(ret <= 0)
 1281    return(ret);
 1282  par[0]= par[1]= par[2]= par[3]= par[4]= NULL;
 1283  if(flag & 1) {
 1284    /* Give up HP-PA boot parameters */
 1285    iso_image_set_hppa_palo(image, par[0], par[1], par[2], par[3], par[4],
 1286                            1);
 1287    return(1);
 1288  }
 1289  if(strcmp(what, "cmdline") == 0) {
 1290    par[0]= text;
 1291  } else if(strcmp(what, "bootloader") == 0) {
 1292    par[1]= text;
 1293  } else if(strcmp(what, "kernel_32") == 0 || strcmp(what, "kernel-32") == 0) {
 1294    par[2]= text;
 1295  } else if(strcmp(what, "kernel_64") == 0 || strcmp(what, "kernel-64") == 0) {
 1296    par[3]= text;
 1297  } else if(strcmp(what, "ramdisk") == 0) {
 1298    par[4]= text;
 1299  } else if(strcmp(what, "hdrversion") == 0) {
 1300    if(strcmp(text, "4") == 0) {
 1301      xorriso->system_area_options= (xorriso->system_area_options & ~0xfc) |
 1302                                    (4 << 2);
 1303    } else if(strcmp(text, "5") == 0) {
 1304      xorriso->system_area_options= (xorriso->system_area_options & ~0xfc) |
 1305                                    (5 << 2);
 1306    } else {
 1307      strcpy(xorriso->info_text, "Unsupported HP-PA PALO header version ");
 1308      Text_shellsafe(text, xorriso->info_text, 1);
 1309      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1310      return(0);
 1311    }
 1312    return(1);
 1313  } else {
 1314    strcpy(xorriso->info_text,
 1315           "HP-PA boot parameter name not recognized: hppa_");
 1316    Text_shellsafe(what, xorriso->info_text, 1);
 1317    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1318    return(0);
 1319  }
 1320  ret= iso_image_set_hppa_palo(image, par[0], par[1], par[2], par[3], par[4],
 1321                               0);
 1322  if (ret < 0) {
 1323    Xorriso_report_iso_error(xorriso, "", ret,
 1324                             "Error when adding HP-PA boot parameter",
 1325                             0, "FAILURE", 1);
 1326    return(0);
 1327  }
 1328  return(1);
 1329 }
 1330 
 1331 
 1332 /* @param flag bit0= Give up DEC Alpha boot parameters
 1333 */
 1334 int Xorriso_set_alpha_boot(struct XorrisO *xorriso, char *path, int flag)
 1335 {
 1336  int ret;
 1337  IsoImage *image;
 1338 
 1339  ret= Xorriso_get_volume(xorriso, &image, 0);
 1340  if(ret <= 0)
 1341    return(ret);
 1342  if(flag & 1) {
 1343    /* Give up boot parameters */
 1344    iso_image_set_alpha_boot(image, NULL, 1);
 1345    return(1);
 1346  }
 1347  ret= iso_image_set_alpha_boot(image, path, 0);
 1348  if (ret < 0) {
 1349    Xorriso_report_iso_error(xorriso, "", ret,
 1350                             "Error when adding DEC Alpha boot loader",
 1351                             0, "FAILURE", 1);
 1352    return(0);
 1353  }
 1354  return(1);
 1355 }
 1356  
 1357 
 1358 /* @param flag bit0= do not set xorriso->system_area_options, just check
 1359                bit1= only check for grub2_mbr <-> isolinux partition_table
 1360 */
 1361 int Xorriso_coordinate_system_area(struct XorrisO *xorriso, int sa_type,
 1362                                    int options, char *cmd, int flag)
 1363 {
 1364  int old_type, old_options, new_options;
 1365  static char *type_names[7] = {
 1366       "MBR", "MIPS Big Endian Volume Header", "MIPS Little Endian Boot Block",
 1367       "SUN Disk Label", "HP-PA PALO v4", "HP-PA PALO v5",
 1368       "DEC Alpha SRM Boot Block"};
 1369  static int num_names = 7;
 1370 
 1371  old_type= (xorriso->system_area_options & 0xfc) >> 2;
 1372  old_options= xorriso->system_area_options & 0x3c03;
 1373  new_options= options & 0x3c03;
 1374  if(((options & (1 << 14)) && (xorriso->system_area_options & 2)) ||
 1375     ((options & 2) && (xorriso->system_area_options & (1 << 14))))
 1376    goto reject;
 1377  if(flag & 2)
 1378    return(1);
 1379  if((old_type != 0 || old_options != 0) &&
 1380     (old_type != sa_type || (old_options != 0 && old_options != new_options))){
 1381 reject:;
 1382    sprintf(xorriso->info_text, "%s : First sector already occupied by %s",
 1383            cmd, old_type < num_names ?
 1384                 type_names[old_type] : "other boot facility");
 1385    if(old_type == 0 && (old_options & 2))
 1386      strcat(xorriso->info_text, " for ISOLINUX isohybrid");
 1387    else if (old_type == 0 && (xorriso->system_area_options & (1 << 14))) {
 1388      strcat(xorriso->info_text, " for GRUB2 patching");
 1389      if(old_type == 0 && (old_options & 1))
 1390        strcat(xorriso->info_text, " with partition table");
 1391    } else if(old_type == 0 && (old_options & 1))
 1392      strcat(xorriso->info_text, " for partition table");
 1393    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 1394    goto hint_revoke;
 1395  }
 1396  if(!(flag & 1))
 1397    xorriso->system_area_options= (xorriso->system_area_options & ~0x3cff) |
 1398                                  ((sa_type << 2) & 0xfc) | (options & 0x3c03);
 1399  return(1);
 1400 
 1401 hint_revoke:;
 1402  if(old_type == 0)
 1403    sprintf(xorriso->info_text, "Revokable by -boot_image any discard");
 1404  else if(old_type == 1 || old_type == 2)
 1405    sprintf(xorriso->info_text, "Revokable by -boot_image any mips_discard");
 1406  else if(old_type == 3)
 1407    sprintf(xorriso->info_text, "Revokable by -boot_image any sparc_discard");
 1408  if(old_type < 4)
 1409    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
 1410  return(0);
 1411 }
 1412 
 1413 
 1414 int Xorriso_gpt_crc(struct XorrisO *xorriso, char *path, int flag)
 1415 {
 1416  int ret;
 1417  char *buf = NULL;
 1418  FILE *fp = NULL;
 1419  uint32_t crc;
 1420 
 1421  Xorriso_alloc_meM(buf, char, 32 * 1024);
 1422 
 1423  ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 0);
 1424  if(ret <= 0)
 1425    goto ex;
 1426  ret= fread(buf, 1, 32 * 1024, fp);
 1427  if(ret == 0) {
 1428    strcpy(xorriso->info_text,
 1429           "No bytes readable for GPT CRC from ");
 1430    Text_shellsafe(path, xorriso->info_text, 1);
 1431    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
 1432    ret= 0; goto ex;
 1433  }
 1434  crc= iso_crc32_gpt((unsigned char *) buf, ret, 0);
 1435  sprintf(xorriso->result_line, "0x%8.8x\n", (unsigned int) crc);
 1436  Xorriso_result(xorriso, 0);
 1437  ret= 1;
 1438 ex:;
 1439  if(fp != NULL && fp != stdin)
 1440    fclose(fp);
 1441  Xorriso_free_meM(buf);
 1442  return(ret);
 1443 }
 1444 
 1445 
 1446 static int Xorriso_split_report_line(struct XorrisO *xorriso, char *line,
 1447                                      int num_limit,
 1448                                      char *name, char **contentpt,
 1449                                      double *num, int *num_count,
 1450                                      char **textpt, int flag)
 1451 {
 1452  int i;
 1453  char *spt, *ept, *cpt;
 1454 
 1455  if(strlen(line) < 21) {
 1456 undigestible:
 1457    sprintf(xorriso->info_text,
 1458            "Undigestible report line with -report_* mode cmd: '%s'", line);
 1459    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 1460    return(0);
 1461  }
 1462  if(line[19] != ':')
 1463    goto undigestible;
 1464  strncpy(name, line, 20);
 1465  name[20]= 0;
 1466 
 1467  for(spt= line + 20; *spt == ' '; spt++);
 1468  *textpt= *contentpt= spt;
 1469  *num_count= 0;
 1470  for(i= 0; i < num_limit; i++) {
 1471    /* Get word */
 1472    for(spt= *textpt; *spt == ' '; spt++);
 1473    if(*spt == 0) {
 1474      *textpt= spt;
 1475  break;
 1476    }
 1477    for(ept= spt + 1; *ept != ' ' && *ept != 0; ept++);
 1478    /* Look for decimal number */
 1479    if(ept - spt > 16)
 1480  break;
 1481    for(cpt= spt; cpt < ept; cpt++)
 1482      if(*cpt < '0' || *cpt > '9')
 1483    break;
 1484    if(cpt != ept)
 1485  break;
 1486    sscanf(spt, "%lf", num + *num_count);
 1487    (*num_count)++;
 1488    *textpt= ept;
 1489  }
 1490  /* Set *textpt to next non-blank */
 1491  for(; **textpt == ' '; (*textpt)++);
 1492  return(1);
 1493 }
 1494 
 1495 
 1496 int Xorriso_record_cmd_line(struct XorrisO *xorriso, char *buf,
 1497                             char **cmds, int *cmd_count, int flag)
 1498 {
 1499  int ret;
 1500 
 1501  if(flag & 1) {
 1502    (*cmd_count)++;
 1503    ret= 1; goto ex;
 1504  }
 1505  Xorriso_alloc_meM(cmds[*cmd_count], char, strlen(buf) + 1);
 1506  strcpy(cmds[*cmd_count], buf);
 1507  (*cmd_count)++;
 1508  ret= 1;
 1509 ex:;
 1510  return(ret);
 1511 }
 1512 
 1513 
 1514 /* @param flag bit0= zeroize MBR partition table
 1515                bit1= zeroize GPT
 1516                bit2= zeroize APM
 1517               bit30= Source imported_iso rather than local_fs
 1518 */
 1519 int Xorriso_add_intvl_adr(struct XorrisO *xorriso, char *buf,
 1520                           uint64_t start_adr, uint64_t end_adr, char *suffix,
 1521                           int flag)
 1522 {
 1523  char *path;
 1524 
 1525  sprintf(buf + strlen(buf), "--interval:%s:%.f%s-%.f%s:",
 1526          ((flag & (1 << 30)) ? "imported_iso" : "local_fs"),
 1527          (double) start_adr, suffix, (double) end_adr, suffix);
 1528  if(flag & 1)
 1529    strcat(buf, "zero_mbrpt,");
 1530  if(flag & 2)
 1531    strcat(buf, "zero_gpt,");
 1532  if(flag & 4)
 1533    strcat(buf, "zero_apm,");
 1534  if(buf[strlen(buf) - 1] == ',')
 1535    buf[strlen(buf) - 1] = 0;
 1536  strcat(buf, ":");
 1537  path= xorriso->indev;
 1538  if(strncmp(path, "stdio:", 6) == 0)
 1539    path+= 6;
 1540  Text_shellsafe(path, buf, 1);
 1541  return(1);
 1542 }
 1543 
 1544 
 1545 int Xorriso_add_offset_size(struct XorrisO *xorriso, char *buf,
 1546                             off_t byte_offset, off_t byte_size, int flag)
 1547 {
 1548  strcat(buf, " ");
 1549  Sfile_off_t_text(buf + strlen(buf), byte_offset, 0);
 1550  strcat(buf, " ");
 1551  Sfile_off_t_text(buf + strlen(buf), byte_size, 0);
 1552  return(1);
 1553 }
 1554 
 1555 
 1556 struct elto_img_par {
 1557  int n, ldsiz, boot_info_table, grub2_boot_info;
 1558  int do_gpt_basdat, do_gpt_hfsplus, do_apm_hfsplus;
 1559  unsigned int ld_seg, hdpt, platform_id;
 1560  unsigned long int lba, extract_size;
 1561  char pltf[8], b[8], emul[8], boot_image_type[16];
 1562  char *path, *id_string, *sel_crit;
 1563 };
 1564 
 1565 
 1566 /* @param ptype   0= unknown, 1= gpt-basdat, 2=gpt-hfsplus, 3=EFI
 1567    @param flag    bit0= isohybrid
 1568 */
 1569 static int Xorriso_register_eltorito_gpt(struct XorrisO *xorriso,
 1570                                          struct elto_img_par *et_img,
 1571                                          int ptype,
 1572                                          int *efi_boot_part, int *first_efi,
 1573                                          int flag)
 1574 {
 1575  if(flag & 1) {
 1576    if(ptype == 1 || ptype == 3)
 1577      et_img->do_gpt_basdat= ptype;
 1578    else if(ptype == 2)
 1579      et_img->do_gpt_hfsplus= 1;
 1580    return(1);
 1581  } else if(*first_efi && et_img->platform_id == 0xef) {
 1582    if(*efi_boot_part <= 0)
 1583      *efi_boot_part= 1;
 1584    return(1);
 1585  }
 1586  if(et_img->platform_id == 0xef)
 1587    *first_efi= 0;
 1588  return(0);
 1589 }
 1590 
 1591 
 1592 /* @param ptype   0= unknown, 1= gpt-basdat, 2=gpt-hfsplus, 3=EFI
 1593    @param flag    bit0= isohybrid
 1594 */
 1595 static int Xorriso_search_eltorito_path(struct XorrisO *xorriso,
 1596                                         struct elto_img_par *et_imgs,
 1597                                         int elto_count, char *path, int ptype,
 1598                                         int *found, int *efi_boot_part,
 1599                                         int flag)
 1600 {
 1601  int first_efi= 1, et_idx, ret;
 1602 
 1603  for(et_idx= 0; et_idx < elto_count; et_idx++) {
 1604    if(strcmp(et_imgs[et_idx].path, path) != 0)
 1605  continue;
 1606    ret= Xorriso_register_eltorito_gpt(xorriso, et_imgs + et_idx,
 1607                                       ptype, efi_boot_part, &first_efi, flag);
 1608    if(ret > 0)
 1609  break;
 1610  }
 1611  *found= et_idx;
 1612  if(et_idx < elto_count)
 1613    return(1);
 1614  return(0);
 1615 }
 1616 
 1617 
 1618 static int Xorriso_search_eltorito_lba(struct XorrisO *xorriso,
 1619                                        struct elto_img_par *et_imgs,
 1620                                        int elto_count,
 1621                                        unsigned int lba,
 1622                                        int *found, int flag)
 1623 {
 1624  int et_idx;
 1625 
 1626  for(et_idx= 0; et_idx < elto_count; et_idx++)
 1627    if(et_imgs[et_idx].lba == lba)
 1628  break;
 1629  *found= et_idx;
 1630  if(et_idx < elto_count)
 1631    return(1);
 1632  return(0);
 1633 }
 1634 
 1635 
 1636 int Xorriso_highest_data_block(struct XorrisO *xorriso, uint32_t *high_block,
 1637                                int flag)
 1638 {
 1639  int ret;
 1640  struct FindjoB *job= NULL;
 1641  struct stat dir_stbuf;
 1642 
 1643  *high_block= 0;
 1644  ret= Findjob_new(&job, "/", 0);
 1645  if(ret <= 0) {
 1646    Xorriso_no_findjob(xorriso, "[internal:last_data_file_block]", 0);
 1647    {ret= -1; goto ex;}
 1648  }
 1649  Findjob_set_action_type(job, 58, 0, 0);
 1650  ret= Xorriso_findi(xorriso, job, NULL,  (off_t) 0,
 1651                     NULL, "/", &dir_stbuf, 0, 0);
 1652  if(ret <= 0)
 1653    goto ex;
 1654  Findjob_get_last_data_file_block(job, high_block, 0);
 1655 ex:;
 1656  Findjob_destroy(&job, 0);
 1657  return(ret);
 1658 }
 1659 
 1660 
 1661 /* @param flag bit0= do not record but only count
 1662                bit1= as_mkisofs
 1663                bit2= no sorry messages
 1664 */
 1665 static int Xorriso_scan_report_lines(struct XorrisO *xorriso,
 1666                                      char **et_lines, int et_line_count,
 1667                                      char **sa_lines, int sa_line_count,
 1668                                      char **cmds, int *cmd_count,
 1669                                      char **boot_imgs, int *boot_img_count,
 1670                                      int flag)
 1671 {
 1672  int ret= 0, i, num_count, mkisofs, line_count, idx, et_idx, isohybrid= 0;
 1673  int ptype, gpt_idx, j, pad, mbr_idx;
 1674  int efi_boot_part= 0, full_sparc_part= 0, have_sparc_part= 0, fe_dummy= 1;
 1675  int appended_as_gpt= 0, have_prep= 0, did_sysarea= 0, cared_for_apm= 0;
 1676  int cared_for_sparc= 0, have_hfsplus= 0;
 1677  int have_sysarea= 0, ptable_killer, imported_iso, have_alpha_ldr_path= 0;
 1678  int have_protective_msdos= 0, part_like_isohybrid= 0, fresh_efi_boot_part;
 1679 
 1680 #ifdef Not_any_more_because_padding_is_now_after_partitions
 1681  int appended_partition= 0;
 1682 #endif
 1683 
 1684  int iso_mbr_part_type= -1, iso_gpt_part_idx= -1;
 1685  unsigned int prev_pltf= 0;
 1686  unsigned long int sa_options= 0, partno, id_tag, perms, start_cyl;
 1687  unsigned long int part_status, part_type, mbr_start_block, mbr_num_blocks;
 1688  unsigned long int partition_offset= 0;
 1689  uint32_t high_block= 0, indev_blocks;
 1690  char name[24], *textpt, *contentpt, *buf= NULL, part_type_text[37];
 1691  char **lines= NULL;
 1692  double num[8];
 1693  char *cat_path= "";
 1694  struct elto_img_par *et_imgs= NULL;
 1695  int elto_count= 0;
 1696  uint32_t mbr_parts_end= 0, extract_size;
 1697  struct FindjoB *job= NULL;
 1698  struct stat dir_stbuf;
 1699  IsoImage *image;
 1700  char *volid, *crt, *mdt, *ext, *eft, uuid[17], *uuid_time;
 1701  char **app_pseudo_paths= NULL;
 1702  struct tm tm_erg;
 1703  int was_force_bootable= 0, have_mbr_force_bootable= 0;
 1704  uint64_t gpt_bheader_block= 0, start_block, num_blocks;
 1705  uint64_t img_blocks= 0, iso_part_blocks;
 1706  char *cpt, *npt, *ftext;
 1707  int ftext_l, l;
 1708  unsigned char bin_data[8];
 1709  uint64_t gpt_part_flags;
 1710  int was_gpt_iso_bootable= 0, was_gpt_iso_not_ro= 0, bin_count;
 1711 
 1712  struct mbr_par {
 1713    uint8_t ptype;
 1714    uint64_t start_block;
 1715    uint64_t block_count;
 1716    int appended;
 1717    int has_path;
 1718  };
 1719  struct mbr_par *mbrpts= NULL;
 1720  int mbr_count= 0;
 1721 
 1722  struct gpt_par {
 1723    int ptype; /* 0= unknown, 1= gpt-basdat, 2=gpt-hfsplus, 3=EFI */
 1724    uint8_t type_guid[16];
 1725    int is_gap;
 1726    int has_path;
 1727    char *path;
 1728    uint64_t start_block;
 1729    uint64_t block_count;
 1730  };
 1731  struct gpt_par *gpts= NULL;
 1732  int gpt_count= 0;
 1733 
 1734  struct apm_par {
 1735    int ptype; /* bit0= type Apple_HFS , bit1= name HFSPLUS_Hybrid */
 1736    char *path;
 1737  };
 1738  struct apm_par *apms= NULL; 
 1739  int apm_count= 0;
 1740 
 1741 #define Xorriso_record_cmd_linE { \
 1742      ret= Xorriso_record_cmd_line(xorriso, buf, cmds, cmd_count, flag & 1); \
 1743      buf[0]= 0; \
 1744      if(ret <= 0) \
 1745        goto ex; \
 1746  }
 1747 #define Xorriso_record_boot_imglinE { \
 1748      ret= Xorriso_record_cmd_line(xorriso, buf, boot_imgs, boot_img_count, \
 1749                                   flag & 1); \
 1750      buf[0]= 0; \
 1751      if(ret <= 0) \
 1752        goto ex; \
 1753  }
 1754 
 1755 /* 2 exp 19 blocks = 1 GiB */
 1756 #define Xorriso_max_endless_uefi_sizE (1 << 19)
 1757 
 1758  mkisofs= !!(flag & 2);
 1759  imported_iso= (!mkisofs) << 30;
 1760 
 1761  *cmd_count= 0;
 1762  *boot_img_count= 0;
 1763  line_count= et_line_count + sa_line_count;
 1764  if(line_count <= 0)
 1765    {ret= 1; goto ex;}
 1766 
 1767  Xorriso_alloc_meM(buf, char, 80 + SfileadrL);
 1768  Xorriso_alloc_meM(lines, char *, line_count);
 1769  for(i= 0; i < et_line_count; i++)
 1770    lines[i]= et_lines[i];
 1771  for(i= 0; i < sa_line_count; i++)
 1772    lines[i + et_line_count]= sa_lines[i];
 1773 
 1774  /* Pre-scan to establish context */
 1775  for(i= 0; i < line_count; i++) {
 1776    ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt,
 1777                                   num, &num_count, &textpt, 0);
 1778    if(ret <= 0)
 1779      goto ex;
 1780    if(strcmp(name, "System area options:") == 0) {
 1781      sscanf(contentpt, "%lx", &sa_options);
 1782 
 1783    } else if(strcmp(name, "System area summary:") == 0) {
 1784      have_sysarea= 1;
 1785 
 1786    } else if(strcmp(name, "El Torito boot img :") == 0) {
 1787      if(num[0] > elto_count)
 1788        elto_count= num[0];
 1789 
 1790    } else if(strcmp(name, "PReP boot partition:") == 0) {
 1791      have_prep= 1;
 1792 
 1793    } else if(strcmp(name, "MBR partition      :") == 0) {
 1794      if(num[0] > mbr_count)
 1795        mbr_count= num[0];
 1796      if(strcmp(textpt, "0x80  0x00            0            1") == 0)
 1797        have_mbr_force_bootable= 1;
 1798 
 1799    } else if(strcmp(name, "GPT partition name :") == 0) {
 1800      if(num[0] > gpt_count)
 1801        gpt_count= num[0];
 1802 
 1803    } else if(strcmp(name, "APM partition name :") == 0) {
 1804      if(num[0] > apm_count)
 1805        apm_count= num[0];
 1806 
 1807    } else if(strcmp(name, "ISO image size/512 :") == 0) {
 1808      img_blocks= num[0];
 1809 
 1810    } else if(strcmp(name, "Partition offset   :") == 0 &&
 1811       (num[0] == 0 || num[0] == 16)) {
 1812      partition_offset= num[0];
 1813 
 1814    }
 1815  }
 1816 
 1817  ret= Xorriso_highest_data_block(xorriso, &high_block, 0);
 1818  if(ret < 0)
 1819    goto ex;
 1820  if(ret == 0)
 1821    high_block = img_blocks / 4 - 1;
 1822 
 1823  if(elto_count > 0) {
 1824    Xorriso_alloc_meM(et_imgs, struct elto_img_par, elto_count);
 1825    for(et_idx= 0; et_idx < elto_count; et_idx++) {
 1826      et_imgs[et_idx].path= NULL;
 1827      et_imgs[et_idx].ldsiz= -1;
 1828    }
 1829    Xorriso_alloc_meM(app_pseudo_paths, char *, elto_count);
 1830    for(i= 0; i < elto_count; i++)
 1831      app_pseudo_paths[i]= NULL;
 1832    for(i= 0; i < elto_count; i++) {
 1833      Xorriso_alloc_meM(app_pseudo_paths[i], char, 80);
 1834      app_pseudo_paths[i][0]= 0;
 1835    }
 1836  }
 1837  if(mbr_count > 0)
 1838    Xorriso_alloc_meM(mbrpts, struct mbr_par, mbr_count);
 1839  if(gpt_count > 0) {
 1840    Xorriso_alloc_meM(gpts, struct gpt_par, gpt_count);
 1841    for(gpt_idx= 0; gpt_idx < gpt_count; gpt_idx++)
 1842      gpts[gpt_idx].path= NULL;
 1843  }
 1844  if(apm_count > 0) {
 1845    Xorriso_alloc_meM(apms, struct apm_par, apm_count);
 1846    for(i= 0; i < apm_count; i++)
 1847      apms[i].path= NULL;
 1848  }
 1849 
 1850  ptable_killer= (mbr_count > 0) | ((gpt_count > 0) << 1) |
 1851                 ((apm_count > 0) << 2);
 1852 
 1853  /* Report volume id and GRUB2 modification date */;
 1854  ret= Xorriso_get_volume(xorriso, &image, 0);
 1855  if(ret <= 0)
 1856    goto ex;
 1857  if(mkisofs)
 1858    sprintf(buf, "-V ");
 1859  else
 1860    sprintf(buf, "-volid ");
 1861  volid= (char *) un0(iso_image_get_volume_id(image));
 1862  Text_shellsafe(volid, buf, 1);
 1863  Xorriso_record_cmd_linE
 1864  ret= iso_image_get_pvd_times(image, &crt, &mdt, &ext, &eft);
 1865  if(ret == ISO_SUCCESS) {
 1866    uuid_time= crt;
 1867    /* If Creation Time is bad and Modification Time is ok: use the latter */
 1868    ret= Decode_ecma119_format(&tm_erg, crt, 0);
 1869    if(ret <= 0 || strlen(crt) != 16) {
 1870      ret= Decode_ecma119_format(&tm_erg, mdt, 0);
 1871      if(!(ret <= 0 || strlen(mdt) != 16))
 1872        uuid_time= mdt;
 1873    }
 1874    pad= 0;
 1875    for(j= 0; j < 16; j++) {
 1876      if(pad) {
 1877        uuid[j]= '0';
 1878      } else if(uuid_time[j] == 0) {
 1879        pad= 1;
 1880        uuid[j]= '0';
 1881      } else if(uuid_time[j] < '0' || uuid_time[j] > '9') {
 1882        uuid[j]= '0';
 1883      } else {
 1884        uuid[j]= uuid_time[j];
 1885      }
 1886    }
 1887    uuid[16]= 0;
 1888    ret= Decode_ecma119_format(&tm_erg, uuid, 0);
 1889    if(!(ret <= 0 || strlen(uuid) != 16)) {
 1890      if(mkisofs)
 1891        sprintf(buf, "--modification-date=");
 1892      else
 1893        sprintf(buf, "-volume_date uuid ");
 1894      Text_shellsafe(uuid, buf, 1);
 1895      Xorriso_record_cmd_linE
 1896    }
 1897  }
 1898 
 1899  /* First pass: set up objects, record El Torito and info needed in 2nd pass */
 1900  for(i= 0; i < line_count; i++) {
 1901    buf[0]= 0;
 1902    ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt,
 1903                                   num, &num_count, &textpt, 0);
 1904    if(ret <= 0)
 1905      goto ex;
 1906 
 1907    if(strcmp(name, "El Torito cat path :") == 0) {
 1908      cat_path= textpt;
 1909 
 1910    } else if(strcmp(name, "El Torito catalog  :") == 0) {
 1911      strcpy(buf, "eltorito_catalog.img/");
 1912      Xorriso_add_offset_size(xorriso, buf, ((off_t) num[0]) * 2048,
 1913                              ((off_t) num[1]) * 2048, 0);
 1914      Xorriso_record_boot_imglinE
 1915 
 1916    } else if(strcmp(name, "El Torito boot img :") == 0) {
 1917      /* Platform Id, bootability, emulation, load segment,
 1918         Hard disk emulation partition type, Load size
 1919      */
 1920      idx= num[0] - 1;
 1921      sscanf(contentpt, "%d %s %s %s %x %x %d %lu",
 1922             &(et_imgs[idx].n), et_imgs[idx].pltf, et_imgs[idx].b,
 1923             et_imgs[idx].emul, &(et_imgs[idx].ld_seg), &(et_imgs[idx].hdpt),
 1924             &(et_imgs[idx].ldsiz), &(et_imgs[idx].lba));
 1925      if(strcmp(et_imgs[idx].pltf, "BIOS") == 0)
 1926        et_imgs[idx].platform_id= 0;
 1927      else if(strcmp(et_imgs[idx].pltf, "PPC") == 0)
 1928        et_imgs[idx].platform_id= 1;
 1929      else if(strcmp(et_imgs[idx].pltf, "Mac") == 0)
 1930        et_imgs[idx].platform_id= 2;
 1931      else if(strcmp(et_imgs[idx].pltf, "UEFI") == 0)
 1932        et_imgs[idx].platform_id= 0xef;
 1933      else
 1934        sscanf(et_imgs[idx].pltf, "%x", &(et_imgs[idx].platform_id));
 1935 
 1936      strcpy(et_imgs[idx].boot_image_type, "any");
 1937      et_imgs[idx].boot_info_table= 0;
 1938      et_imgs[idx].grub2_boot_info= 0;
 1939      et_imgs[idx].path= et_imgs[idx].id_string= et_imgs[idx].sel_crit= "";
 1940      et_imgs[idx].do_gpt_basdat= et_imgs[idx].do_gpt_hfsplus= 0;
 1941      et_imgs[idx].do_apm_hfsplus= 0;
 1942      et_imgs[idx].extract_size= (et_imgs[idx].ldsiz + 3) / 4;
 1943 
 1944    } else if(strcmp(name, "El Torito img path :") == 0) {
 1945      idx= num[0] - 1;
 1946      et_imgs[idx].path= textpt;
 1947      ret= Xorriso_iso_lstat(xorriso, et_imgs[idx].path, &dir_stbuf, 0);
 1948      if(ret == 0) {
 1949        extract_size = (dir_stbuf.st_size + 2047) / 2048;
 1950        if(extract_size > et_imgs[idx].extract_size)
 1951          et_imgs[idx].extract_size= extract_size;
 1952      }
 1953 
 1954    } else if(strcmp(name, "El Torito img blks :") == 0) {
 1955      idx= num[0] - 1;
 1956      if(num[1] > et_imgs[idx].extract_size)
 1957        et_imgs[idx].extract_size= num[1];
 1958 
 1959    } else if(strcmp(name, "El Torito img opts :") == 0) {
 1960      idx= num[0] - 1;
 1961      if(strstr(textpt, "boot-info-table") != NULL)
 1962        et_imgs[idx].boot_info_table= 1;
 1963      if(strstr(textpt, "isohybrid-suitable") != NULL)
 1964        strcpy(et_imgs[idx].boot_image_type, "isolinux");
 1965      if(strstr(textpt, "grub2-boot-info") != NULL) {
 1966        strcpy(et_imgs[idx].boot_image_type, "grub");
 1967        et_imgs[idx].grub2_boot_info= 1;
 1968      }
 1969 
 1970    } else if(strcmp(name, "El Torito id string:") == 0) {
 1971      idx= num[0] - 1;
 1972      et_imgs[idx].id_string= textpt;
 1973 
 1974    } else if(strcmp(name, "El Torito sel crit :") == 0) {
 1975      idx= num[0] - 1;
 1976      et_imgs[idx].sel_crit= textpt;
 1977 
 1978    } else if(strcmp(name, "System area summary:") == 0) {
 1979      if(strstr(textpt, "protective-msdos-label") != NULL)
 1980        have_protective_msdos= 1;
 1981 
 1982    } else if(strcmp(name, "MBR partition      :") == 0) {
 1983      sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu",
 1984             &partno, &part_status, &part_type, &mbr_start_block,
 1985             &mbr_num_blocks);
 1986      idx= partno - 1;
 1987      mbrpts[idx].ptype= part_type;
 1988      mbrpts[idx].start_block= mbr_start_block;
 1989      mbrpts[idx].block_count= mbr_num_blocks;
 1990      if(mbr_num_blocks > 0 && mbr_start_block + mbr_num_blocks > mbr_parts_end)
 1991        mbr_parts_end= mbr_start_block + mbr_num_blocks; 
 1992      if(mbr_start_block == partition_offset * 4 &&
 1993         (mbr_start_block + mbr_num_blocks) >= high_block * 4 &&
 1994          iso_mbr_part_type < 0)
 1995        iso_mbr_part_type = part_type;
 1996 
 1997    } else if(strcmp(name, "MBR partition path :") == 0) {
 1998      idx= num[0] - 1;
 1999      mbrpts[idx].has_path= 1;
 2000 
 2001    } else if(strcmp(name, "GPT lba range      :") == 0) {
 2002      gpt_bheader_block= num[2];
 2003 
 2004    } else if(strcmp(name, "GPT type GUID      :") == 0) {
 2005      idx= num[0] - 1;
 2006      if(strcmp(textpt, "a2a0d0ebe5b9334487c068b6b72699c7") == 0)
 2007        gpts[idx].ptype= 1; /* Basic data */
 2008      else if(strcmp(textpt, "005346480000aa11aa1100306543ecac") == 0)
 2009        gpts[idx].ptype= 2; /* HFS+ */
 2010      else if(strcmp(textpt, "28732ac11ff8d211ba4b00a0c93ec93b") == 0)
 2011        gpts[idx].ptype= 3; /* EFI System Partition */
 2012      else
 2013        gpts[idx].ptype= 0;
 2014      Xorriso_parse_guid(xorriso, textpt, gpts[idx].type_guid, 1);
 2015 
 2016    } else if(strcmp(name, "GPT start and size :") == 0) {
 2017      idx= num[0] - 1;
 2018      if(num[2] > 0)
 2019        appended_as_gpt= 1;
 2020      start_block= gpts[idx].start_block= num[1];
 2021      num_blocks= gpts[idx].block_count= num[2];
 2022      if(start_block == partition_offset * 4 &&
 2023         (start_block + num_blocks) >= high_block * 4 &&
 2024         iso_gpt_part_idx < 0)
 2025        iso_gpt_part_idx= idx;
 2026 
 2027    } else if(strcmp(name, "GPT partition path :") == 0) {
 2028      idx= num[0] - 1;
 2029      gpts[idx].has_path= 1;
 2030      gpts[idx].path= textpt;
 2031 
 2032    } else if(strcmp(name, "GPT partition name :") == 0) {
 2033      idx= num[0] - 1;
 2034      if(strstr(contentpt, " 470061007000") != NULL) /* "Gap"... */
 2035        gpts[idx].is_gap= 1;
 2036 
 2037    } else if(strcmp(name, "APM partition name :") == 0) {
 2038      idx= num[0] - 1;
 2039      if(strcmp(textpt, "HFSPLUS_Hybrid") == 0)
 2040        apms[idx].ptype|= 2;
 2041 
 2042    } else if(strcmp(name, "APM partition type :") == 0) {
 2043      idx= num[0] - 1;
 2044      if(strcmp(textpt, "Apple_HFS") == 0)
 2045        apms[idx].ptype|= 1;
 2046 
 2047    } else if(strcmp(name, "APM partition path :") == 0) {
 2048      idx= num[0] - 1;
 2049      apms[idx].path= textpt;
 2050 
 2051    } else if(strcmp(name, "DEC Alpha ldr path :") == 0) {
 2052      have_alpha_ldr_path= 1;
 2053 
 2054    }
 2055  }
 2056 
 2057  if(appended_as_gpt && !have_protective_msdos) {
 2058    /* Check if really a pure GPT or a nearly pure mbr-force-bootable GPT */
 2059    if(mbr_count != 1 && !(mbr_count == 2 && have_mbr_force_bootable)) {
 2060      appended_as_gpt= 0;
 2061    } else if(mbrpts[0].ptype != 0xee || mbrpts[0].start_block != 1) {
 2062      appended_as_gpt= 0;
 2063    } else if(gpt_bheader_block != mbrpts[0].block_count) {
 2064      appended_as_gpt= 0;
 2065    }
 2066  }
 2067 
 2068  iso_part_blocks= img_blocks;
 2069  for(mbr_idx = 0; mbr_idx < mbr_count; mbr_idx++) {
 2070    if(mbrpts[mbr_idx].start_block == partition_offset * 4) {
 2071      iso_part_blocks= mbrpts[mbr_idx].block_count + partition_offset * 4;
 2072  break;
 2073    }
 2074  }
 2075 
 2076  /* Second pass: scan for System Area info */
 2077  for(i= 0; i < line_count; i++) {
 2078    buf[0]= 0;
 2079    ret= Xorriso_split_report_line(xorriso, lines[i], 8, name, &contentpt,
 2080                                   num, &num_count, &textpt, 0);
 2081    if(ret <= 0)
 2082      goto ex;
 2083 
 2084    if(strcmp(name, "System area options:") == 0) {
 2085      if((sa_options & 0x3c00) == 0x0400) {
 2086        if(mkisofs)
 2087          sprintf(buf, "-chrp-boot-part ");
 2088        else
 2089          sprintf(buf, "-boot_image any chrp_boot_part=on ");
 2090        Xorriso_record_cmd_linE
 2091        buf[0]= 0;
 2092        ret= Xorriso_assess_written_features(xorriso,
 2093                                             mkisofs ? "as_mkisofs" : "cmd", 1);
 2094        if(ret > 0) {
 2095          ftext= xorriso->result_line;
 2096          ftext_l= strlen(ftext);
 2097          for(cpt= ftext ; cpt - ftext < ftext_l ; cpt+= l + 1) {
 2098            npt= strchr(cpt, '\n');
 2099            if(npt == NULL)
 2100              l= strlen(cpt);
 2101            else
 2102              l= npt - cpt;
 2103            cpt[l]= 0;
 2104            /* Only forward relaxations of ISO 9660 defaults, plus no RR */
 2105            if(mkisofs) {
 2106              if(strcmp(cpt, "-iso-level 2") != 0 &&
 2107                 strcmp(cpt, "-iso-level 3") != 0 &&
 2108                 strcmp(cpt, "--norock") != 0 &&
 2109                 strncmp(cpt, "-untranslated_name_len", 22) != 0 &&
 2110                 strcmp(cpt, "-N") != 0 &&
 2111                 strcmp(cpt, "-D") != 0 &&
 2112                 strcmp(cpt, "-U") != 0 &&
 2113                 strcmp(cpt, "-max-iso9660-filenames") != 0 &&
 2114                 strcmp(cpt, "-d") != 0 &&
 2115                 strcmp(cpt, "-allow-lowercase") != 0)
 2116          continue;
 2117            } else {
 2118              /* (Do not forward iso_9660_level because 3 is default and the
 2119                  user possibly had reasons to lower it) */
 2120              if(strcmp(cpt, "-rockridge off") != 0 &&
 2121                 strncmp(cpt, "-compliance untranslated_name_len=", 34) != 0 &&
 2122                 strcmp(cpt, "-compliance omit_version_off:only_iso_version")
 2123                        != 0 &&
 2124                 strcmp(cpt, "-compliance omit_version:only_iso_version_off")
 2125                        != 0 &&
 2126                 strcmp(cpt, "-compliance deep_paths") != 0 &&
 2127                 strcmp(cpt, "-compliance long_paths") != 0 &&
 2128                 strcmp(cpt, "-compliance full_ascii") != 0 &&
 2129                 strcmp(cpt, "-compliance long_names") != 0 &&
 2130                 strncmp(cpt, "-compliance no_force_dots:", 26) != 0 &&
 2131                 strcmp(cpt, "-compliance lowercase") != 0)
 2132          continue;
 2133              if(strcmp(cpt, "-compliance untranslated_name_len=0") == 0)
 2134          continue;
 2135            }
 2136            if(strncmp(cpt, "-compliance untranslated_name_len=", 34) == 0) {
 2137              /* Better allow the maximum if it is reported as non-0 */
 2138              strcpy(buf, "-compliance untranslated_name_len=96");
 2139            } else {
 2140              strcpy(buf, cpt);
 2141            }
 2142            Xorriso_record_cmd_linE
 2143          }
 2144        }
 2145      }
 2146 
 2147    } else if(strcmp(name, "System area summary:") == 0) {
 2148      if(strstr(textpt, "isohybrid") != NULL) {
 2149        isohybrid= 1;
 2150        if(mkisofs)
 2151          sprintf(buf, "-isohybrid-mbr ");
 2152        else
 2153          sprintf(buf, "-boot_image isolinux system_area=");
 2154        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) 0, (uint64_t) 15, "s",
 2155                              imported_iso | ptable_killer);
 2156        Xorriso_record_cmd_linE
 2157        strcpy(buf, "mbr_code_isohybrid.img/");
 2158        Xorriso_add_offset_size(xorriso, buf, (off_t) 0, (off_t) 446, 0);
 2159        Xorriso_record_boot_imglinE
 2160        did_sysarea= 1;
 2161      }
 2162      if(strstr(textpt, "grub2-mbr") != NULL) {
 2163        if(mkisofs)
 2164          sprintf(buf, "--grub2-mbr ");
 2165        else
 2166          sprintf(buf, "-boot_image grub grub2_mbr=");
 2167        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) 0, (uint64_t) 15, "s",
 2168                              imported_iso | ptable_killer);
 2169        Xorriso_record_cmd_linE
 2170        strcpy(buf, "mbr_code_grub2.img/");
 2171        Xorriso_add_offset_size(xorriso, buf, (off_t) 0, (off_t) 446, 0);
 2172        Xorriso_record_boot_imglinE
 2173        did_sysarea= 1;
 2174      }
 2175      if(strstr(textpt, "protective-msdos-label") != NULL) {
 2176        if(mkisofs)
 2177          sprintf(buf, "--protective-msdos-label");
 2178        else
 2179          sprintf(buf, "-boot_image any partition_table=on");
 2180        Xorriso_record_cmd_linE
 2181      }
 2182      if(strstr(textpt, "cyl-align-off") != NULL) {
 2183        if(mkisofs)
 2184          sprintf(buf, "-partition_cyl_align off");
 2185        else
 2186          sprintf(buf, "-boot_image any partition_cyl_align=off");
 2187      } else if(strstr(textpt, "cyl-align-all") != NULL) {
 2188        if(mkisofs)
 2189          sprintf(buf, "-partition_cyl_align all");
 2190        else
 2191          sprintf(buf, "-boot_image any partition_cyl_align=all");
 2192      } else if(strstr(textpt, "cyl-align-") != NULL) {
 2193        if(mkisofs)
 2194          sprintf(buf, "-partition_cyl_align on");
 2195        else
 2196          sprintf(buf, "-boot_image any partition_cyl_align=on");
 2197      } else
 2198        buf[0]= 0;
 2199 
 2200    } else if(strcmp(name, "Partition offset   :") == 0 &&
 2201       (num[0] == 0 || num[0] == 16)) {
 2202      if(mkisofs)
 2203        sprintf(buf, "-partition_offset %.f", num[0]);
 2204      else
 2205        sprintf(buf, "-boot_image any partition_offset=%.f", num[0]);
 2206 
 2207    } else if(strcmp(name, "MBR heads per cyl  :") == 0 &&
 2208       (num[0] > 0 && num[0] <= 255)) {
 2209      if(mkisofs)
 2210        sprintf(buf, "-partition_hd_cyl %.f", num[0]);
 2211      else
 2212        sprintf(buf, "-boot_image any partition_hd_cyl=%.f", num[0]);
 2213 
 2214    } else if(strcmp(name, "MBR secs per head  :") == 0 &&
 2215       (num[0] > 0 && num[0] <= 63)) {
 2216      if(mkisofs)
 2217        sprintf(buf, "-partition_sec_hd %.f", num[0]);
 2218      else
 2219        sprintf(buf, "-boot_image any partition_sec_hd=%.f", num[0]);
 2220 
 2221    } else if(strcmp(name, "MBR partition      :") == 0) {
 2222      sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu",
 2223             &partno, &part_status, &part_type, &mbr_start_block,
 2224             &mbr_num_blocks);
 2225      if(mbr_num_blocks > 0 && part_type != 0x00 && part_type != 0xee &&
 2226         (iso_part_blocks <= mbr_start_block ||
 2227          (have_protective_msdos && img_blocks == mbr_parts_end &&
 2228           partno > 1))) {
 2229        if(!appended_as_gpt) {
 2230          sprintf(buf, "-append_partition %lu 0x%lx ", partno, part_type);
 2231          Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) mbr_start_block,
 2232                              ((uint64_t) mbr_start_block) + mbr_num_blocks - 1,
 2233                                "d", imported_iso);
 2234          Xorriso_record_cmd_linE
 2235          if(partno >= 1 && (int) partno <= mbr_count)
 2236            mbrpts[partno - 1].appended= 1;
 2237 
 2238 #ifdef Not_any_more_because_padding_is_now_after_partitions
 2239          appended_partition= 1;
 2240 #endif
 2241 
 2242        }
 2243        if(part_type == 0xef) {
 2244          sprintf(buf, "mbr_part%lu_efi.img/", partno);
 2245          Xorriso_add_offset_size(xorriso, buf, ((off_t) mbr_start_block) * 512,
 2246                                  ((off_t) mbr_num_blocks) * 512, 0);
 2247          Xorriso_record_boot_imglinE
 2248        }
 2249      } else if(part_type == 0x41 && have_prep) {
 2250        if(mkisofs) {
 2251          sprintf(buf, "-prep-boot-part ");
 2252        } else {
 2253          sprintf(buf, "-boot_image any prep_boot_part=");
 2254        }
 2255        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) mbr_start_block,
 2256                              ((uint64_t) mbr_start_block) + mbr_num_blocks - 1,
 2257                              "d", imported_iso);
 2258        Xorriso_record_cmd_linE
 2259        sprintf(buf, "mbr_part%lu_prep.img/", partno);
 2260        Xorriso_add_offset_size(xorriso, buf, ((off_t) mbr_start_block) * 512,
 2261                                ((off_t) mbr_num_blocks) * 512, 0);
 2262        Xorriso_record_boot_imglinE
 2263      } else if(part_type == 0xef) {
 2264        sprintf(buf, "mbr_part%lu_efi.img/", partno);
 2265        Xorriso_add_offset_size(xorriso, buf, ((off_t) mbr_start_block) * 512,
 2266                                ((off_t) mbr_num_blocks) * 512, 0);
 2267        Xorriso_record_boot_imglinE
 2268      }
 2269      if((part_status & 0x80) && !was_force_bootable) {
 2270        was_force_bootable= 1;
 2271        if(buf[0]) {
 2272          Xorriso_record_cmd_linE
 2273        }
 2274        if(mkisofs)
 2275          sprintf(buf, "--mbr-force-bootable");
 2276        else
 2277          sprintf(buf, "-boot_image any mbr_force_bootable=on");
 2278      }
 2279    } else if(strcmp(name, "MBR partition path :") == 0) {
 2280      idx= num[0] - 1;
 2281      if(mbrpts[idx].ptype == 0x41) {
 2282        sprintf(xorriso->info_text,
 2283                "Cannot make proposal to mark PReP partition by data file: ");
 2284        Text_shellsafe(textpt, xorriso->info_text, 1);
 2285        if(!(flag & 5))
 2286          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2287  continue;
 2288      }
 2289      ptype= 0;
 2290      if(mbrpts[idx].ptype == 0xef)
 2291        ptype= 3;
 2292      ret= Xorriso_search_eltorito_path(xorriso, et_imgs, elto_count,
 2293                                        textpt, ptype,
 2294                                        &et_idx, &efi_boot_part, !!isohybrid);
 2295      if(ret <= 0) {
 2296        sprintf(xorriso->info_text,
 2297                "Cannot make proposal to mark data file as MBR partition without being an El Torito boot image : ");
 2298        Text_shellsafe(textpt, xorriso->info_text, 1);
 2299        if(!(flag & 5))
 2300          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2301      } else {
 2302        for(gpt_idx= 0; gpt_idx < gpt_count; gpt_idx++) {
 2303          if(gpts[gpt_idx].path != NULL)
 2304            if(strcmp(gpts[gpt_idx].path, textpt) == 0)
 2305        break;
 2306        }
 2307        if(gpt_idx >= gpt_count) {
 2308          sprintf(xorriso->info_text,
 2309                  "Cannot make proposal to mark data file as MBR partition without being in GPT : ");
 2310          Text_shellsafe(textpt, xorriso->info_text, 1);
 2311          if(!(flag & 5))
 2312            Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2313        }
 2314      } 
 2315 
 2316    } else if(strcmp(name, "GPT disk GUID      :") == 0) {
 2317 
 2318      /* >>> ??? need command to set disk GUID */;
 2319 
 2320    } else if(strcmp(name, "GPT partition name :") == 0) {
 2321 
 2322      /* >>> ??? need command to set partition name for partition number */;
 2323 
 2324    } else if(strcmp(name, "GPT partition GUID :") == 0) {
 2325 
 2326      /* >>> ??? need command to set partition GUID for partition number */;
 2327 
 2328    } else if(strcmp(name, "GPT partition flags:") == 0) {
 2329 
 2330      /* >>> check whether 0x100000000000000[15] . Else: complain */;
 2331 
 2332      cpt= strstr(contentpt, "0x");
 2333      if(cpt != NULL) {
 2334        ret= Hex_to_bin(cpt + 2, 8, &bin_count, bin_data, 0);
 2335        if(ret > 0) {
 2336          /* convert big-endian bin_data to local endianness */
 2337          gpt_part_flags= 0;
 2338          for(gpt_idx= 0; gpt_idx < bin_count; gpt_idx++)
 2339            gpt_part_flags|= (((uint64_t) bin_data[gpt_idx]) <<
 2340                              (8 * (bin_count - 1 - gpt_idx)));
 2341 
 2342          if((gpt_part_flags & 4) && !was_gpt_iso_bootable) {
 2343            was_gpt_iso_bootable= 1;
 2344            if(buf[0]) {
 2345              Xorriso_record_cmd_linE
 2346            }
 2347            if(mkisofs)
 2348              sprintf(buf, "--gpt-iso-bootable");
 2349            else
 2350              sprintf(buf, "-boot_image any gpt_iso_bootable=on");
 2351          }
 2352 
 2353          if(num_count > 0 && num[0] == 1 &&
 2354             (!(gpt_part_flags & (((uint64_t) 1) << 60))) &&
 2355             !was_gpt_iso_not_ro) {
 2356            was_gpt_iso_not_ro= 1;
 2357            if(buf[0]) {
 2358              Xorriso_record_cmd_linE
 2359            }
 2360            if(mkisofs)
 2361              sprintf(buf, "--gpt-iso-not-ro");
 2362            else
 2363              sprintf(buf, "-boot_image any gpt_iso_not_ro=on");
 2364          }
 2365        }
 2366      }
 2367 
 2368    } else if(strcmp(name, "GPT partition path :") == 0) {
 2369      idx= num[0] - 1;
 2370      ret= Xorriso_search_eltorito_path(xorriso, et_imgs, elto_count,
 2371                                        textpt, gpts[idx].ptype,
 2372                                        &et_idx, &efi_boot_part, !!isohybrid);
 2373      if(ret <= 0) {
 2374        sprintf(xorriso->info_text,
 2375                "Cannot make proposal to mark data file as GPT partition : ");
 2376        Text_shellsafe(textpt, xorriso->info_text, 1);
 2377        if(!(flag & 5))
 2378          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2379      }
 2380 
 2381    } else if(strcmp(name, "GPT start and size :") == 0) {
 2382      idx= num[0] - 1;
 2383      if(gpts[idx].ptype == 3)
 2384        part_type= 0xef;
 2385      else
 2386        part_type= 0xcd;
 2387 
 2388      fresh_efi_boot_part= 0;
 2389      if(high_block * 4 < num[1] && num[2] > 0 && !gpts[idx].is_gap) {
 2390        for(mbr_idx = 0; mbr_idx < mbr_count; mbr_idx++) {
 2391          if(mbrpts[mbr_idx].start_block == num[1]) {
 2392            if(mbrpts[mbr_idx].block_count != num[2] && !(flag & 1)) {
 2393              sprintf(xorriso->info_text,
 2394                      "GPT partition %d has same start block as MBR partition %d but different block count (%.f <> %.f)",
 2395                      idx + 1, mbr_idx + 1, num[2],
 2396                      (double) mbrpts[mbr_idx].block_count);
 2397              Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING",
 2398                                  0);
 2399            }
 2400        break;
 2401          }
 2402        }
 2403        if(mbr_idx >= mbr_count) {
 2404          if(appended_as_gpt == 1) {
 2405            appended_as_gpt= 2;
 2406            Xorriso__format_guid(gpts[idx].type_guid, part_type_text, 0);
 2407          } else {
 2408            sprintf(part_type_text, "0x%lx", part_type);
 2409          }
 2410          sprintf(buf, "-append_partition %d %s ", idx + 1, part_type_text);
 2411          Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) num[1],
 2412                                (uint64_t) (num[1] + num[2] - 1.0), "d",
 2413                                imported_iso);
 2414          Xorriso_record_cmd_linE
 2415 
 2416 #ifdef Not_any_more_because_padding_is_now_after_partitions
 2417          appended_partition= 1;
 2418 #endif
 2419 
 2420        }
 2421 
 2422      } else if(gpts[idx].ptype == 3 && gpts[idx].has_path == 0 &&
 2423                img_blocks >= num[1] + num[2] && !efi_boot_part) {
 2424        if(mkisofs)
 2425          sprintf(buf, "-efi-boot-part ");
 2426        else
 2427          sprintf(buf, "-boot_image any efi_boot_part=");
 2428        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) num[1],
 2429                              (uint64_t) (num[1] + num[2] - 1.0), "d",
 2430                              imported_iso);
 2431        efi_boot_part= 2;
 2432        fresh_efi_boot_part= 1;
 2433        Xorriso_record_cmd_linE
 2434      }
 2435 
 2436      if(!fresh_efi_boot_part) {
 2437        /* Check for isohybri-ish MBR and GPT mix */
 2438        if((mbr_count == 1 || (mbr_count == 2 && have_mbr_force_bootable)) &&
 2439           mbrpts[0].ptype == 0xee && have_protective_msdos) {
 2440          /* real GPT (+/- mbr_force_bootable) is not -part_like_isohybrid */
 2441          ret= 0;
 2442        } else {
 2443          ret= Xorriso_search_eltorito_lba(xorriso, et_imgs, elto_count,
 2444                                           (unsigned int) (num[1] / 4.0),
 2445                                           &et_idx, 0);
 2446        }
 2447        if(ret > 0) {
 2448          if(!(isohybrid ||
 2449               et_imgs[et_idx].do_gpt_basdat ||
 2450               et_imgs[et_idx].do_gpt_hfsplus ||
 2451               part_like_isohybrid)) {
 2452            if(mkisofs)
 2453              sprintf(buf, "-part_like_isohybrid");
 2454            else
 2455              sprintf(buf, "-boot_image any part_like_isohybrid=on");
 2456            Xorriso_record_cmd_linE
 2457            part_like_isohybrid= 1;
 2458            appended_as_gpt= 0;
 2459          }
 2460          /*  mark el torito for  -isohybrid-gpt-... */
 2461          Xorriso_register_eltorito_gpt(xorriso, et_imgs + et_idx,
 2462                                        gpts[idx].ptype, &efi_boot_part,
 2463                                        &fe_dummy, 1);
 2464          if(efi_boot_part == 1) {
 2465            /* -isohybrid-gpt- substitutes for -efi-boot-part --efi-boot-image */
 2466            efi_boot_part= 2;
 2467          }
 2468        }
 2469      }
 2470 
 2471      if(gpts[idx].ptype == 2 &&
 2472         (img_blocks / 2 > num[2] || num[1] >= img_blocks)) {
 2473        /* Obviously not a HFS+ tree covering the ISO */
 2474        sprintf(buf, "gpt_part%d_hfsplus.img/", idx + 1);
 2475        Xorriso_add_offset_size(xorriso, buf, ((off_t) num[1]) * 512,
 2476                                ((off_t) num[2]) * 512, 0);
 2477        Xorriso_record_boot_imglinE
 2478      } else if(gpts[idx].ptype == 3) {
 2479        sprintf(buf, "gpt_part%d_efi.img/", idx + 1);
 2480        Xorriso_add_offset_size(xorriso, buf, ((off_t) num[1]) * 512,
 2481                                ((off_t) num[2]) * 512, 0);
 2482        Xorriso_record_boot_imglinE
 2483      }
 2484 
 2485    } else if(strcmp(name, "APM block size     :") == 0) {
 2486      if(mkisofs)
 2487        sprintf(buf, "-apm-block-size %.f", num[0]);
 2488      else
 2489        sprintf(buf, "-boot_image any apm_block_size=%.f", num[0]);
 2490 
 2491    } else if(strcmp(name, "APM partition name :") == 0) {
 2492 
 2493      /* >>> ??? need command to set APM partition name for partition number */;
 2494 
 2495    } else if(strcmp(name, "APM partition path :") == 0) {
 2496      idx= num[0] - 1;
 2497      /* Check El Torito EFI boot images for same path */
 2498      for(et_idx= 0; isohybrid && et_idx < elto_count; et_idx++)
 2499        if(strcmp(et_imgs[et_idx].path, textpt) == 0) {
 2500          if(apms[idx].ptype == 1) {
 2501            et_imgs[et_idx].do_apm_hfsplus= 1;
 2502            cared_for_apm= 1;
 2503          }
 2504      break;
 2505        }
 2506 
 2507    } else if(strcmp(name, "APM start and size :") == 0) {
 2508      idx= num[0] - 1;
 2509 
 2510      if(num[1] + num[2] <= img_blocks && apms[idx].ptype == 3 &&
 2511         apms[idx].path == NULL && !have_hfsplus) {
 2512        
 2513        /* >>> HFS+ magic number */;
 2514        /* >>> Read byte 1024 and 1025 after partition start
 2515               Must be {'H', '+'}  (0x482b big endian)
 2516        */;
 2517        /* ??? >>> Do this recognition in libisofs ? */
 2518 
 2519        if(mkisofs)
 2520          sprintf(buf, "-hfsplus");
 2521        else
 2522          sprintf(buf, "-hfsplus on");
 2523        Xorriso_record_cmd_linE
 2524 
 2525        /* Report commands for blessings and creator-type */
 2526        ret= Findjob_new(&job, "/", 0);
 2527        if(ret <= 0) {
 2528          Xorriso_no_findjob(xorriso, "xorriso", 0);
 2529          {ret= -1; goto ex;}
 2530        }
 2531        Findjob_set_action_target(job, 53, NULL, 0);
 2532        xorriso->show_hfs_cmd_count= *cmd_count;
 2533        xorriso->show_hfs_cmds= cmds;
 2534        xorriso->show_hfs_cmd_flag= (flag & 1) | ((!!mkisofs) << 1);
 2535        ret= Xorriso_findi(xorriso, job, NULL, (off_t) 0, NULL, "/",
 2536                           &dir_stbuf, 0, 0);
 2537        *cmd_count= xorriso->show_hfs_cmd_count;
 2538        if(ret <= 0)
 2539          goto ex;
 2540        have_hfsplus= 1;
 2541        cared_for_apm= 1;
 2542      }
 2543 
 2544    } else if(strcmp(name, "MIPS-BE boot path  :") == 0) {
 2545      if(mkisofs)
 2546        sprintf(buf, "-mips-boot ");
 2547      else
 2548        sprintf(buf, "-boot_image any mips_path=");
 2549      Text_shellsafe(textpt, buf, 1);
 2550 
 2551    } else if(strcmp(name, "MIPS-LE boot path  :") == 0) {
 2552      if(mkisofs)
 2553        sprintf(buf, "-mipsel-boot ");
 2554      else
 2555        sprintf(buf, "-boot_image any mipsel_path=");
 2556      Text_shellsafe(textpt, buf, 1);
 2557 
 2558    } else if(strcmp(name, "SUN SPARC disklabel:") == 0) {
 2559      if(mkisofs)
 2560        sprintf(buf, "-sparc-label ");
 2561      else
 2562        sprintf(buf, "-boot_image any sparc_label=");
 2563      Text_shellsafe(textpt, buf, 1);
 2564 
 2565    } else if(strcmp(name, "SPARC GRUB2 path   :") == 0) {
 2566      if(mkisofs) {
 2567        sprintf(buf, "-B ,");
 2568        Xorriso_record_cmd_linE
 2569        sprintf(buf, "--grub2-sparc-core ");
 2570      } else
 2571        sprintf(buf, "-boot_image grub grub2_sparc_core=");
 2572      Text_shellsafe(textpt, buf, 1);
 2573      cared_for_sparc= 1;
 2574 
 2575    } else if(strcmp(name, "SUN SPARC partition:") == 0) {
 2576      have_sparc_part= 1;
 2577      partno= id_tag= perms= num_blocks= 0;
 2578      start_cyl= 0xffffffff;
 2579      sscanf(contentpt, "%lu 0x%lx 0x%lx %lu %lu",
 2580             &partno, &id_tag, &perms, &start_cyl, &mbr_num_blocks);
 2581      if(partno > 0 && partno < 9 && start_cyl == 0 && 
 2582         mbr_num_blocks >= img_blocks - 600 && mbr_num_blocks <= img_blocks &&
 2583         ((partno == 1 && id_tag == 4) || (partno > 1 && id_tag == 2)))
 2584        full_sparc_part|= (1 << (partno - 1));
 2585 
 2586    } else if(strcmp(name, "PALO header version:") == 0) {
 2587      if(mkisofs)
 2588        sprintf(buf, "-hppa-hdrversion %.f", num[0]);
 2589      else
 2590        sprintf(buf, "-boot_image any hppa_hdrversion=%.f", num[0]);
 2591 
 2592    } else if(strcmp(name, "HP-PA cmdline      :") == 0) {
 2593      if(mkisofs)
 2594        sprintf(buf, "-hppa-cmdline ");
 2595      else
 2596        sprintf(buf, "-boot_image any hppa_cmdline=");
 2597      Text_shellsafe(textpt, buf, 1);
 2598 
 2599    } else if(strcmp(name, "HP-PA 32-bit kernel:") == 0) {
 2600      if(mkisofs)
 2601        sprintf(buf, "-hppa-kernel-32 ");
 2602      else
 2603        sprintf(buf, "-boot_image any hppa_kernel_32=");
 2604      Text_shellsafe(textpt, buf, 1);
 2605 
 2606    } else if(strcmp(name, "HP-PA 64-bit kernel:") == 0) {
 2607      if(mkisofs)
 2608        sprintf(buf, "-hppa-kernel-64 ");
 2609      else
 2610        sprintf(buf, "-boot_image any hppa_kernel_64=");
 2611      Text_shellsafe(textpt, buf, 1);
 2612 
 2613    } else if(strcmp(name, "HP-PA ramdisk      :") == 0) {
 2614      if(mkisofs)
 2615        sprintf(buf, "-hppa-ramdisk ");
 2616      else
 2617        sprintf(buf, "-boot_image any hppa_ramdisk=");
 2618      Text_shellsafe(textpt, buf, 1);
 2619 
 2620    } else if(strcmp(name, "HP-PA bootloader   :") == 0) {
 2621      if(mkisofs)
 2622        sprintf(buf, "-hppa-bootloader ");
 2623      else
 2624        sprintf(buf, "-boot_image any hppa_bootloader=");
 2625      Text_shellsafe(textpt, buf, 1);
 2626 
 2627    } else if(strcmp(name, "DEC Alpha ldr adr  :") == 0) {
 2628      if(!have_alpha_ldr_path) {
 2629        sprintf(xorriso->info_text,
 2630                "Cannot enable DEC Alpha boot loader because it is not a data file in the ISO filesystem");
 2631        if(!(flag & 5))
 2632          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2633      }
 2634 
 2635    } else if(strcmp(name, "DEC Alpha ldr path :") == 0) {
 2636      if(mkisofs)
 2637        sprintf(buf, "-alpha-boot ");
 2638      else
 2639        sprintf(buf, "-boot_image any alpha_boot=");
 2640      Text_shellsafe(textpt, buf, 1);
 2641 
 2642    }
 2643    
 2644    if(buf[0])
 2645      Xorriso_record_cmd_linE
 2646  }
 2647 
 2648  if(appended_as_gpt == 2) {
 2649    if(mkisofs)
 2650      sprintf(buf, "-appended_part_as_gpt");
 2651    else
 2652      sprintf(buf, "-boot_image any appended_part_as=gpt");
 2653    Xorriso_record_cmd_linE
 2654  }
 2655 
 2656  if(have_sparc_part) {
 2657    if(full_sparc_part == 255) {
 2658      if(mkisofs) {
 2659        sprintf(buf, "-G ");
 2660        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) 0, (uint64_t) 15, "s",
 2661                              imported_iso);
 2662        Xorriso_record_cmd_linE
 2663        did_sysarea= 1;
 2664        sprintf(buf, "-B ...");
 2665        Xorriso_record_cmd_linE
 2666      } else {
 2667        sprintf(buf, "-boot_image any system_area=");
 2668        Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) 0, (uint64_t) 15, "s",
 2669                              imported_iso);
 2670        Xorriso_record_cmd_linE
 2671        did_sysarea= 1;
 2672        for(i= 2; i <= 8; i++) {
 2673          sprintf(buf, "-append_partition %d 0x00 .", i);
 2674          Xorriso_record_cmd_linE
 2675        }
 2676      }
 2677      cared_for_sparc= 1;
 2678    } else if(!cared_for_sparc) {
 2679      sprintf(xorriso->info_text,
 2680        "Cannot enable SUN Disk Label because of non-trivial partition layout");
 2681      if(!(flag & 5))
 2682        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2683    }
 2684  }
 2685  if(have_sysarea && !did_sysarea) {
 2686    /* Zeroize old partition tables from -indev */
 2687    if(mkisofs)
 2688      sprintf(buf, "-G ");
 2689    else
 2690      sprintf(buf, "-boot_image any system_area=");
 2691    Xorriso_add_intvl_adr(xorriso, buf, (uint64_t) 0, (uint64_t) 15, "s",
 2692                          imported_iso | ptable_killer);
 2693    Xorriso_record_cmd_linE
 2694    did_sysarea= 1;
 2695  }
 2696  if(have_sysarea) {
 2697    strcpy(buf, "systemarea.img/");
 2698    Xorriso_add_offset_size(xorriso, buf, (off_t) 0, (off_t) 16 * 2048, 0);
 2699    Xorriso_record_boot_imglinE
 2700  }
 2701  if(iso_mbr_part_type >= 0) {
 2702    if(mkisofs)
 2703      sprintf(buf, "-iso_mbr_part_type 0x%2.2x",
 2704                   (unsigned int) iso_mbr_part_type);
 2705    else
 2706      sprintf(buf, "-boot_image any iso_mbr_part_type=0x%2.2x",
 2707                   (unsigned int) iso_mbr_part_type);
 2708    Xorriso_record_cmd_linE
 2709 
 2710  } else if(iso_gpt_part_idx >= 0) {
 2711    if(mkisofs)
 2712      sprintf(buf, "-iso_mbr_part_type ");
 2713    else
 2714      sprintf(buf, "-boot_image any iso_mbr_part_type=");
 2715    Xorriso__format_guid(gpts[iso_gpt_part_idx].type_guid, buf + strlen(buf),
 2716                         0);
 2717    Xorriso_record_cmd_linE
 2718    
 2719  }
 2720 
 2721  /* Issue commands related to El Torito */
 2722  if(elto_count <= 0)
 2723    goto after_el_torito;
 2724 
 2725  if(efi_boot_part == 1) {
 2726    if(mkisofs)
 2727      sprintf(buf, "-efi-boot-part --efi-boot-image");
 2728    else
 2729      sprintf(buf, "-boot_image any efi_boot_part=--efi-boot-image");
 2730    Xorriso_record_cmd_linE
 2731  }
 2732  if(cat_path[0]) {
 2733    if(mkisofs)
 2734      sprintf(buf, "-c ");
 2735    else
 2736      sprintf(buf, "-boot_image any cat_path=");
 2737    Text_shellsafe(cat_path, buf, 1);
 2738  } else {
 2739    if(mkisofs)
 2740      sprintf(buf, "--boot-catalog-hide");
 2741    else
 2742      sprintf(buf, "-boot_image any cat_hidden=on");
 2743  }
 2744  Xorriso_record_cmd_linE
 2745  for(idx= 0; idx < elto_count; idx++) {
 2746    if(strcmp(et_imgs[idx].pltf, "UEFI") == 0 &&
 2747       et_imgs[idx].extract_size <= 0) {
 2748      ret= Xorriso_obtain_indev_readsize(xorriso, &indev_blocks, 0);
 2749      if(ret > 0) {
 2750        if(indev_blocks > et_imgs[idx].lba &&
 2751           indev_blocks - et_imgs[idx].lba <= Xorriso_max_endless_uefi_sizE)
 2752          et_imgs[idx].extract_size= indev_blocks - et_imgs[idx].lba;
 2753      }
 2754      if(et_imgs[idx].extract_size <= 0)
 2755  continue;
 2756    }
 2757    sprintf(buf, "eltorito_img%d_", idx + 1);
 2758    for(j= 0; j < 4 && et_imgs[idx].pltf[j] != 0; j++) {
 2759      buf[strlen(buf) + 1]= 0;
 2760      buf[strlen(buf)]= tolower(et_imgs[idx].pltf[j]);
 2761    }
 2762    strcat(buf, ".img/");
 2763    Xorriso_add_offset_size(xorriso, buf, ((off_t) et_imgs[idx].lba) * 2048,
 2764                            ((off_t) et_imgs[idx].extract_size) * 2048, 0);
 2765    Xorriso_record_boot_imglinE
 2766 
 2767    if(et_imgs[idx].ld_seg != 0 && et_imgs[idx].ld_seg != 0x07c0) {
 2768      if(!(flag & 5)) {
 2769        sprintf(xorriso->info_text,
 2770               "Cannot enable EL Torito boot image #%d because its Load Segment is neither 0x0 nor 0x7c0",
 2771               idx + 1);
 2772        Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2773      }
 2774  continue;
 2775    }
 2776    if(idx > 0) {
 2777      if(mkisofs)
 2778        sprintf(buf, "-eltorito-alt-boot");
 2779      else
 2780        sprintf(buf, "-boot_image any next");
 2781      Xorriso_record_cmd_linE
 2782    }
 2783    if(et_imgs[idx].path[0] == 0) {
 2784      /* Check whether appended partition */;
 2785      for(i= 0; i < mbr_count; i++)
 2786        if((mbrpts[i].appended || !mbrpts[i].has_path) &&
 2787           mbrpts[i].start_block == ((uint64_t) et_imgs[idx].lba) * 4 &&
 2788           (mbrpts[i].block_count == (uint64_t) et_imgs[idx].ldsiz ||
 2789            et_imgs[idx].ldsiz == 0 || et_imgs[idx].ldsiz == 1)) 
 2790      break;
 2791      if (i < mbr_count) {
 2792        if(!mbrpts[i].appended) {
 2793          mbrpts[i].appended= 1;
 2794          if(!appended_as_gpt) {
 2795            sprintf(buf, "-append_partition %lu 0x%lx ", (unsigned long) i + 1,
 2796                          (unsigned long) mbrpts[i].ptype);
 2797            Xorriso_add_intvl_adr(xorriso, buf,
 2798                                  (uint64_t) mbrpts[i].start_block,
 2799                                  ((uint64_t) mbrpts[i].start_block) +
 2800                                  mbrpts[i].block_count - 1,
 2801                                  "d", imported_iso);
 2802            Xorriso_record_cmd_linE
 2803 
 2804 #ifdef Not_any_more_because_padding_is_now_after_partitions
 2805            appended_partition= 1;
 2806 #endif
 2807 
 2808            buf[0]= 0;
 2809          }
 2810        }
 2811        sprintf(app_pseudo_paths[idx],
 2812                "--interval:appended_partition_%d_start_%lus_size_%lud:all::",
 2813                i + 1,
 2814                (unsigned long) et_imgs[idx].lba,
 2815                (unsigned long) mbrpts[i].block_count);
 2816        et_imgs[idx].path= app_pseudo_paths[idx];
 2817      }
 2818      if (et_imgs[idx].path[0] == 0 && efi_boot_part != 2) {
 2819        for(i= 0; i < gpt_count; i++) {
 2820          if((have_protective_msdos || appended_as_gpt) && (
 2821             gpts[i].start_block == ((uint64_t) et_imgs[idx].lba) * 4 &&
 2822             (gpts[i].block_count == (uint64_t) et_imgs[idx].ldsiz ||
 2823             et_imgs[idx].ldsiz == 0 || et_imgs[idx].ldsiz == 1)))
 2824        break;
 2825        }
 2826        if (i < gpt_count) {
 2827          sprintf(app_pseudo_paths[idx],
 2828                  "--interval:appended_partition_%d_start_%lus_size_%lud:all::",
 2829                  i + 1,
 2830                  (unsigned long) et_imgs[idx].lba,
 2831                  (unsigned long) gpts[i].block_count);
 2832          et_imgs[idx].path= app_pseudo_paths[idx];
 2833        }
 2834      }
 2835 
 2836      if (et_imgs[idx].path[0] == 0) {
 2837 
 2838        /* >>> need way to exploit .extract_size by cutting out from ISO */;
 2839 
 2840      }
 2841 
 2842      if (et_imgs[idx].path[0] == 0) {
 2843        if(!(flag & 5)) {
 2844          sprintf(xorriso->info_text,
 2845               "Cannot enable EL Torito boot image #%d because it is not a data file in the ISO filesystem",
 2846               idx + 1);
 2847          Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2848        }
 2849        buf[0]= 0;
 2850  continue;
 2851      }
 2852    }
 2853    if(et_imgs[idx].platform_id != 0xef) {
 2854      if(mkisofs) {
 2855        if(prev_pltf != et_imgs[idx].platform_id) {
 2856          sprintf(buf, "-eltorito-platform 0x%2.2x", et_imgs[idx].platform_id);
 2857          Xorriso_record_cmd_linE
 2858        }
 2859        prev_pltf= et_imgs[idx].platform_id;
 2860        sprintf(buf, "-b ");
 2861      } else {
 2862        sprintf(buf, "-boot_image %s bin_path=", et_imgs[idx].boot_image_type);
 2863      }
 2864    } else {
 2865      if(mkisofs)
 2866        sprintf(buf, "-e ");
 2867      else
 2868        sprintf(buf, "-boot_image %s efi_path=", et_imgs[idx].boot_image_type);
 2869    }
 2870    Text_shellsafe(et_imgs[idx].path, buf, 1);
 2871    Xorriso_record_cmd_linE
 2872    if(!mkisofs) {
 2873      sprintf(buf, "-boot_image any platform_id=0x%2.2x",
 2874                   et_imgs[idx].platform_id);
 2875      Xorriso_record_cmd_linE
 2876    }
 2877    if(strcmp(et_imgs[idx].emul, "none") == 0) {
 2878      if(mkisofs)
 2879        sprintf(buf, "-no-emul-boot");
 2880      else
 2881        sprintf(buf, "-boot_image any emul_type=no_emulation");
 2882    } else if(strcmp(et_imgs[idx].emul, "hd") == 0) {
 2883      if(mkisofs)
 2884        sprintf(buf, "-hard-disk-boot");
 2885      else
 2886        sprintf(buf, "-boot_image any emul_type=hard_disk");
 2887    } else {
 2888      if(mkisofs)
 2889        buf[0]= 0;
 2890      else
 2891        sprintf(buf, "-boot_image any emul_type=diskette");
 2892    }
 2893    if(buf[0])
 2894      Xorriso_record_cmd_linE
 2895    if(et_imgs[idx].ldsiz >= 0) {
 2896      if(mkisofs)
 2897        sprintf(buf, "-boot-load-size %d", et_imgs[idx].ldsiz);
 2898      else
 2899        sprintf(buf, "-boot_image any load_size=%d", et_imgs[idx].ldsiz * 512);
 2900      Xorriso_record_cmd_linE
 2901    }
 2902    if(et_imgs[idx].boot_info_table) {
 2903      if(mkisofs)
 2904        sprintf(buf, "-boot-info-table");
 2905      else
 2906        sprintf(buf, "-boot_image any boot_info_table=on");
 2907      Xorriso_record_cmd_linE
 2908    }
 2909    if(et_imgs[idx].grub2_boot_info) {
 2910      if(mkisofs)
 2911        sprintf(buf, "--grub2-boot-info");
 2912      else
 2913        sprintf(buf, "-boot_image grub grub2_boot_info=on");
 2914      Xorriso_record_cmd_linE
 2915    }
 2916    if(et_imgs[idx].id_string[0] != 0) {
 2917      if(mkisofs)
 2918        sprintf(buf, "-eltorito-id ");
 2919      else
 2920        sprintf(buf, "-boot_image any id_string=");
 2921      Text_shellsafe(et_imgs[idx].id_string, buf, 1);
 2922      Xorriso_record_cmd_linE
 2923    }
 2924    if(et_imgs[idx].sel_crit[0] != 0) {
 2925      if(mkisofs)
 2926        sprintf(buf, "-eltorito-selcrit ");
 2927      else
 2928        sprintf(buf, "-boot_image any sel_crit=");
 2929      Text_shellsafe(et_imgs[idx].sel_crit, buf, 1);
 2930      Xorriso_record_cmd_linE
 2931    }
 2932    if(et_imgs[idx].do_gpt_basdat &&
 2933      !(et_imgs[idx].do_gpt_basdat == 3 && 
 2934        strstr(et_imgs[idx].path, "--interval:appended_partition_") ==
 2935        et_imgs[idx].path)) { /* (not with appended EFI partition) */
 2936      if(mkisofs)
 2937        sprintf(buf, "-isohybrid-gpt-basdat");
 2938      else
 2939        sprintf(buf, "-boot_image isolinux partition_entry=gpt_basdat");
 2940      Xorriso_record_cmd_linE
 2941    }
 2942    if(et_imgs[idx].do_gpt_hfsplus) {
 2943      if(mkisofs)
 2944        sprintf(buf, "-isohybrid-gpt-hfsplus");
 2945      else
 2946        sprintf(buf, "-boot_image isolinux partition_entry=gpt_hfsplus");
 2947      Xorriso_record_cmd_linE
 2948    }
 2949    if(et_imgs[idx].do_apm_hfsplus) {
 2950      if(mkisofs)
 2951        sprintf(buf, "-isohybrid-apm-hfsplus");
 2952      else
 2953        sprintf(buf, "-boot_image isolinux partition_entry=apm_hfsplus");
 2954      Xorriso_record_cmd_linE
 2955    }
 2956  }
 2957 after_el_torito:
 2958 
 2959  if((apm_count > 0 && !cared_for_apm) && !(flag & 5)) {
 2960    sprintf(xorriso->info_text,
 2961            "Cannot make proposal to produce APM of loaded image");
 2962    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
 2963  }
 2964 
 2965 #ifdef Not_any_more_because_padding_is_now_after_partitions
 2966 
 2967  if(appended_partition) {
 2968    if(mkisofs)
 2969      sprintf(buf, "-no-pad");
 2970    else
 2971      sprintf(buf, "-padding 0");
 2972    Xorriso_record_cmd_linE
 2973  }
 2974 
 2975 #endif /* Not_any_more_because_padding_is_now_after_partitions */
 2976 
 2977  ret= 1;
 2978 ex:
 2979  xorriso->show_hfs_cmds= NULL;
 2980  Findjob_destroy(&job, 0);
 2981  Xorriso_free_meM(apms);
 2982  Xorriso_free_meM(gpts);
 2983  Xorriso_free_meM(mbrpts);
 2984  if(app_pseudo_paths != NULL) {
 2985    for(i= 0; i < elto_count; i++)
 2986      if(app_pseudo_paths[i] != NULL)
 2987        Xorriso_free_meM(app_pseudo_paths[i]);
 2988    Xorriso_free_meM(app_pseudo_paths);
 2989  }
 2990  Xorriso_free_meM(et_imgs);
 2991  Xorriso_free_meM(lines);
 2992  Xorriso_free_meM(buf);
 2993  return(ret);
 2994 
 2995 #undef Xorriso_record_cmd_linE
 2996 #undef Xorriso_record_boot_imglinE
 2997 #undef Xorriso_max_endless_uefi_sizE
 2998 
 2999 }
 3000 
 3001 
 3002 /* @param flag bit0= currently not significant:
 3003                      report is about El Torito rather than System Area
 3004                bit1= report -as mkisofs options in cmds
 3005                bit2= no sorry messages
 3006                bit15= dispose cmds and boot_imgs
 3007 */
 3008 static int Xorriso_report_to_cmd(struct XorrisO *xorriso,
 3009                                  char **et_lines, int et_line_count,
 3010                                  char **sa_lines, int sa_line_count,
 3011                                  char ***cmds, int *cmd_count,
 3012                                  char ***boot_imgs, int *boot_img_count,
 3013                                  int flag)
 3014 {
 3015  int ret= 0, i;
 3016 
 3017  if(flag & (1 << 15))
 3018    {ret= 1; goto ex;}
 3019  *cmds= NULL;
 3020  *cmd_count= 0;
 3021 
 3022  /* Count commands */
 3023  ret= Xorriso_scan_report_lines(xorriso, et_lines, et_line_count,
 3024                                 sa_lines, sa_line_count, *cmds, cmd_count,
 3025                                 *boot_imgs, boot_img_count,
 3026                                 1 | (flag & 6));
 3027  if(ret <= 0)
 3028    goto ex;
 3029 
 3030  if(*cmd_count <= 0 && *boot_img_count <= 0)
 3031    {ret= 2; goto ex;}
 3032  if(*cmd_count > 0) {
 3033    Xorriso_alloc_meM(*cmds, char *, *cmd_count);
 3034    for(i= 0; i < *cmd_count; i++)
 3035      (*cmds)[i]= NULL;
 3036  }
 3037  if(*boot_img_count > 0) {
 3038    Xorriso_alloc_meM(*boot_imgs, char *, *boot_img_count);
 3039    for(i= 0; i < *boot_img_count; i++)
 3040      (*boot_imgs)[i]= NULL;
 3041  }
 3042  
 3043  /* Record commands */
 3044  ret= Xorriso_scan_report_lines(xorriso, et_lines, et_line_count, 
 3045                                 sa_lines, sa_line_count, *cmds, cmd_count,
 3046                                 *boot_imgs, boot_img_count,
 3047                                 flag & 6);
 3048  if(ret <= 0)
 3049    goto ex;
 3050 
 3051  ret= 1;
 3052 ex:
 3053  if(ret <= 0 || (flag & (1 << 15))) {
 3054    if(*cmds != NULL) {
 3055      for(i= 0; i < *cmd_count; i++)
 3056        if((*cmds)[i] != NULL)
 3057          Xorriso_free_meM((*cmds)[i]);
 3058      Xorriso_free_meM(*cmds);
 3059      *cmds= NULL;
 3060    }
 3061    if(*boot_imgs != NULL) {
 3062      for(i= 0; i < *boot_img_count; i++)
 3063        if((*boot_imgs)[i] != NULL)
 3064          Xorriso_free_meM((*boot_imgs)[i]);
 3065      Xorriso_free_meM(*boot_imgs);
 3066      *boot_imgs= NULL;
 3067    }
 3068  }
 3069  return(ret); 
 3070 }
 3071 
 3072 
 3073 
 3074 static void Xorriso_report_lines(struct XorrisO *xorriso,
 3075                                 char **lines, int line_count)
 3076 {
 3077  int i;
 3078 
 3079  for(i = 0; i < line_count ; i++) {
 3080    sprintf(xorriso->result_line, "%s\n", lines[i]);
 3081    Xorriso_result(xorriso,0);
 3082  }
 3083 } 
 3084 
 3085 
 3086 /* @param flag bit0= report El Torito rather than System Area
 3087                bit1= with form "cmd" do not report but rather execute
 3088 */
 3089 int Xorriso_report_system_area(struct XorrisO *xorriso, char *form, int flag)
 3090 {
 3091  int ret, line_count, cmd_count= 0, et_line_count= 0, sa_line_count= 0;
 3092  int do_cmd= 0, as_mkisofs= 0, i, bin_count, boot_img_count= 0;
 3093  char **lines = NULL, **et_lines= NULL, **sa_lines= NULL, **cmds= NULL;
 3094  char **boot_imgs= NULL;
 3095  uint8_t guid[16];
 3096  IsoImage *image;
 3097 
 3098  if(strcmp(form, "cmd") == 0 || strcmp(form, "as_mkisofs") == 0 || (flag & 2))
 3099    do_cmd= 1;
 3100  if(strcmp(form, "as_mkisofs") == 0)
 3101    as_mkisofs= 1;
 3102 
 3103  if(strcmp(form, "help") == 0) {
 3104    if(flag & 1)
 3105      ret= iso_image_report_el_torito(NULL, &et_lines, &et_line_count, 1);
 3106    else
 3107      ret= iso_image_report_system_area(NULL, &sa_lines, &sa_line_count, 1);
 3108    if(ret <= 0)
 3109      goto ex;
 3110    sprintf(xorriso->result_line,
 3111 "------------------------------------------------------------------------------\n");
 3112    Xorriso_result(xorriso, 0);
 3113    if(flag & 1)
 3114    sprintf(xorriso->result_line, "With -report_el_torito \"plain\":\n");
 3115    else
 3116      sprintf(xorriso->result_line, "With -report_system_area \"plain\":\n");
 3117    Xorriso_result(xorriso, 0);
 3118    sprintf(xorriso->result_line,
 3119 "------------------------------------------------------------------------------\n");
 3120    Xorriso_result(xorriso, 0);
 3121    sprintf(xorriso->result_line, "\n");
 3122    Xorriso_result(xorriso, 0);
 3123 
 3124  } else if(strcmp(form, "") == 0 || strcmp(form, "plain") == 0 || do_cmd) {
 3125    ret= Xorriso_get_volume(xorriso, &image, 0);
 3126    if(ret <= 0)
 3127      goto ex;
 3128    if(do_cmd || (flag & 1))
 3129      ret= iso_image_report_el_torito(image, &et_lines, &et_line_count, 0);
 3130    if(ret < 0)
 3131      goto ex;
 3132    if(do_cmd || !(flag & 1))
 3133      ret= iso_image_report_system_area(image, &sa_lines, &sa_line_count, 0);
 3134    if(ret < 0)
 3135      goto ex;
 3136    if(do_cmd) {
 3137      ret= Xorriso_report_to_cmd(xorriso, et_lines, et_line_count,
 3138                                 sa_lines, sa_line_count, &cmds, &cmd_count,
 3139                                 &boot_imgs, &boot_img_count,
 3140                                 (flag & 1) | (as_mkisofs << 1));
 3141      if(ret <= 0)
 3142        goto ex;
 3143    }
 3144 
 3145  } else if(strncmp(form, "gpt_crc_of:", 11) == 0 && !(flag & 1)) {
 3146    ret = Xorriso_gpt_crc(xorriso, form + 11, 0);
 3147    goto ex;
 3148 
 3149  } else if(strcmp(form, "make_guid") == 0 && !(flag & 1)) {
 3150    ret= Xorriso_make_guid(xorriso, xorriso->result_line, 0);
 3151    if(ret < 0)
 3152      goto ex;
 3153    strcat(xorriso->result_line, "\n");
 3154    Xorriso_result(xorriso,0);
 3155    goto ex;
 3156 
 3157  } else if(strcmp(form, "gpt_disk_guid") == 0 && !(flag & 1)) {
 3158    ret= Xorriso_get_volume(xorriso, &image, 0);
 3159    if(ret <= 0)
 3160      goto ex;
 3161    ret= iso_image_report_system_area(image, &sa_lines, &sa_line_count, 0);
 3162    if(ret <= 0)
 3163      goto ex;
 3164    for(i= 0; i < sa_line_count; i++) {
 3165      if(strncmp(sa_lines[i], "GPT disk GUID      :      ", 26) == 0) {
 3166        ret= Hex_to_bin(sa_lines[i] + 26, 16, &bin_count, guid, 0);
 3167        if(ret < 0 || bin_count != 16)
 3168    break;
 3169        Xorriso_format_guid(xorriso, guid, xorriso->result_line, 0);
 3170        strcat(xorriso->result_line, "\n");
 3171        Xorriso_result(xorriso,0);
 3172        ret= 1;
 3173        goto ex;
 3174      }
 3175    }
 3176    ret= 1;
 3177    goto ex;
 3178    
 3179  } else {
 3180    sprintf(xorriso->info_text,
 3181            "%s form parameter not recognized: ",
 3182            flag & 1 ? "-report_el_torito" : "-report_system_area");
 3183    Text_shellsafe(form, xorriso->info_text, 1);
 3184    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
 3185    ret= 0; goto ex;
 3186  }
 3187  if(ret < 0)
 3188    goto ex;
 3189  if(flag & 1) {
 3190    lines= et_lines;
 3191    line_count= et_line_count;
 3192  } else {
 3193    lines= sa_lines;
 3194    line_count= sa_line_count;
 3195  }
 3196  if(!do_cmd) {
 3197    if(lines == NULL || ret == 0) {
 3198      if(flag & 1)
 3199        strcpy(xorriso->info_text, "No El Torito information was loaded");
 3200      else
 3201        strcpy(xorriso->info_text, "No System Area was loaded");
 3202      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 3203      ret= 2; goto ex;
 3204    }
 3205    if(line_count == 0) {
 3206      if(flag & 1)
 3207        strcpy(xorriso->info_text, "No El Torito information available");
 3208      else
 3209        strcpy(xorriso->info_text, "System Area only contains 0-bytes");
 3210      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 3211      ret= 2; goto ex;
 3212    }
 3213  }
 3214  if(flag & 2) {
 3215    if(cmd_count > 0) {
 3216      ret= Xorriso_execute_option(xorriso,
 3217                "-boot_image any discard -boot_image any system_area=/dev/zero",
 3218                1 | 16);
 3219      if(ret <= 0)
 3220        goto ex;
 3221      for(i= 0; i < cmd_count; i++) {
 3222        ret= Xorriso_execute_option(xorriso, cmds[i], 1 | 16);
 3223        if(ret <= 0)
 3224          goto ex;
 3225      }
 3226      sprintf(xorriso->info_text,
 3227              "Replayed %d boot related commands", cmd_count);
 3228      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
 3229    } else {
 3230      Xorriso_msgs_submit(xorriso, 0,
 3231                          "No proposals available for boot related commands",
 3232                          0, "NOTE", 0);
 3233      ret= 2; goto ex;
 3234    }
 3235  } else if(do_cmd) {
 3236    Xorriso_report_lines(xorriso, cmds, cmd_count);
 3237  } else {
 3238    Xorriso_report_lines(xorriso, lines, line_count);
 3239  }
 3240  ret= 1;
 3241 ex:;
 3242  Xorriso_report_to_cmd(xorriso, NULL, 0, NULL, 0, &cmds, &cmd_count,
 3243                        &boot_imgs, &boot_img_count, 1 << 15);
 3244  if(et_lines != NULL)
 3245    iso_image_report_el_torito(NULL, &et_lines, &et_line_count, 1 << 15);
 3246  if(sa_lines != NULL)
 3247    iso_image_report_system_area(NULL, &sa_lines, &sa_line_count, 1 << 15);
 3248  return(ret);
 3249 }
 3250 
 3251 
 3252 /* @param flag bit15= dispose imgs
 3253  */
 3254 int Xorriso_list_boot_images(struct XorrisO *xorriso,
 3255                              char ***imgs, int *img_count, int flag)
 3256 {
 3257  int ret, cmd_count= 0, et_line_count= 0, sa_line_count= 0, boot_img_count= 0;
 3258  char **et_lines= NULL, **sa_lines= NULL, **cmds= NULL, **boot_imgs= NULL;
 3259  IsoImage *image;
 3260 
 3261  if(flag & (1 << 15)) {
 3262    boot_imgs= *imgs;
 3263    boot_img_count= *img_count;
 3264    Xorriso_report_to_cmd(xorriso, NULL, 0, NULL, 0, &cmds, &cmd_count,
 3265                          &boot_imgs, &boot_img_count, 1 << 15);
 3266    *imgs= NULL;
 3267    *img_count= 0;
 3268    return(1);
 3269  }
 3270 
 3271  *imgs= NULL;
 3272  *img_count= 0;
 3273 
 3274  ret= Xorriso_get_volume(xorriso, &image, 0);
 3275  if(ret <= 0)
 3276    goto ex;
 3277  ret= iso_image_report_el_torito(image, &et_lines, &et_line_count, 0);
 3278  if(ret < 0)
 3279    goto ex;
 3280  ret= iso_image_report_system_area(image, &sa_lines, &sa_line_count, 0);
 3281  if(ret < 0)
 3282    goto ex;
 3283  ret= Xorriso_report_to_cmd(xorriso, et_lines, et_line_count,
 3284                             sa_lines, sa_line_count, &cmds, &cmd_count,
 3285                             &boot_imgs, &boot_img_count, 4);
 3286  if(ret <= 0)
 3287    goto ex;
 3288  *imgs= boot_imgs;
 3289  *img_count= boot_img_count;
 3290  boot_imgs= NULL;
 3291  boot_img_count= 0;
 3292  ret= 1;
 3293 ex:;
 3294  Xorriso_report_to_cmd(xorriso, NULL, 0, NULL, 0, &cmds, &cmd_count,
 3295                        &boot_imgs, &boot_img_count, 1 << 15);
 3296  if(et_lines != NULL)
 3297    iso_image_report_el_torito(NULL, &et_lines, &et_line_count, 1 << 15);
 3298  if(sa_lines != NULL)
 3299    iso_image_report_system_area(NULL, &sa_lines, &sa_line_count, 1 << 15);
 3300  return(ret);
 3301 }
 3302