libisoburn  1.5.4
About: libisoburn is a frontend for the libraries libburn and libisofs which enables creation and expansion of ISO-9660 filesystems on all media and file types supported by libburn. It implements the API and command interpreter of program xorriso, and installs this program as small dynamically linked binary. xorriso is suitable for incremental data backup and for production of bootable ISO 9660 images. A statically linked version is available as GNU xorriso.
  Fossies Dox: libisoburn-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

isofs_wrap.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#include "libisoburn.h"
#include "isoburn.h"
Include dependency graph for isofs_wrap.c:

Go to the source code of this file.

Data Structures

struct  ecma119_pri_vol_desc
 

Macros

#define BP(a, b)   [(b) - (a) + 1]
 

Functions

static uint32_t iso_read_lsb (const uint8_t *buf, int bytes)
 
IsoImage * isoburn_get_attached_image (struct burn_drive *d)
 Get the image attached to a drive, if any. More...
 
int isoburn_get_attached_start_lba (struct burn_drive *d)
 Get the start address of the image that is attached to the drive, if any. More...
 
static void isoburn_idle_free_function (void *ignored)
 
int isoburn_root_defaults (IsoImage *image, int flag)
 Initialize the root directory attributes of a freshly created image. More...
 
int isoburn_read_image (struct burn_drive *d, struct isoburn_read_opts *read_opts, IsoImage **image)
 Load the ISO filesystem directory tree from the medium in the given drive. More...
 
int isoburn_attach_image (struct burn_drive *d, IsoImage *image)
 Set the IsoImage to be used with a drive. More...
 
int isoburn_attach_start_lba (struct burn_drive *d, int lba, int flag)
 Set the start address of the image that is attached to the drive, if any. More...
 
int isoburn_activate_session (struct burn_drive *drive)
 Call this after isoburn_disc_write has finished and burn_drive_wrote_well() indicates success. More...
 
int isoburn_get_img_partition_offset (struct burn_drive *drive, uint32_t *block_offset_2k)
 API. More...
 
static int isoburn_inspect_partition (struct isoburn *o, uint32_t img_size, int flag)
 
int isoburn_start_emulation (struct isoburn *o, int flag)
 Initialize the emulation of multi-session on random access media. More...
 
int isoburn_invalidate_iso (struct isoburn *o, int flag)
 Alters and writes the first 64 kB of a "medium" to invalidate an ISO image. More...
 
int isoburn_set_read_pacifier (struct burn_drive *drive, int(*read_pacifier)(IsoImage *, IsoFileSource *), void *read_handle)
 Set a callback function for producing pacifier messages during the lengthy process of image reading. More...
 

Macro Definition Documentation

◆ BP

#define BP (   a,
 
)    [(b) - (a) + 1]

Definition at line 38 of file isofs_wrap.c.

Function Documentation

◆ iso_read_lsb()

static uint32_t iso_read_lsb ( const uint8_t *  buf,
int  bytes 
)
static

Definition at line 78 of file isofs_wrap.c.

79 {
80  int i;
81  uint32_t ret = 0;
82 
83  for (i=0; i<bytes; i++) {
84  ret += ((uint32_t) buf[i]) << (i*8);
85  }
86  return ret;
87 }

Referenced by isoburn_inspect_partition(), and isoburn_start_emulation().

◆ isoburn_activate_session()

int isoburn_activate_session ( struct burn_drive *  d)

Call this after isoburn_disc_write has finished and burn_drive_wrote_well() indicates success.

It will eventually complete the emulation of multi-session functionality, if needed at all. Let libisoburn decide. Not a wrapper, but peculiar to libisoburn.

Since
0.1.0
Parameters
dThe output drive to which the session was written
Returns
1 success , <=0 failure

Definition at line 393 of file isofs_wrap.c.

394 {
395  int ret, do_sync = 1;
396  struct isoburn *o;
397 
398  ret = isoburn_find_emulator(&o, drive, 0);
399  if (ret < 0)
400  return -1;
401 
402  if (o->emulation_mode != 1)
403  return 1; /* don't need to activate session */
404  if (o->fabricated_msc2 >= 0)
405  return 1; /* blind growing: do not alter anything outside the session */
406 
407  if (!(o->fabricated_disc_status == BURN_DISC_APPENDABLE ||
408  (o->fabricated_disc_status == BURN_DISC_BLANK &&
409  o->zero_nwa > 0)))
410  return 1;
411  ret = burn_drive_get_drive_role(drive);
412  if (ret != 1)
413  do_sync = !! o->do_fsync;
414 
415  ret = burn_random_access_write(drive, (off_t) 0, (char*)o->target_iso_head,
416  o->target_iso_head_size, do_sync);
417 
418  return ret;
419 }
int isoburn_find_emulator(struct isoburn **pt, struct burn_drive *drive, int flag)
Retrieve medium emulation and eventual isoburn emulator of drive.
Definition: burn_wrap.c:627
uint8_t * target_iso_head
Definition: isoburn.h:134
int do_fsync
Definition: isoburn.h:172
struct burn_drive * drive
Definition: isoburn.h:70
int emulation_mode
Definition: isoburn.h:75
int fabricated_msc2
Definition: isoburn.h:92
enum burn_disc_status fabricated_disc_status
Definition: isoburn.h:114
int zero_nwa
Definition: isoburn.h:98
int target_iso_head_size
Definition: isoburn.h:133

References isoburn::do_fsync, isoburn::drive, isoburn::emulation_mode, isoburn::fabricated_disc_status, isoburn::fabricated_msc2, isoburn_find_emulator(), isoburn::target_iso_head, isoburn::target_iso_head_size, and isoburn::zero_nwa.

Referenced by isoburn_invalidate_iso(), and Xorriso_write_session().

◆ isoburn_attach_image()

int isoburn_attach_image ( struct burn_drive *  d,
IsoImage *  image 
)

Set the IsoImage to be used with a drive.

This eventually releases the reference to the old IsoImage attached to the drive. Caution: Use with care. It hardly makes sense to replace an image that reflects a valid ISO image on the medium. This call is rather intended for writing a newly created and populated image to blank media. The use case in xorriso is to let an image survive the change or demise of the outdev target drive.

Since
0.1.0
Parameters
dThe drive which shall be write target of the volset.
imageThe image that represents the image to be written. This image pointer MUST already be a valid reference suitable for iso_image_unref(). It may have been obtained by appropriate libisofs calls or by isoburn_read_image() with d==NULL.
Returns
<=0 error , 1 = success

Definition at line 351 of file isofs_wrap.c.

352 {
353  int ret;
354  struct isoburn *o;
355 
356  ret = isoburn_find_emulator(&o, d, 0);
357  if (ret < 0 || o == NULL)
358  return 0;
359  if (image == NULL) {
360  isoburn_msgs_submit(o, 0x00060000,
361  "Program error: isoburn_attach_image: image==NULL",
362  0, "FATAL", 0);
363  return -1;
364  }
365  if(o->image != NULL)
366  iso_image_unref(o->image);
367  o->image = image;
368  o->image_start_lba = -1;
369  return(1);
370 }
int isoburn_msgs_submit(struct isoburn *o, int error_code, char msg_text[], int os_errno, char severity[], int flag)
Definition: isoburn.c:340
int image_start_lba
Definition: isoburn.h:145
IsoImage * image
Definition: isoburn.h:142

References isoburn::image, isoburn::image_start_lba, isoburn_find_emulator(), and isoburn_msgs_submit().

Referenced by Xorriso_aquire_drive().

◆ isoburn_attach_start_lba()

int isoburn_attach_start_lba ( struct burn_drive *  d,
int  lba,
int  flag 
)

Set the start address of the image that is attached to the drive, if any.

Since
1.2.2
Parameters
dThe drive to inquire
lbaThe logical block address where the System Area of the image starts. <0 means that the address is invalid.
flagBitfield, submit 0 for now.
Returns
<=0 error (e.g. because no image is attached), 1 = success

Definition at line 374 of file isofs_wrap.c.

375 {
376  int ret;
377  struct isoburn *o;
378 
379  ret = isoburn_find_emulator(&o, d, 0);
380  if(ret < 0)
381  return ret;
382  if(o == NULL)
383  return 0;
384  if(o->image == NULL)
385  return 0;
386  o->image_start_lba = lba;
387  return 1;
388 }

References isoburn::image, isoburn::image_start_lba, and isoburn_find_emulator().

Referenced by Xorriso_aquire_drive().

◆ isoburn_get_attached_image()

IsoImage* isoburn_get_attached_image ( struct burn_drive *  d)

Get the image attached to a drive, if any.

Since
0.1.0
Parameters
dThe drive to inquire
Returns
A reference to attached image, or NULL if the drive has no image attached. This reference needs to be released via iso_image_unref() when it is not longer needed.

Definition at line 92 of file isofs_wrap.c.

93 {
94  int ret;
95  struct isoburn *o= NULL;
96  ret = isoburn_find_emulator(&o, d, 0);
97  if (ret < 0)
98  return NULL;
99 
100  if (o == NULL) {
101  return NULL;
102  }
103  iso_image_ref(o->image);
104  return o->image;
105 }

References isoburn::image, and isoburn_find_emulator().

Referenced by Xorriso_aquire_drive(), Xorriso_attach_boot_image(), Xorriso_boot_image_status(), Xorriso_pacifier_loop(), Xorriso_record_boot_info(), Xorriso_set_system_area_path(), Xorriso_show_boot_info(), and Xorriso_write_session().

◆ isoburn_get_attached_start_lba()

int isoburn_get_attached_start_lba ( struct burn_drive *  d)

Get the start address of the image that is attached to the drive, if any.

Since
1.2.2
Parameters
dThe drive to inquire
Returns
The logical block address where the System Area of the image starts. <0 means that the address is invalid.

Definition at line 109 of file isofs_wrap.c.

110 {
111  int ret;
112  struct isoburn *o= NULL;
113 
114  ret = isoburn_find_emulator(&o, d, 0);
115  if (ret < 0 || o == NULL)
116  return -1;
117  if(o->image == NULL)
118  return -1;
119  return o->image_start_lba;
120 }

References isoburn::image, isoburn::image_start_lba, and isoburn_find_emulator().

Referenced by Xorriso_aquire_drive(), and Xorriso_check_media().

◆ isoburn_get_img_partition_offset()

int isoburn_get_img_partition_offset ( struct burn_drive *  drive,
uint32_t *  block_offset_2k 
)

API.

Inquire the partition offset of the loaded image.

Since
0.6.2

Definition at line 424 of file isofs_wrap.c.

426 {
427  int ret;
428  struct isoburn *o;
429 
430  ret = isoburn_find_emulator(&o, drive, 0);
431  if(ret < 0 || o == NULL)
432  return -1;
433  *block_offset_2k= o->loaded_partition_offset;
434  if(o->loaded_partition_offset == 0)
435  return(0);
437  + (off_t) 2048 * (off_t) o->loaded_partition_offset)
438  return(1);
439  return(2);
440 }
#define Libisoburn_target_head_sizE
Definition: isoburn.h:51
uint32_t loaded_partition_offset
Definition: isoburn.h:138

References isoburn::drive, isoburn_find_emulator(), Libisoburn_target_head_sizE, isoburn::loaded_partition_offset, and isoburn::target_iso_head_size.

Referenced by Xorriso_aquire_drive(), and Xorriso_set_system_area().

◆ isoburn_idle_free_function()

static void isoburn_idle_free_function ( void *  ignored)
static

Definition at line 123 of file isofs_wrap.c.

124 {
125  return;
126 }

Referenced by isoburn_read_image().

◆ isoburn_inspect_partition()

static int isoburn_inspect_partition ( struct isoburn o,
uint32_t  img_size,
int  flag 
)
static

Definition at line 447 of file isofs_wrap.c.

449 {
450  uint8_t *mbr, *part, *buf= NULL;
451  uint32_t offst, numsec;
452  struct ecma119_pri_vol_desc *pvm;
453  off_t data_count;
454  int ret;
455  char *msg= NULL;
456  static int max_offst= 512 - 32;
457 
458  buf= (uint8_t *) calloc(1, 2048);
459  msg= calloc(1, 160);
460  if(buf == NULL || msg == NULL)
461  {ret= -1; goto ex;}
462 
463  mbr= o->target_iso_head;
464  part= mbr + 446;
465  if(mbr[510] != 0x55 || mbr[511] != 0xAA)
466  {ret= 2; goto ex;} /* not an MBR */
467 
468  /* Does the first partition entry look credible ? */
469  if(part[0] != 0x80 && part[0] != 0x00)
470  {ret= 2; goto ex;} /* Invalid partition status */
471  if(part[1] == 0 && part[2] == 0 && part[3] == 0)
472  {ret= 2; goto ex;} /* Zero C/H/S start address */
473 
474  /* Does it match the normal ISO image ? */
475  offst= iso_read_lsb(part + 8, 4);
476  numsec= iso_read_lsb(part + 12, 4);
477  if(offst < 64)
478  {ret= 2; goto ex;} /* Zero or unusably small partition start */
479  if((offst % 4) || (numsec % 4))
480  {ret= 2; goto ex;} /* Not aligned to 2k */
481  if(numsec < 72)
482  {ret= 2; goto ex;} /* No room for volume descriptors */
483  offst/= 4;
484  numsec/= 4;
485  if(offst + numsec > img_size)
486  {ret= 2; goto ex;} /* Partition end exceeds image end */
487 
488  /* Is there a PVD at the partition start ? */
489  ret = burn_read_data(o->drive, (off_t) (offst + 16) * (off_t) 2048,
490  (char*) buf, 2048, &data_count, 32);
491  if(ret <= 0)
492  {ret= 2; goto ex;}
493  pvm = (struct ecma119_pri_vol_desc *) buf;
494  if (strncmp((char*) pvm->std_identifier, "CD001", 5) != 0)
495  {ret= 2; goto ex;} /* not a PVD */
496  if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
497  || pvm->file_structure_version[0] != 1 )
498  {ret= 2; goto ex;} /* failed sanity check */
499 
500  if(iso_read_lsb(pvm->vol_space_size, 4) + offst > img_size)
501  {ret= 2; goto ex;} /* Image ends do not match plausibly */
502 
503  /* Now it is credible. Not yet clear is whether it is acceptable. */
504  o->loaded_partition_offset= offst;
505 
506  /* If the partition start is too large: Report but do not accept. */
507  if(offst > (uint32_t) max_offst) {/* Not more than 1 MB of .target_iso_head */
508  sprintf(msg,
509  "Detected partition offset of %.f blocks. Maximum for load buffer is %d",
510  (double) offst, max_offst);
511  isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "WARNING", 0);
512  {ret= 3; goto ex;}
513  }
514 
515  /* Accept partition start and adjust buffer size */
516  ret= isoburn_adjust_target_iso_head(o, offst, 0);
517  if(ret <= 0)
518  goto ex;
519 
520  ret= 1;
521 ex:;
522  if(buf != NULL)
523  free(buf);
524  if(msg != NULL)
525  free(msg);
526  return(ret);
527 }
int isoburn_adjust_target_iso_head(struct isoburn *o, uint32_t offst, int flag)
Check whether the size of target_iso_head matches the given partition offset.
Definition: isoburn.c:368
static uint32_t iso_read_lsb(const uint8_t *buf, int bytes)
Definition: isofs_wrap.c:78
uint8_t file_structure_version[(882) -(882)+1]
Definition: isofs_wrap.c:71
uint8_t vol_desc_type[(1) -(1)+1]
Definition: isofs_wrap.c:42
uint8_t std_identifier[(6) -(2)+1]
Definition: isofs_wrap.c:43
uint8_t vol_desc_version[(7) -(7)+1]
Definition: isofs_wrap.c:44
uint8_t vol_space_size[(88) -(81)+1]
Definition: isofs_wrap.c:49

References isoburn::drive, ecma119_pri_vol_desc::file_structure_version, iso_read_lsb(), isoburn_adjust_target_iso_head(), isoburn_msgs_submit(), isoburn::loaded_partition_offset, ecma119_pri_vol_desc::std_identifier, isoburn::target_iso_head, ecma119_pri_vol_desc::vol_desc_type, ecma119_pri_vol_desc::vol_desc_version, and ecma119_pri_vol_desc::vol_space_size.

Referenced by isoburn_start_emulation().

◆ isoburn_invalidate_iso()

int isoburn_invalidate_iso ( struct isoburn o,
int  flag 
)

Alters and writes the first 64 kB of a "medium" to invalidate an ISO image.

(It shall stay restorable by skilled humans, though). The result shall especially keep libisoburn from accepting the medium image as ISO filesystem.

Parameters
oA fully activated isoburn object. isoburn_start_emulation() was already called.
Returns
<=0 error , 1 = success

Definition at line 673 of file isofs_wrap.c.

674 {
675  int end_ed_found= 0, i;
676  char *head;
677 
678  head= (char *) o->target_iso_head;
679  /*
680  * replace CD001 with CDXX1 in PVM.
681  */
682  memcpy(head + 16 * 2048 + 1, "CDXX1", 5);
683 
684  /* Invalidate further ECMA-119 volume descriptors and possible UDF volume
685  recognition sequence */
686  for(i= 17 * 2048; i < 32 * 2048; i+= 2048) {
687  if(end_ed_found) {
688  if(head[i] == 0 && strncmp(head + i + 1, "BEA01", 5) == 0)
689  memcpy(head + i + 1, "BEAX1", 5);
690  else if(head[i] == 0 && strncmp(head + i + 1, "NSR", 3) == 0)
691  memcpy(head + i + 1, "NSRX", 4);
692  else if(head[i] == 0 && strncmp(head + i + 1, "TEA", 3) == 0)
693  memcpy(head + i + 1, "TEAX", 4);
694  } else if(strncmp(head + i + 1, "CD001", 5) == 0) {
695  if(((unsigned char *) head)[i] == 0xff)
696  end_ed_found= 1;
697  memcpy(head + i + 3, "XX", 2);
698  }
699  }
700 
701  return isoburn_activate_session(o->drive);
702 }
int isoburn_activate_session(struct burn_drive *drive)
Call this after isoburn_disc_write has finished and burn_drive_wrote_well() indicates success.
Definition: isofs_wrap.c:393

References isoburn::drive, isoburn_activate_session(), and isoburn::target_iso_head.

Referenced by isoburn_disc_erase().

◆ isoburn_read_image()

int isoburn_read_image ( struct burn_drive *  d,
struct isoburn_read_opts read_opts,
IsoImage **  image 
)

Load the ISO filesystem directory tree from the medium in the given drive.

This will give libisoburn the base on which it can let libisofs perform image growing or image modification. The loaded volset gets attached to the drive object and handed out to the application. Not a wrapper, but peculiar to libisoburn.

Since
0.1.0
Parameters
dThe drive which holds an existing ISO filesystem or blank media. d is allowed to be NULL which produces an empty ISO image. In this case one has to call before writing isoburn_attach_volset() with the volset from this call and with the intended output drive.
read_optsThe read options which can be chosen by the application
imagethe image read, if the disc is blank it will have no files. This reference needs to be released via iso_image_unref() when it is not longer needed. The drive, if not NULL, will hold an own reference which it will release when it gets a new volset or when it gets released via isoburn_drive_release(). You can pass NULL if you already have a reference or you plan to obtain it later with isoburn_get_attached_image(). Of course, if you haven't specified a valid drive (i.e., if d == NULL), this parameter can't be NULL.
Returns
<=0 error , 1 = success

Definition at line 142 of file isofs_wrap.c.

145 {
146  int ret, int_num, dummy, ignore_aclea= 0;
147  IsoReadOpts *ropts= NULL;
148  IsoReadImageFeatures *features= NULL;
149  uint32_t ms_block;
150  char *msg= NULL;
151  enum burn_disc_status status= BURN_DISC_BLANK;
152  IsoDataSource *ds= NULL;
153  struct isoburn *o= NULL;
154  IsoImage *new_image= NULL;
155 
156  msg= calloc(1, 160);
157 
158  if(d != NULL) {
159  ret = isoburn_find_emulator(&o, d, 0);
160  if (ret < 0 || o == NULL)
161  {ret= 0; goto ex;}
162  status = isoburn_disc_get_status(d);
163  o->image_start_lba= -1;
164  }
165  if(read_opts==NULL) {
166  isoburn_msgs_submit(o, 0x00060000,
167  "Program error: isoburn_read_image: read_opts==NULL",
168  0, "FATAL", 0);
169  {ret= -1; goto ex;}
170  }
171  if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) {
172 create_blank_image:;
173  /*
174  * Blank disc, we create a new image without files.
175  */
176 
177  if (d == NULL) {
178  /* New empty image without relation to a drive */
179  if (image==NULL) {
180  isoburn_msgs_submit(o, 0x00060000,
181  "Program error: isoburn_read_image: image==NULL",
182  0, "FATAL", 0);
183  {ret= -1; goto ex;}
184  }
185  /* create a new image */
186  ret = iso_image_new("ISOIMAGE", image);
187  if (ret < 0) {
188  isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
189  goto ex;
190  }
191  new_image= *image;
192  } else {
193  /* Blank new image for the drive */
194  if(o->image != NULL)
195  ignore_aclea= iso_image_get_ignore_aclea(o->image);
196  iso_image_unref(o->image);
197  ret = iso_image_new("ISOIMAGE", &o->image);
198  if (ret < 0) {
199  isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
200  goto ex;
201  }
202  if (image != NULL) {
203  *image = o->image;
204  iso_image_ref(*image); /*protects object from premature free*/
205  }
206  iso_image_set_ignore_aclea(o->image, ignore_aclea);
207  ret= isoburn_root_defaults(o->image, 0);
208  if(ret <= 0)
209  goto ex;
210  new_image= o->image;
211  }
212  ret= iso_image_set_truncate_mode(new_image, read_opts->truncate_mode,
213  read_opts->truncate_length);
214  if(ret < 0)
215  goto ex;
216  {ret= 1; goto ex;}
217  }
218 
219  if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) {
220  isoburn_msgs_submit(o, 0x00060000,
221  "Program error: isoburn_read_image: incorrect disc status",
222  0, "FATAL", 0);
223  {ret= -4; goto ex;}
224  }
225 
226  ret = isoburn_disc_get_msc1(d, &int_num);
227  if (ret <= 0)
228  {ret= -2; goto ex;}
229  ms_block= int_num;
230  if (o != NULL)
231  o->image_start_lba= ms_block;
232  ret = isoburn_read_iso_head(d, int_num, &dummy, NULL, 0);
233  if (ret <= 0) {
234  sprintf(msg, "No ISO 9660 image at LBA %d. Creating blank image.", int_num);
235  isoburn_msgs_submit(o, 0x00060000, msg, 0, "WARNING", 0);
236  goto create_blank_image;
237  }
238 
239  if(read_opts->displacement != 0 && abs(read_opts->displacement_sign) == 1) {
240  /* Apply reverse displacement to session start */
241  if(read_opts->displacement_sign == -1) {
242  if(ms_block+ read_opts->displacement < ms_block) {
243 displacement_rollover:;
244  sprintf(msg, "Displacement offset leads outside 32 bit range.");
245  isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
246  {ret= 0; goto ex;}
247  }
248  ms_block+= read_opts->displacement;
249  } else {
250  if(ms_block < read_opts->displacement)
251  goto displacement_rollover;
252  ms_block-= read_opts->displacement;
253  }
254  }
255 
256 
257  /* create the data source */
258  ret = iso_read_opts_new(&ropts, 0);
259  if (ret < 0) {
260  isoburn_report_iso_error(ret, "Cannot create write opts", 0, "FATAL", 0);
261  goto ex;
262  }
263 
264  /* Important: do not return until iso_read_opts_free() */
265 
266  iso_read_opts_set_start_block(ropts, ms_block);
267  iso_read_opts_set_no_rockridge(ropts, read_opts->norock);
268  iso_read_opts_set_no_aaip(ropts, read_opts->noaaip);
269  if(read_opts->nomd5 == 2)
270  int_num= 2;
271  else if(read_opts->nomd5 == 1)
272  int_num= 1;
273  else
274  int_num= 0;
275  iso_read_opts_set_no_md5(ropts, int_num);
276  if(read_opts->do_ecma119_map)
277  iso_read_opts_set_ecma119_map(ropts, read_opts->map_mode);
278  if(read_opts->do_joliet_map)
279  iso_read_opts_set_joliet_map(ropts, read_opts->joliet_map_mode);
280  iso_read_opts_set_new_inos(ropts, read_opts->noino);
281 
282  iso_read_opts_set_no_joliet(ropts, read_opts->nojoliet);
283  iso_read_opts_set_no_iso1999(ropts, read_opts->noiso1999);
284  iso_read_opts_set_preferjoliet(ropts, read_opts->preferjoliet);
285  iso_read_opts_set_default_permissions(ropts,
286  read_opts->mode, read_opts->dirmode);
287  iso_read_opts_set_default_uid(ropts, read_opts->uid);
288  iso_read_opts_set_default_gid(ropts, read_opts->gid);
289  iso_read_opts_set_input_charset(ropts, read_opts->input_charset);
290  iso_read_opts_auto_input_charset(ropts, read_opts->auto_input_charset);
291  iso_read_opts_load_system_area(ropts, 1);
292  iso_read_opts_keep_import_src(ropts, 1);
293  ret= iso_image_set_truncate_mode(o->image, read_opts->truncate_mode,
294  read_opts->truncate_length);
295  if(ret < 0)
296  goto ex;
297 
298  ds = isoburn_data_source_new(d, read_opts->displacement,
299  read_opts->displacement_sign,
300  read_opts->cache_tiles, read_opts->cache_tile_blocks);
301  if (ds == NULL) {
302  isoburn_report_iso_error(ret, "Cannot create IsoDataSource object", 0,
303  "FATAL", 0);
304  ret= -1; goto ex;
305  }
306  if(o->iso_data_source!=NULL)
307  iso_data_source_unref(o->iso_data_source);
308  o->iso_data_source= ds;
309  iso_image_attach_data(o->image, o->read_pacifier_handle,
311  if(o->read_pacifier_handle==NULL)
312  iso_tree_set_report_callback(o->image, NULL);
313  else
314  iso_tree_set_report_callback(o->image, o->read_pacifier);
315 
316  ret = iso_image_import(o->image, ds, ropts, &features);
317  iso_tree_set_report_callback(o->image, NULL);
318  iso_read_opts_free(ropts);
319  ropts= NULL;
320 
321  if (ret < 0) {
322  isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0);
323  goto ex;
324  }
325  /* Important: do not return until free(features) */
326  if (image!=NULL) {
327  *image = o->image;
328  iso_image_ref(*image); /*protects object from premature free*/
329  }
330  read_opts->hasRR = iso_read_image_features_has_rockridge(features);
331  read_opts->hasJoliet = iso_read_image_features_has_joliet(features);
332  read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features);
333  read_opts->hasElTorito = iso_read_image_features_has_eltorito(features);
334  read_opts->size = iso_read_image_features_get_size(features);
335  read_opts->tree_loaded = iso_read_image_features_tree_loaded(features);
336  read_opts->rr_loaded = iso_read_image_features_rr_loaded(features);
337  ret= 1;
338 ex:;
339  if(msg != NULL)
340  free(msg);
341  if(ropts != NULL)
342  iso_read_opts_free(ropts);
343  if(features != NULL)
344  iso_read_image_features_destroy(features);
345  return(ret);
346 }
enum burn_disc_status isoburn_disc_get_status(struct burn_drive *drive)
Inquire the medium status.
Definition: burn_wrap.c:646
int isoburn_read_iso_head(struct burn_drive *d, int lba, int *image_blocks, char *info, int flag)
Try whether the data at the given address look like a ISO 9660 image header and obtain its alleged si...
Definition: burn_wrap.c:1301
int isoburn_report_iso_error(int iso_error_code, char msg_text[], int os_errno, char min_severity[], int flag)
Definition: burn_wrap.c:1221
int isoburn_disc_get_msc1(struct burn_drive *d, int *start_lba)
Obtain the start block number of the most recent session on the medium.
Definition: burn_wrap.c:799
IsoDataSource * isoburn_data_source_new(struct burn_drive *d, uint32_t displacement, int displacement_sign, int cache_tiles, int tile_blocks)
Get a data source suitable for read from a drive using burn_read_data() function.
Definition: data_source.c:325
int isoburn_root_defaults(IsoImage *image, int flag)
Initialize the root directory attributes of a freshly created image.
Definition: isofs_wrap.c:129
static void isoburn_idle_free_function(void *ignored)
Definition: isofs_wrap.c:123
int cache_tile_blocks
Definition: isoburn.h:320
unsigned int hasIso1999
It will be set to 1 if the image is an ISO 9660:1999, i.e.
Definition: isoburn.h:384
uid_t uid
Default uid when no RR.
Definition: isoburn.h:346
unsigned int hasRR
Definition: isoburn.h:375
mode_t dirmode
Default mode for directories when no RR (only permissions)
Definition: isoburn.h:349
unsigned int noaaip
Definition: isoburn.h:333
int truncate_mode
What to do in case of name longer than truncate_length: 0= throw FAILURE 1= truncate to truncate_leng...
Definition: isoburn.h:371
unsigned int hasJoliet
Definition: isoburn.h:377
uint32_t size
Will be filled with the size (in 2048 byte block) of the image, as reported in the PVM.
Definition: isoburn.h:389
mode_t mode
Default mode when no RR (only permissions)
Definition: isoburn.h:348
unsigned int noino
Definition: isoburn.h:338
unsigned int nojoliet
Definition: isoburn.h:323
unsigned int norock
Definition: isoburn.h:322
uint32_t displacement
Definition: isoburn.h:398
unsigned int do_ecma119_map
Definition: isoburn.h:326
unsigned int map_mode
Definition: isoburn.h:327
unsigned int nomd5
Definition: isoburn.h:341
char * input_charset
Input charset for RR file names.
Definition: isoburn.h:355
unsigned int noiso1999
Definition: isoburn.h:324
unsigned int preferjoliet
Definition: isoburn.h:343
int displacement_sign
Definition: isoburn.h:399
unsigned int hasElTorito
It will be set to 1 if El-Torito boot record is present, to 0 if not.
Definition: isoburn.h:387
unsigned int do_joliet_map
Definition: isoburn.h:329
int auto_input_charset
Enable or disable methods to automatically choose an input charset.
Definition: isoburn.h:364
unsigned int joliet_map_mode
Definition: isoburn.h:330
unsigned int pretend_blank
Definition: isoburn.h:396
gid_t gid
Default uid when no RR.
Definition: isoburn.h:347
void * read_pacifier_handle
Definition: isoburn.h:160
IsoDataSource * iso_data_source
Definition: isoburn.h:149
int(* read_pacifier)(IsoImage *, IsoFileSource *)
Definition: isoburn.h:157

References isoburn_read_opts::auto_input_charset, isoburn_read_opts::cache_tile_blocks, isoburn_read_opts::cache_tiles, isoburn_read_opts::dirmode, isoburn_read_opts::displacement, isoburn_read_opts::displacement_sign, isoburn_read_opts::do_ecma119_map, isoburn_read_opts::do_joliet_map, isoburn_read_opts::gid, isoburn_read_opts::hasElTorito, isoburn_read_opts::hasIso1999, isoburn_read_opts::hasJoliet, isoburn_read_opts::hasRR, isoburn::image, isoburn::image_start_lba, isoburn_read_opts::input_charset, isoburn::iso_data_source, isoburn_data_source_new(), isoburn_disc_get_msc1(), isoburn_disc_get_status(), isoburn_find_emulator(), isoburn_idle_free_function(), isoburn_msgs_submit(), isoburn_read_iso_head(), isoburn_report_iso_error(), isoburn_root_defaults(), isoburn_read_opts::joliet_map_mode, isoburn_read_opts::map_mode, isoburn_read_opts::mode, isoburn_read_opts::noaaip, isoburn_read_opts::noino, isoburn_read_opts::noiso1999, isoburn_read_opts::nojoliet, isoburn_read_opts::nomd5, isoburn_read_opts::norock, isoburn_read_opts::preferjoliet, isoburn_read_opts::pretend_blank, isoburn::read_pacifier, isoburn::read_pacifier_handle, isoburn_read_opts::rr_loaded, isoburn_read_opts::size, isoburn_read_opts::tree_loaded, isoburn_read_opts::truncate_length, isoburn_read_opts::truncate_mode, and isoburn_read_opts::uid.

Referenced by Xorriso_aquire_drive(), and Xorriso_create_empty_iso().

◆ isoburn_root_defaults()

int isoburn_root_defaults ( IsoImage *  image,
int  flag 
)

Initialize the root directory attributes of a freshly created image.

Definition at line 129 of file isofs_wrap.c.

130 {
131  IsoNode *root_node;
132  mode_t root_mode= 0755;
133 
134  root_node= (IsoNode *) iso_image_get_root(image);
135  iso_node_set_permissions(root_node, root_mode);
136  return(1);
137 }

References isoburn::image.

Referenced by isoburn_new(), and isoburn_read_image().

◆ isoburn_set_read_pacifier()

int isoburn_set_read_pacifier ( struct burn_drive *  drive,
int(*)(IsoImage *, IsoFileSource *)  read_pacifier,
void *  app_handle 
)

Set a callback function for producing pacifier messages during the lengthy process of image reading.

The callback function and the application handle are stored until they are needed for the underlying call to libisofs. Other than with libisofs the handle is managed entirely by the application. An idle .free() function is exposed to libisofs. The handle has to stay valid until isoburn_read_image() is done. It has to be detached by isoburn_set_read_pacifier(drive, NULL, NULL); before it may be removed from memory.

Since
0.1.0
Parameters
driveThe drive which will be used with isoburn_read_image() It has to be acquired by an isoburn_* wrapper call.
read_pacifierThe callback function
app_handleThe app handle which the callback function can obtain via iso_image_get_attached_data() from its IsoImage*
Returns
1 success, <=0 failure

Definition at line 706 of file isofs_wrap.c.

709 {
710  int ret;
711  struct isoburn *o;
712 
713  ret = isoburn_find_emulator(&o, drive, 0);
714  if(ret < 0 || o == NULL)
715  return -1;
716  o->read_pacifier_handle= read_handle;
718  return(1);
719 }

References isoburn::drive, isoburn_find_emulator(), isoburn::read_pacifier, and isoburn::read_pacifier_handle.

Referenced by Xorriso_aquire_drive(), and Xorriso_create_empty_iso().

◆ isoburn_start_emulation()

int isoburn_start_emulation ( struct isoburn o,
int  flag 
)

Initialize the emulation of multi-session on random access media.

The need for emulation is confirmed already.

Parameters
oA freshly created isoburn object. isoburn_create_data_source() was already called, nevertheless.
flagbit0= read-only
Returns
<=0 error , 1 = success

Definition at line 537 of file isofs_wrap.c.

538 {
539  int ret, i, capacity = -1, role, dummy;
540  off_t data_count, to_read;
541  struct burn_drive *drive;
542  struct ecma119_pri_vol_desc *pvm;
543  enum burn_disc_status s;
544  char *path= NULL, *msg= NULL;
545 
546  path= calloc(1, BURN_DRIVE_ADR_LEN);
547  msg= calloc(1, 2 * BURN_DRIVE_ADR_LEN);
548  if(path == NULL || msg == NULL)
549  {ret= -1; goto ex;}
550 
551  if(o==NULL) {
552  isoburn_msgs_submit(NULL, 0x00060000,
553  "Program error: isoburn_start_emulation: o==NULL",
554  0, "FATAL", 0);
555  {ret= -1; goto ex;}
556  }
557 
558  drive= o->drive;
559 
560  if(flag & 1)
561  o->fabricated_disc_status= BURN_DISC_FULL;
562 
563  /* We can assume 0 as start block for image.
564  The data there point to the most recent session.
565  */
566  role = burn_drive_get_drive_role(drive);
567  ret = burn_get_read_capacity(drive, &capacity, 0);
568  if (ret <= 0)
569  capacity = -1;
570  if (role == 5) { /* random access write-only medium */
571  s = burn_disc_get_status(drive);
573  burn_disc_track_lba_nwa(drive, NULL, 0, &dummy, &(o->nwa));
574  if(o->nwa < o->zero_nwa)
575  o->zero_nwa= 0;
576  {ret= 1; goto ex;}
577  } else if (capacity > 0 || role == 2 || role == 4) {
578  /* Might be a block device on a system where libburn cannot determine its
579  size. Try to read anyway. */
580  to_read = o->target_iso_head_size;
581  memset(o->target_iso_head, 0, to_read);
582  if(capacity > 0 && (off_t) capacity * (off_t) 2048 < to_read)
583  to_read = (off_t) capacity * (off_t) 2048;
584  ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head,
585  to_read, &data_count, 32 | 8);
586  if (ret <= 0) {
587  /* an error means a disc with no ISO image */
588  o->media_read_error= 1;
589  if (ret == -2) {
590  path[0]= 0;
591  burn_drive_d_get_adr(drive, path);
592  sprintf(msg, "Pseudo drive '%s' does not allow reading", path);
593  isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "NOTE", 0);
594  o->fabricated_disc_status= BURN_DISC_BLANK;
595  } else if (capacity > 0)
596  o->fabricated_disc_status= BURN_DISC_FULL;
597  else if(!(flag & 1))
598  o->fabricated_disc_status= BURN_DISC_BLANK;
599  {ret= 1; goto ex;}
600  }
601  } else {
602  /* No read capacity means blank medium */
603  if(!(flag & 1))
604  o->fabricated_disc_status= BURN_DISC_BLANK;
605  {ret= 1; goto ex;}
606  }
607 
608  /* check first 64K. If 0's, the disc is treated as a blank disc, and thus
609  overwritten without extra check. */
611  while (i && !o->target_iso_head[i-1])
612  --i;
613 
614  if (!i) {
615  if(!(flag & 1))
616  o->fabricated_disc_status= BURN_DISC_BLANK;
617  {ret= 1; goto ex;}
618  }
619 
620  pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
621 
622  if (strncmp((char*)pvm->std_identifier, "CD001", 5) == 0) {
623  off_t size;
624 
625  /* sanity check */
626  if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
627  || pvm->file_structure_version[0] != 1 ) {
628  /* TODO for now I treat this as a full disc */
629  o->fabricated_disc_status= BURN_DISC_FULL;
630  {ret= 1; goto ex;}
631  }
632 
633  /* ok, PVM found, set size */
634  size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
635  ret= isoburn_inspect_partition(o, (uint32_t) size, 0);
636  if (ret <= 0)
637  goto ex;
638  size *= (off_t) 2048; /* block size in bytes */
639  isoburn_set_start_byte(o, size, 0);
640  if(!(flag & 1))
641  o->fabricated_disc_status= BURN_DISC_APPENDABLE;
642  } else if (strncmp((char*)pvm->std_identifier, "CDXX1", 5) == 0 ||
643  (strncmp((char*)pvm->std_identifier, "CDxx1", 5) == 0 &&
644  pvm->vol_desc_type[0] == 'x')) {
645 
646  /* empty image */
647  isoburn_set_start_byte(o, o->zero_nwa * 2048, 0);
648  if(!(flag & 1))
649  o->fabricated_disc_status= BURN_DISC_BLANK;
650  } else {
651  /* treat any disc in an unknown format as full */
652  o->fabricated_disc_status= BURN_DISC_FULL;
653  }
654 
655  ret= 1;
656 ex:;
657  if(path != NULL)
658  free(path);
659  if(msg != NULL)
660  free(msg);
661  return(ret);
662 }
int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag)
Set the start address for an emulated add-on session.
Definition: burn_wrap.c:1081
static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size, int flag)
Definition: isofs_wrap.c:447
int nwa
Definition: isoburn.h:104
int media_read_error
Definition: isoburn.h:118

References isoburn::drive, isoburn::fabricated_disc_status, ecma119_pri_vol_desc::file_structure_version, iso_read_lsb(), isoburn_inspect_partition(), isoburn_msgs_submit(), isoburn_set_start_byte(), Libisoburn_target_head_sizE, isoburn::media_read_error, isoburn::nwa, ecma119_pri_vol_desc::std_identifier, isoburn::target_iso_head, isoburn::target_iso_head_size, ecma119_pri_vol_desc::vol_desc_type, ecma119_pri_vol_desc::vol_desc_version, ecma119_pri_vol_desc::vol_space_size, and isoburn::zero_nwa.

Referenced by isoburn_welcome_media().