1 
2 
3 
4 /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
5 
6    Copyright 2007-2017 Thomas Schmitt, <scdbackup@gmx.net>
7 
8    Provided under GPL version 2 or later.
9 
10    This file contains functions which are needed to read data
11    from ISO image.
12 */
13 
14 #ifdef HAVE_CONFIG_H
15 #include "../config.h"
16 #endif
17 
18 #include <ctype.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <sys/stat.h>
25 #include <sys/time.h>
26 #include <time.h>
27 #include <errno.h>
28 #include <pthread.h>
29 
30 #ifdef HAVE_STDINT_H
31 #include <stdint.h>
32 #else
33 #ifdef HAVE_INTTYPES_H
34 #include <inttypes.h>
35 #endif
36 #endif
37 
38 #ifdef Xorriso_standalonE
39 
40 #ifdef Xorriso_with_libjtE
41 #include "../libjte/libjte.h"
42 #endif
43 
44 #else
45 
46 #ifdef Xorriso_with_libjtE
47 #include <libjte/libjte.h>
48 #endif
49 
50 #endif /* ! Xorriso_standalonE */
51 
52 #include "xorriso.h"
53 #include "xorriso_private.h"
54 
55 #include "base_obj.h"
56 #include "lib_mgt.h"
57 
58 
59 
60 /* See Xorriso__preset_signal_behavior() */
61 static int Xorriso_signal_behavioR= 1;
62 
63 
Xorriso__version(int * major,int * minor,int * micro)64 void Xorriso__version(int *major, int *minor, int *micro)
65 {
66  *major= Xorriso_header_version_majoR;
67  *minor= Xorriso_header_version_minoR;
68  *micro= Xorriso_header_version_micrO;
69 }
70 
71 
Xorriso__is_compatible(int major,int minor,int micro,int flag)72 int Xorriso__is_compatible(int major, int minor, int micro, int flag)
73 {
74  int own_major, own_minor, own_micro;
75 
76  Xorriso__version(&own_major, &own_minor, &own_micro);
77  return(own_major > major ||
78         (own_major == major && (own_minor > minor ||
79          (own_minor == minor && own_micro >= micro))));
80 }
81 
82 
Xorriso__get_patch_level_text(int flag)83 char *Xorriso__get_patch_level_text(int flag)
84 {
85  return(Xorriso_program_patch_leveL);
86 }
87 
88 
89 /** The list of startup file names */
90 #define Xorriso_rc_nuM 4
91 
92 static char Xorriso_sys_rc_nameS[Xorriso_rc_nuM][80]= {
93  "/etc/default/xorriso",
94  "/etc/opt/xorriso/rc",
95  "/etc/xorriso/xorriso.conf",
96  "placeholder for $HOME/.xorrisorc"
97 };
98 
99 
Xorriso_new(struct XorrisO ** xorriso,char * progname,int flag)100 int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
101 {
102  int i, ret;
103  struct XorrisO *m;
104  char *leafname= NULL;
105 
106  leafname= TSOB_FELD(char, SfileadrL);
107  if(leafname == NULL)
108    return(-1);
109  *xorriso= m= TSOB_FELD(struct XorrisO,1);
110  if(m==NULL) {
111    free(leafname);
112    return(-1);
113  }
114 
115  /* Base initialization by actions which must not fail */
116 
117  m->libs_are_started= 0;
118  strncpy(m->progname,progname,sizeof(m->progname)-1);
119  m->progname[sizeof(m->progname)-1]= 0;
120  if(getcwd(m->initial_wdx,sizeof(m->initial_wdx)-1)==NULL)
121    m->initial_wdx[0]= 0;
122  m->no_rc= 0;
123  m->argument_emulation= 0;
124 
125  m->rc_filename_count= Xorriso_rc_nuM;
126  for(i=0;i<m->rc_filename_count-1;i++)
127    strcpy(m->rc_filenames[i],Xorriso_sys_rc_nameS[i]);
128  m->rc_filenames[m->rc_filename_count-1][0]= 0;
129  m->arrange_args= 0;
130  m->mkisofsrc_done= 0;
131 
132  m->wdi[0]= 0;
133  strcpy(m->wdx, m->initial_wdx);
134  m->did_something_useful= 0;
135  m->add_plainly= 0;
136  m->split_size= 0;
137  strcpy(m->list_delimiter, "--");
138  m->ino_behavior= 1 | 2 | 4 | 32;      /* off:no_lsl_count */
139  m->iso_level= 3;
140  m->iso_level_is_default= 1;
141  m->do_joliet= 0;
142  m->do_hfsplus= 0;
143  m->do_fat= 0;
144  m->do_rockridge= 1;
145  m->do_iso1999= 0;
146  m->ecma119_map= 1;
147  m->do_aaip= 0;
148  m->do_md5= 0;
149  m->no_emul_toc= 0;
150  m->do_old_empty= 0;
151  m->scdbackup_tag_name[0]= 0;
152  m->scdbackup_tag_time[0]= 0;
153  m->scdbackup_tag_written[0]= 0;
154  m->scdbackup_tag_listname[0]= 0;
155  m->relax_compliance= 0;
156  m->allow_dir_id_ext_dflt= 1;
157  m->rr_reloc_dir[0]= 0;
158  m->rr_reloc_flags= 1;
159  m->untranslated_name_len= 0;
160  m->do_follow_pattern= 1;
161  m->do_follow_param= 0;
162  m->do_follow_links= 0;
163  m->follow_link_limit= 100;
164  m->resolve_link_rec_count= 0;
165  m->resolve_link_rec_limit= 100;
166  m->do_follow_concat= 0;
167  m->do_follow_mount= 1;
168  m->do_global_uid= 0;
169  m->global_uid= 0;
170  strcpy(m->volid, "ISOIMAGE");
171  m->volid_default= 1;
172  m->loaded_volid[0]= 0;
173  m->assert_volid[0]= 0;
174  m->assert_volid_sev[0]= 0;
175  m->preparer_id[0]= 0;
176  m->publisher[0]= 0;
177  m->application_id[0]= 0;
178  m->system_id[0]= 0;
179  m->volset_id[0]= 0;
180  m->copyright_file[0]= 0;
181  m->biblio_file[0]= 0;
182  m->abstract_file[0]= 0;
183  strcpy(m->application_use, " ");
184  m->session_logfile[0]= 0;
185  m->session_lba= -1;
186  m->session_blocks= 0;
187  m->do_global_gid= 0;
188  m->global_gid= 0;
189  m->do_global_mode= 0;
190  m->global_dir_mode= 0555;
191  m->global_file_mode= 0444;
192  m->do_tao= 0;
193  m->filters= NULL;
194  m->filter_list_closed= 0;
195  m->zlib_level_default= m->zlib_level= 6;
196  m->zisofs_block_size= m->zisofs_block_size_default= (1 << 15);
197  m->zisofs_by_magic= 0;
198  m->do_overwrite= 2;
199  m->do_reassure= 0;
200  m->drive_blacklist= NULL;
201  m->drive_greylist= NULL;
202  m->drive_whitelist= NULL;
203  m->toc_emulation_flag= 0;
204  m->image_start_mode= 0;
205  m->image_start_value[0]= 0;
206  m->displacement= 0;
207  m->displacement_sign= 0;
208  m->read_fs= 0;
209  m->drives_exclusive= 1;
210  m->linux_scsi_dev_family= 0;
211  m->early_stdio_test= 0;
212  m->cache_num_tiles= 0;
213  m->cache_tile_blocks= 0;
214  m->cache_default= 1 | 2;
215  m->do_calm_drive= 1;
216  m->indev[0]= 0;
217  m->in_drive_handle= NULL;
218  m->in_volset_handle= NULL;
219  m->in_charset= NULL;
220  m->isofs_st_out= time(0) - 1;
221  m->indev_is_exclusive= 1;
222  m->indev_off_adr[0]= 0;
223  m->isofs_st_in= 0;
224  m->volset_change_pending= 0;
225  m->no_volset_present= 0;
226  m->in_sector_map= NULL;
227  m->check_media_default= NULL;
228  m->check_media_bad_limit= Xorriso_read_quality_invaliD;
229  m->outdev[0]= 0;
230  m->out_drive_handle= NULL;
231  m->out_charset= NULL;
232  m->dev_fd_1= -1;
233  m->outdev_is_exclusive= 1;
234  m->outdev_off_adr[0]= 0;
235  m->grow_blindly_msc2= -1;
236  m->ban_stdio_write= 0;
237  m->do_dummy= 0;
238  m->do_close= 0;
239  m->auto_close= 0;
240  m->write_speed= 0;  /* max */
241  m->read_speed= -2;  /* do not set */
242  m->fs= 4*512; /* 4 MiB */
243  m->padding= 300*1024;
244  m->do_padding_by_libisofs= 0;
245  m->alignment= 0;
246  m->do_stream_recording= 0;
247  m->dvd_obs= 0;
248  m->modesty_on_drive= 0;
249  m->min_buffer_usec= 5000;
250  m->max_buffer_usec= 25000;
251  m->buffer_timeout_sec= 120;
252  m->min_buffer_percent= 90;
253  m->max_buffer_percent= 95;
254  m->use_immed_bit= 0;
255  m->use_immed_bit_default= 0;
256  m->stdio_sync= 0;
257  m->stdio_sync_is_default= 1;
258  m->keep_boot_image= 0;
259  m->boot_image_cat_path[0]= 0;
260  m->boot_image_cat_hidden= 0;
261  m->boot_count= 0;
262  m->boot_platform_id= 0x00; /* El Torito Boot Catalog Platform ID: 0 = 80x86 */
263  m->patch_isolinux_image= 0;
264  m->boot_image_bin_path[0]= 0;
265  m->boot_image_bin_form[0]= 0;
266  m->boot_image_emul= 0;
267  m->boot_emul_default= 1;
268  m->boot_image_load_size= 4 * 512;     /* hearsay out of libisofs/demo/iso.c */
269  m->boot_img_size_default= 1;
270  m->boot_img_full_size= 0;
271  memset(m->boot_id_string, 0, sizeof(m->boot_id_string));
272  memset(m->boot_selection_crit, 0, sizeof(m->boot_selection_crit));
273 
274 #ifdef Xorriso_with_isohybriD
275  m->boot_image_isohybrid= 1;
276 #else
277  m->boot_image_isohybrid= 0;
278 #endif
279 
280  m->boot_efi_default= 0;
281  m->system_area_disk_path[0]= 0;
282  m->system_area_clear_loaded= 0;
283  m->system_area_options= 0;
284  m->patch_system_area= 0;
285  m->partition_offset= 0;
286  m->partition_secs_per_head= 0;
287  m->partition_heads_per_cyl= 0;
288  m->prep_partition[0]= 0;
289  m->efi_boot_partition[0]= 0;
290  for(i= 0; i < Xorriso_max_appended_partitionS; i++) {
291    m->appended_partitions[i]= NULL;
292    m->appended_part_types[i]= 0;
293  }
294  m->appended_as_gpt= 0;
295  m->appended_as_apm= 0;
296  m->part_like_isohybrid= 0;
297  m->iso_mbr_part_type= -1;
298  memset(m->gpt_guid, 0, 16);
299  m->gpt_guid_mode= 0;
300  m->ascii_disc_label[0]= 0;
301  m->grub2_sparc_core[0]= 0;
302  memset(m->hfsp_serial_number, 0, 8);
303  m->hfsp_block_size= 0;
304  m->apm_block_size= 0;
305  m->vol_creation_time= 0;
306  m->vol_modification_time= 0;
307  m->vol_expiration_time= 0;
308  m->vol_effective_time= 0;
309  m->vol_uuid[0]= 0;
310  m->all_file_dates[0]= 0;
311 
312 #ifdef Xorriso_with_libjtE
313  m->libjte_handle= NULL;
314 #endif
315 
316  m->jigdo_params= NULL;
317  m->jigdo_values= NULL;
318  m->libjte_params_given= 0;
319  m->loaded_boot_bin_lba= 0;
320  m->loaded_boot_cat_path[0]= 0;
321  m->allow_graft_points= 0;
322  m->allow_restore= 0;
323  m->do_concat_split= 1;
324  m->do_auto_chmod= 0;
325  m->do_restore_sort_lba= 0;
326  m->do_strict_acl= 0;
327  m->dialog= 0;
328  m->buffered_dialog= NULL;
329  m->bsl_interpretation= 0;
330  m->sh_style_result= 0;
331  m->search_mode= 0;
332  m->structured_search= 1;
333  m->do_iso_rr_pattern= 1;
334  m->do_disk_pattern= 2;
335  m->temp_mem_limit= 16*1024*1024;
336  m->file_size_limit= Xorriso_default_file_size_limiT;
337  m->file_name_limit= 255;
338  m->disk_exclusions= NULL;
339  m->iso_rr_hidings= NULL;
340  m->joliet_hidings= NULL;
341  m->hfsplus_hidings= NULL;
342  m->disk_excl_mode= 1;
343  m->use_stdin= 0;
344  m->tolerate_stdin_eof= 0;
345  m->result_page_length= 0;
346  m->result_page_width= 80;
347  m->mark_text[0]= 0;
348  m->packet_output= 0;
349  for(i=0; i<4; i++) {
350    m->logfile[i][0]= 0;
351    m->logfile_fp[i]= NULL;
352  }
353  m->pktlog_fp= NULL;
354  m->stderr_fp= NULL;
355  for(i= 0; i < Xorriso_max_outlist_stacK; i++) {
356    m->result_msglists[i]= NULL;
357    m->info_msglists[i]= NULL;
358    m->msglist_flags[i]= 0;
359  }
360  m->lib_msg_queue_lock_ini= 0;
361  m->result_msglists_lock_ini= 0;
362  m->write_to_channel_lock_ini= 0;
363  m->msg_watcher_lock_ini= 0;
364  m->msg_watcher_state= 0;
365  m->msgw_result_handler= NULL;
366  m->msgw_result_handle= NULL;
367  m->msgw_info_handler= NULL;
368  m->msgw_info_handle= NULL;
369  m->msgw_stack_handle= -1;
370  m->msgw_msg_pending= 0;
371  m->msgw_fetch_lock_ini= 0;
372  m->msg_sieve= NULL;
373  m->msg_sieve_disabled= 0;
374  m->msglist_stackfill= 0;
375  m->status_history_max= Xorriso_status_history_maX;
376  m->scsi_log= 0;
377  strcpy(m->report_about_text, "UPDATE");
378  Xorriso__text_to_sev(m->report_about_text, &m->report_about_severity, 0);
379  m->library_msg_direct_print= 0;
380  strcpy(m->abort_on_text,"FAILURE");
381  Xorriso__text_to_sev(m->abort_on_text, &m->abort_on_severity, 0);
382  m->abort_on_is_default= 1;
383  m->problem_status= 0;
384  m->problem_status_lock_ini= 0;
385  m->problem_status_text[0]= 0;
386  m->errfile_log[0]= 0;
387  m->errfile_mode= 0;
388  m->errfile_fp= NULL;
389 
390  m->img_read_error_mode= 1;       /* abort faulty image reading with FAILURE */
391  m->extract_error_mode= 1;          /* keep extracted files after read error */
392  strcpy(m->return_with_text, "SORRY");
393  Xorriso__text_to_sev(m->return_with_text, &m->return_with_severity, 0);
394  m->return_with_value= 32;
395  m->eternal_problem_status= 0;
396  m->eternal_problem_status_text[0]= 0;
397  m->re= NULL;
398  /* >>> ??? how to initialize m->match[0] ? */
399  m->re_constants= NULL;
400  m->re_count= 0;
401  m->re_fill= 0;
402  m->reg_expr[0]= 0;
403  m->run_state= 0;
404  m->is_dialog= 0;
405  m->bar_is_fresh= 0;
406  m->pending_option[0]= 0;
407  m->request_to_abort= 0;
408  m->request_not_to_ask= 0;
409  m->idle_time= 0.0;
410  m->re_failed_at= -1;
411  m->prepended_wd= 0;
412  m->insert_count= 0;
413  m->insert_bytes= 0;
414  m->error_count= 0;
415  m->launch_frontend_banned= 0;
416  m->pacifier_style= 0;
417  m->pacifier_interval= 1.0;
418  m->pacifier_count= 0;
419  m->pacifier_prev_count= 0;
420  m->pacifier_total= 0;
421  m->pacifier_byte_count= 0;
422  m->pacifier_fifo= NULL;
423  m->start_time= 0.0;
424  m->last_update_time= 0.0;
425  m->find_compare_result= 1;
426  m->find_check_md5_result= 0;
427  m->last_abort_file_time= 0.0;
428 
429  m->node_counter= 0;
430  m->node_array_size= 0;
431  m->node_array= NULL;
432  m->node_disk_prefixes= NULL;
433  m->node_img_prefixes= NULL;
434 
435  m->hln_count= 0;
436  m->hln_array= NULL;
437  m->hln_targets= NULL;
438  m->hln_change_pending= 0;
439  m->di_do_widen= NULL;
440  m->di_disk_paths= NULL;
441  m->di_iso_paths= NULL;
442 
443  m->node_targets_availmem= 0;
444 
445  m->di_count= 0;
446  m->di_array= NULL;
447 
448  m->perm_stack= NULL;
449 
450  m->update_flags= 0;
451 
452  m->show_hfs_cmd_flag= 0;
453  m->show_hfs_cmd_count= 0;
454  m->show_hfs_cmds= NULL;
455 
456  m->result_line[0]= 0;
457  m->result_line_counter= 0;
458  m->result_page_counter= 0;
459  m->result_open_line_len= 0;
460 
461  m->info_text[0]= 0;
462 
463 
464  /* Here begin actions which might fail */
465 
466  ret= Sfile_leafname(progname, leafname, 0);
467  if(ret<=0)
468    goto failure;
469  if(strcmp(leafname, "osirrox")==0) {
470    m->allow_restore= 1;
471    m->drives_exclusive= 0;
472  } else if(strcmp(leafname, "xorrisofs")==0 || strcmp(leafname, "genisofs")==0 ||
473         strcmp(leafname, "mkisofs")==0 || strcmp(leafname, "genisoimage")==0) {
474    m->argument_emulation= 1;
475    m->pacifier_style= 1;
476    Xorriso_protect_stdout(*xorriso, 0);
477  } else if(strcmp(leafname, "xorrecord")==0 || strcmp(leafname, "wodim")==0 ||
478            strcmp(leafname, "cdrecord")==0 || strcmp(leafname, "cdrskin")==0) {
479    m->argument_emulation= 2;
480    m->pacifier_style= 2;
481  }
482  ret= Exclusions_new(&(m->disk_exclusions), 0);
483  if(ret<=0)
484    goto failure;
485  ret= Exclusions_new(&(m->iso_rr_hidings), 0);
486  if(ret<=0)
487    goto failure;
488  ret= Exclusions_new(&(m->joliet_hidings), 0);
489  if(ret<=0)
490    goto failure;
491  ret= Exclusions_new(&(m->hfsplus_hidings), 0);
492  if(ret<=0)
493    goto failure;
494  Xorriso_relax_compliance(m, "default", 0);
495  ret= Xorriso_lst_new(&(m->drive_greylist), "/dev", m->drive_greylist, 1);
496  if(ret <= 0)
497    goto failure;
498  Xorriso_preparer_string(m, m->preparer_id, 1); /* avoids library calls */
499  ret= pthread_mutex_init(&(m->lib_msg_queue_lock), NULL);
500  if(ret != 0)
501    goto failure;
502  m->lib_msg_queue_lock_ini= 1;
503  ret= pthread_mutex_init(&(m->result_msglists_lock), NULL);
504  if(ret != 0)
505    goto failure;
506  m->result_msglists_lock_ini= 1;
507  ret= pthread_mutex_init(&(m->write_to_channel_lock), NULL);
508  if(ret != 0)
509    goto failure;
510  m->result_msglists_lock_ini= 1;
511  ret= pthread_mutex_init(&(m->problem_status_lock), NULL);
512  if(ret != 0)
513    goto failure;
514  m->problem_status_lock_ini= 1;
515  ret= pthread_mutex_init(&(m->msg_watcher_lock), NULL);
516  if(ret != 0)
517    goto failure;
518  m->msg_watcher_lock_ini= 1;
519  ret= pthread_mutex_init(&(m->msgw_fetch_lock), NULL);
520  if(ret != 0)
521    goto failure;
522  m->msgw_fetch_lock_ini= 1;
523 
524  if(leafname != NULL)
525    free(leafname);
526  return(1);
527 failure:;
528  Xorriso_destroy(xorriso, 0);
529  if(leafname != NULL)
530    free(leafname);
531  return(-1);
532 }
533 
534 
Xorriso_destroy_re(struct XorrisO * m,int flag)535 int Xorriso_destroy_re(struct XorrisO *m, int flag)
536 {
537  int i;
538 
539  if(m->re!=NULL) {
540    for(i=0;i<m->re_fill;i++) {
541      if(m->re_constants!=NULL)
542        if(m->re_constants[i]!=NULL)
543    continue; /* ,->re[i] was never subject to regcomp() */
544      regfree(&(m->re[i]));
545    }
546    free((char *) m->re);
547    m->re= NULL;
548  }
549 
550  if(m->re_constants!=NULL) {
551    for(i=0;i<m->re_fill;i++)
552      if(m->re_constants[i]!=NULL)
553        free(m->re_constants[i]);
554    free((char *) m->re_constants);
555    m->re_constants= NULL;
556  }
557  m->re_count= 0;
558  m->re_fill= 0;
559  return(1);
560 }
561 
562 
563 /* @param flag bit0= global shutdown of libraries */
Xorriso_destroy(struct XorrisO ** xorriso,int flag)564 int Xorriso_destroy(struct XorrisO **xorriso, int flag)
565 {
566  struct XorrisO *m;
567  int i;
568 
569  m= *xorriso;
570  if(m==NULL)
571    return(0);
572 
573  /* Give up drives and image to unref all connected xorriso objects */
574  Xorriso_give_up_drive(m, 3);
575 
576  if(m->in_charset!=NULL)
577    free(m->in_charset);
578  if(m->out_charset!=NULL)
579    free(m->out_charset);
580  Checkmediajob_destroy(&(m->check_media_default), 0);
581  Sectorbitmap_destroy(&(m->in_sector_map), 0);
582  Xorriso_destroy_re(m,0);
583  Exclusions_destroy(&(m->disk_exclusions), 0);
584  Exclusions_destroy(&(m->iso_rr_hidings), 0);
585  Exclusions_destroy(&(m->joliet_hidings), 0);
586  Exclusions_destroy(&(m->hfsplus_hidings), 0);
587  Xorriso_destroy_all_extf(m, 0);
588  Xorriso_lst_destroy_all(&(m->drive_blacklist), 0);
589  Xorriso_lst_destroy_all(&(m->drive_greylist), 0);
590  Xorriso_lst_destroy_all(&(m->drive_whitelist), 0);
591  Xorriso_destroy_node_array(m, 0);
592  Xorriso_destroy_hln_array(m, 0);
593  Xorriso_destroy_di_array(m, 0);
594 
595 #ifdef Xorriso_with_libjtE
596  if(m->libjte_handle)
597    libjte_destroy(&(m->libjte_handle));
598 #endif
599 
600  Xorriso_lst_destroy_all(&(m->jigdo_params), 0);
601  Xorriso_lst_destroy_all(&(m->jigdo_values), 0);
602  for(i= 0; i < Xorriso_max_appended_partitionS; i++)
603    if(m->appended_partitions[i] != NULL)
604      free(m->appended_partitions[i]);
605 
606  Xorriso_detach_libraries(m, flag&1);
607 
608  if(m->lib_msg_queue_lock_ini)
609    pthread_mutex_destroy(&(m->lib_msg_queue_lock));
610  if(m->result_msglists_lock_ini)
611    pthread_mutex_destroy(&(m->result_msglists_lock));
612  if(m->write_to_channel_lock_ini)
613    pthread_mutex_destroy(&(m->write_to_channel_lock));
614  if(m->problem_status_lock_ini)
615    pthread_mutex_destroy(&(m->problem_status_lock));
616  if(m->msg_watcher_lock_ini)
617    pthread_mutex_destroy(&(m->msg_watcher_lock));
618  if(m->msgw_fetch_lock_ini)
619    pthread_mutex_destroy(&(m->msgw_fetch_lock));
620  Xorriso_sieve_dispose(m, 0);
621 
622  free((char *) m);
623  *xorriso= NULL;
624  return(1);
625 }
626 
627 
Xorriso_destroy_node_array(struct XorrisO * xorriso,int flag)628 int Xorriso_destroy_node_array(struct XorrisO *xorriso, int flag)
629 {
630  int i;
631 
632  if(xorriso->node_array != NULL) {
633    for(i= 0; i < xorriso->node_counter; i++)
634      iso_node_unref((IsoNode *) xorriso->node_array[i]);
635    free(xorriso->node_array);
636  }
637  xorriso->node_array= NULL;
638  xorriso->node_counter= xorriso->node_array_size= 0;
639  Xorriso_lst_destroy_all(&(xorriso->node_disk_prefixes), 0);
640  Xorriso_lst_destroy_all(&(xorriso->node_img_prefixes), 0);
641  return(1);
642 }
643 
644 
645 /* @param flag bit0= do not destroy hln_array but only hln_targets
646 */
Xorriso_destroy_hln_array(struct XorrisO * xorriso,int flag)647 int Xorriso_destroy_hln_array(struct XorrisO *xorriso, int flag)
648 {
649  int i;
650 
651 
652  if(xorriso->hln_array != NULL && !(flag & 1)) {
653    for(i= 0; i < xorriso->hln_count; i++)
654      iso_node_unref((IsoNode *) xorriso->hln_array[i]);
655    free(xorriso->hln_array);
656    xorriso->hln_array= NULL;
657    xorriso->hln_count= 0;
658  }
659  if(xorriso->hln_targets != NULL) {
660    for(i= 0; i < xorriso->hln_count; i++)
661      if(xorriso->hln_targets[i] != NULL)
662        free(xorriso->hln_targets[i]);
663    free(xorriso->hln_targets);
664    xorriso->hln_targets= NULL;
665  }
666  xorriso->node_targets_availmem= 0;
667  return(1);
668 }
669 
670 
Xorriso_destroy_di_array(struct XorrisO * xorriso,int flag)671 int Xorriso_destroy_di_array(struct XorrisO *xorriso, int flag)
672 {
673  int i;
674 
675  if(xorriso->di_array != NULL) {
676    for(i= 0; i < xorriso->di_count; i++)
677      if(xorriso->di_array[i] != NULL)
678        iso_node_unref((IsoNode *) xorriso->di_array[i]);
679    free(xorriso->di_array);
680    xorriso->di_array= NULL;
681  }
682  if(xorriso->di_do_widen != NULL) {
683    free(xorriso->di_do_widen);
684    xorriso->di_do_widen= NULL;
685  }
686  Xorriso_lst_destroy_all(&(xorriso->di_disk_paths), 0);
687  Xorriso_lst_destroy_all(&(xorriso->di_iso_paths), 0);
688  xorriso->di_count= 0;
689 
690 #ifdef NIX
691  /* <<< */
692  fprintf(stderr, "xorriso_DEBUG: get_di_count= %lu\n",
693          Xorriso_get_di_counteR);
694 #endif /* NIX */
695 
696  return(1);
697 }
698 
699 
Xorriso_new_node_array(struct XorrisO * xorriso,off_t mem_limit,int addon_nodes,int flag)700 int Xorriso_new_node_array(struct XorrisO *xorriso, off_t mem_limit,
701                            int addon_nodes, int flag)
702 {
703  int i;
704 
705  if(xorriso->node_counter <= 0)
706    return(1);
707 
708  xorriso->node_array= calloc(xorriso->node_counter + addon_nodes,
709                              sizeof(IsoNode *));
710  if(xorriso->node_array == NULL) {
711    Xorriso_no_malloc_memory(xorriso, NULL, 0);
712    return(-1);
713  }
714  for(i= 0; i < xorriso->node_counter + addon_nodes; i++)
715    xorriso->node_array[i]= NULL;
716  xorriso->node_array_size= xorriso->node_counter + addon_nodes;
717  xorriso->node_counter= 0;
718  return(1);
719 }
720 
721 
722 /* @param flag bit0= do not allocate hln_array but only hln_targets
723 */
Xorriso_new_hln_array(struct XorrisO * xorriso,off_t mem_limit,int flag)724 int Xorriso_new_hln_array(struct XorrisO *xorriso, off_t mem_limit, int flag)
725 {
726  int i;
727 
728  Xorriso_destroy_hln_array(xorriso, flag & 1);
729  if(xorriso->hln_count <= 0)
730    return(1);
731 
732  if(!(flag & 1)) {
733    xorriso->hln_array= calloc(xorriso->hln_count, sizeof(char *));
734    if(xorriso->hln_array == NULL) {
735      Xorriso_no_malloc_memory(xorriso, NULL, 0);
736      return(-1);
737    }
738    for(i= 0; i < xorriso->hln_count; i++)
739      xorriso->hln_array[i]= NULL;
740  }
741 
742  xorriso->hln_targets= calloc(xorriso->hln_count, sizeof(char *));
743  if(xorriso->hln_targets == NULL) {
744    if(!(flag & 1)) {
745      free(xorriso->hln_array);
746      xorriso->hln_array= NULL;
747    }
748    Xorriso_no_malloc_memory(xorriso, NULL, 0);
749    return(-1);
750  }
751  for(i= 0; i < xorriso->hln_count; i++)
752    xorriso->hln_targets[i]= NULL;
753  xorriso->node_targets_availmem= mem_limit
754                                  - xorriso->hln_count * sizeof(void *)
755                                  - xorriso->hln_count * sizeof(char *);
756  if(xorriso->node_targets_availmem < 0)
757    xorriso->node_targets_availmem= 0;
758  return(1);
759 }
760 
761 
Xorriso__preset_signal_behavior(int behavior,int flag)762 int Xorriso__preset_signal_behavior(int behavior, int flag)
763 {
764  if(behavior < 0 || behavior > 3)
765    return(0);
766  Xorriso_signal_behavioR= behavior;
767  return(1);
768 }
769 
770 
Xorriso__get_signal_behavior(int flag)771 int Xorriso__get_signal_behavior(int flag)
772 {
773  return(Xorriso_signal_behavioR);
774 }
775 
776