#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#include "isoburn.h"
#include "libisoburn.h"

Go to the source code of this file.
Data Structures | |
| struct | ecma119_pri_vol_desc |
Defines | |
| #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. | |
| static void | isoburn_idle_free_function (void *ignored) |
| int | isoburn_read_image (struct burn_drive *d, struct isoburn_read_opts *read_opts, IsoImage **image) |
| Load the ISO filesystem directory tree from the media in the given drive. | |
| int | isoburn_attach_image (struct burn_drive *d, IsoImage *image) |
| Set the IsoImage to be used with a drive. | |
| int | isoburn_activate_session (struct burn_drive *drive) |
| Call this after isoburn_disc_write has finished and burn_drive_wrote_well() indicates success. | |
| int | isoburn_start_emulation (struct isoburn *o, int flag) |
| Initialize the emulation of multi-session on random access media. | |
| int | isoburn_invalidate_iso (struct isoburn *o, int flag) |
| Alters and writes the first 64 kB of a "media" to invalidate an ISO image. | |
| 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. | |
| #define BP | ( | a, | |||
| b | ) | [(b) - (a) + 1] |
Definition at line 33 of file isofs_wrap.c.
| static uint32_t iso_read_lsb | ( | const uint8_t * | buf, | |
| int | bytes | |||
| ) | [static] |
Definition at line 73 of file isofs_wrap.c.
Referenced by isoburn_start_emulation().
00074 { 00075 int i; 00076 uint32_t ret = 0; 00077 00078 for (i=0; i<bytes; i++) { 00079 ret += ((uint32_t) buf[i]) << (i*8); 00080 } 00081 return ret; 00082 }
| int isoburn_activate_session | ( | struct burn_drive * | drive | ) |
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.
| d | The output drive to which the session was written |
Definition at line 272 of file isofs_wrap.c.
References isoburn::emulation_mode, isoburn::fabricated_disc_status, isoburn::fabricated_msc2, isoburn_find_emulator(), Libisoburn_target_head_sizE, isoburn::target_iso_head, and isoburn::zero_nwa.
Referenced by isoburn_invalidate_iso(), and main().
00273 { 00274 int ret; 00275 struct isoburn *o; 00276 00277 ret = isoburn_find_emulator(&o, drive, 0); 00278 if (ret < 0) 00279 return -1; 00280 00281 if (o->emulation_mode != 1) 00282 return 1; /* don't need to activate session */ 00283 if (o->fabricated_msc2 >= 0) 00284 return 1; /* blind growing: do not alter anything outside the session */ 00285 00286 if (!(o->fabricated_disc_status == BURN_DISC_APPENDABLE || 00287 (o->fabricated_disc_status == BURN_DISC_BLANK && 00288 o->zero_nwa > 0))) 00289 return 1; 00290 00291 ret = burn_random_access_write(drive, (off_t) 0, (char*)o->target_iso_head, 00292 Libisoburn_target_head_sizE, 1); 00293 00294 return ret; 00295 }
| 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 media. 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.
| d | The drive which shall be write target of the volset. | |
| image | The 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. |
Definition at line 249 of file isofs_wrap.c.
References isoburn::image, isoburn_find_emulator(), and isoburn_msgs_submit().
00250 { 00251 int ret; 00252 struct isoburn *o; 00253 00254 ret = isoburn_find_emulator(&o, d, 0); 00255 if (ret < 0 || o == NULL) 00256 return 0; 00257 if (image == NULL) { 00258 isoburn_msgs_submit(o, 0x00060000, 00259 "Program error: isoburn_attach_image: image==NULL", 00260 0, "FATAL", 0); 00261 return -1; 00262 } 00263 if(o->image != NULL) 00264 iso_image_unref(o->image); 00265 o->image = image; 00266 return(1); 00267 }
| IsoImage* isoburn_get_attached_image | ( | struct burn_drive * | d | ) |
Get the image attached to a drive, if any.
| d | The drive to inquire |
Definition at line 87 of file isofs_wrap.c.
References isoburn::image, and isoburn_find_emulator().
00088 { 00089 int ret; 00090 struct isoburn *o= NULL; 00091 ret = isoburn_find_emulator(&o, d, 0); 00092 if (ret < 0) 00093 return NULL; 00094 00095 if (o == NULL) { 00096 return NULL; 00097 } 00098 iso_image_ref(o->image); 00099 return o->image; 00100 }
| static void isoburn_idle_free_function | ( | void * | ignored | ) | [static] |
| int isoburn_invalidate_iso | ( | struct isoburn * | o, | |
| int | flag | |||
| ) |
Alters and writes the first 64 kB of a "media" to invalidate an ISO image.
(It shall stay restorable by skilled humans, though). The result shall especially keep libisoburn from accepting the media image as ISO filesystem.
| o | A fully activated isoburn object. isoburn_start_emulation() was already called. |
Definition at line 381 of file isofs_wrap.c.
References isoburn::drive, isoburn_activate_session(), and isoburn::target_iso_head.
Referenced by isoburn_disc_erase().
00382 { 00383 /* 00384 * replace CD001 with CDXX1 in PVM. 00385 * I think this is enought for invalidating an iso image 00386 */ 00387 strncpy((char*)o->target_iso_head + 16 * 2048 + 1, "CDXX1", 5); 00388 return isoburn_activate_session(o->drive); 00389 }
| int isoburn_read_image | ( | struct burn_drive * | d, | |
| struct isoburn_read_opts * | read_opts, | |||
| IsoImage ** | image | |||
| ) |
Load the ISO filesystem directory tree from the media 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.
| d | The 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_opts | The read options which can be chosen by the application | |
| image | the 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. |
Definition at line 111 of file isofs_wrap.c.
References isoburn_read_opts::dirmode, isoburn_read_opts::gid, isoburn_read_opts::hasElTorito, isoburn_read_opts::hasIso1999, isoburn_read_opts::hasJoliet, isoburn_read_opts::hasRR, isoburn::image, 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_read_opts::mode, isoburn_read_opts::noiso1999, isoburn_read_opts::nojoliet, isoburn_read_opts::norock, isoburn_read_opts::preferjoliet, isoburn_read_opts::pretend_blank, isoburn::read_pacifier, isoburn::read_pacifier_handle, isoburn_read_opts::size, and isoburn_read_opts::uid.
00114 { 00115 int ret, int_num, dummy; 00116 IsoReadOpts *ropts= NULL; 00117 IsoReadImageFeatures *features= NULL; 00118 uint32_t ms_block; 00119 char msg[160]; 00120 enum burn_disc_status status= BURN_DISC_BLANK; 00121 IsoDataSource *ds= NULL; 00122 struct isoburn *o= NULL; 00123 00124 if(d != NULL) { 00125 ret = isoburn_find_emulator(&o, d, 0); 00126 if (ret < 0 || o == NULL) 00127 return 0; 00128 status = isoburn_disc_get_status(d); 00129 } 00130 if(read_opts==NULL) { 00131 isoburn_msgs_submit(o, 0x00060000, 00132 "Program error: isoburn_read_image: read_opts==NULL", 00133 0, "FATAL", 0); 00134 return(-1); 00135 } 00136 if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) { 00137 create_blank_image:; 00138 /* 00139 * Blank disc, we create a new image without files. 00140 */ 00141 00142 if (d == NULL) { 00143 /* New empty image without relation to a drive */ 00144 if (image==NULL) { 00145 isoburn_msgs_submit(o, 0x00060000, 00146 "Program error: isoburn_read_image: image==NULL", 00147 0, "FATAL", 0); 00148 return -1; 00149 } 00150 /* create a new image */ 00151 ret = iso_image_new("ISOIMAGE", image); 00152 if (ret < 0) { 00153 isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0); 00154 return ret; 00155 } 00156 } else { 00157 /* Blank new image for the drive */ 00158 iso_image_unref(o->image); 00159 ret = iso_image_new("ISOIMAGE", &o->image); 00160 if (ret < 0) { 00161 isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0); 00162 return ret; 00163 } 00164 if (image) { 00165 *image = o->image; 00166 iso_image_ref(*image); /*protects object from premature free*/ 00167 } 00168 } 00169 return 1; 00170 } 00171 00172 if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) { 00173 isoburn_msgs_submit(o, 0x00060000, 00174 "Program error: isoburn_read_image: incorrect disc status", 00175 0, "FATAL", 0); 00176 return -4; 00177 } 00178 00179 memset((char *) &ropts, 0, sizeof(ropts)); 00180 00181 ret = isoburn_disc_get_msc1(d, &int_num); 00182 if (ret <= 0) 00183 return -2; 00184 ms_block= int_num; 00185 ret = isoburn_read_iso_head(d, int_num, &dummy, NULL, 0); 00186 if (ret <= 0) { 00187 sprintf(msg, "No ISO 9660 image at LBA %d. Creating blank image.", int_num); 00188 isoburn_msgs_submit(o, 0x00060000, msg, 0, "WARNING", 0); 00189 goto create_blank_image; 00190 } 00191 00192 /* create the data source */ 00193 ret = iso_read_opts_new(&ropts, 0); 00194 if (ret < 0) { 00195 isoburn_report_iso_error(ret, "Cannot create write opts", 0, "FATAL", 0); 00196 return ret; 00197 } 00198 /* Important: do not return until iso_read_opts_free() */ 00199 iso_read_opts_set_start_block(ropts, ms_block); 00200 iso_read_opts_set_no_rockridge(ropts, read_opts->norock); 00201 iso_read_opts_set_no_joliet(ropts, read_opts->nojoliet); 00202 iso_read_opts_set_no_iso1999(ropts, read_opts->noiso1999); 00203 iso_read_opts_set_preferjoliet(ropts, read_opts->preferjoliet); 00204 iso_read_opts_set_default_permissions(ropts, 00205 read_opts->mode, read_opts->dirmode); 00206 iso_read_opts_set_default_uid(ropts, read_opts->uid); 00207 iso_read_opts_set_default_gid(ropts, read_opts->gid); 00208 iso_read_opts_set_input_charset(ropts, read_opts->input_charset); 00209 00210 /* <<< experimental API call of libisofs 00211 iso_read_opts_set_error_behavior(ropts, 1); 00212 */ 00213 00214 ds = isoburn_data_source_new(d); 00215 if(o->iso_data_source!=NULL) 00216 iso_data_source_unref(o->iso_data_source); 00217 o->iso_data_source= ds; 00218 iso_image_attach_data(o->image, o->read_pacifier_handle, 00219 isoburn_idle_free_function); 00220 if(o->read_pacifier_handle==NULL) 00221 iso_tree_set_report_callback(o->image, NULL); 00222 else 00223 iso_tree_set_report_callback(o->image, o->read_pacifier); 00224 ret = iso_image_import(o->image, ds, ropts, &features); 00225 iso_tree_set_report_callback(o->image, NULL); 00226 iso_read_opts_free(ropts); 00227 00228 if (ret < 0) { 00229 isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0); 00230 return ret; 00231 } 00232 /* Important: do not return until free(features) */ 00233 if (image!=NULL) { 00234 *image = o->image; 00235 iso_image_ref(*image); /*protects object from premature free*/ 00236 } 00237 read_opts->hasRR = iso_read_image_features_has_rockridge(features); 00238 read_opts->hasJoliet = iso_read_image_features_has_joliet(features); 00239 read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features); 00240 read_opts->hasElTorito = iso_read_image_features_has_eltorito(features); 00241 read_opts->size = iso_read_image_features_get_size(features); 00242 iso_read_image_features_destroy(features); 00243 return 1; 00244 }
| 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.
| drive | The drive which will be used with isoburn_read_image() It has to be aquired by an isoburn_* wrapper call. | |
| read_pacifier | The callback function | |
| app_handle | The app handle which the callback function can obtain via iso_image_get_attached_data() from its IsoImage* |
Definition at line 393 of file isofs_wrap.c.
References isoburn_find_emulator(), isoburn::read_pacifier, and isoburn::read_pacifier_handle.
00396 { 00397 int ret; 00398 struct isoburn *o; 00399 00400 ret = isoburn_find_emulator(&o, drive, 0); 00401 if(ret < 0 || o == NULL) 00402 return -1; 00403 o->read_pacifier_handle= read_handle; 00404 o->read_pacifier= read_pacifier; 00405 return(1); 00406 }
| 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.
| o | A freshly created isoburn object. isoburn_create_data_source() was already called, nevertheless. |
Definition at line 304 of file isofs_wrap.c.
References isoburn::drive, isoburn::fabricated_disc_status, iso_read_lsb(), isoburn_msgs_submit(), isoburn_set_start_byte(), Libisoburn_target_head_sizE, isoburn::target_iso_head, and isoburn::zero_nwa.
Referenced by isoburn_welcome_media().
00305 { 00306 int ret, i; 00307 off_t data_count; 00308 struct burn_drive *drive; 00309 struct ecma119_pri_vol_desc *pvm; 00310 00311 if(o==NULL) { 00312 isoburn_msgs_submit(NULL, 0x00060000, 00313 "Program error: isoburn_start_emulation: o==NULL", 00314 0, "FATAL", 0); 00315 return -1; 00316 } 00317 00318 drive= o->drive; 00319 00320 /* we can assume 0 as start block for image */ 00321 /* TODO what about ms? where we validate valid iso image in ms disc? */ 00322 ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head, 00323 (off_t) Libisoburn_target_head_sizE, &data_count, 2); 00324 00325 /* an error means an empty disc */ 00326 if (ret <= 0) { 00327 o->fabricated_disc_status= BURN_DISC_BLANK; 00328 return 1; 00329 } 00330 00331 /* check first 64K. If 0's, the disc is treated as a blank disc, and thus 00332 overwritten without extra check. */ 00333 i = Libisoburn_target_head_sizE; 00334 while (i && !o->target_iso_head[i-1]) 00335 --i; 00336 00337 if (!i) { 00338 o->fabricated_disc_status= BURN_DISC_BLANK; 00339 return 1; 00340 } 00341 00342 pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048); 00343 00344 if (!strncmp((char*)pvm->std_identifier, "CD001", 5)) { 00345 off_t size; 00346 00347 /* sanity check */ 00348 if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1 00349 || pvm->file_structure_version[0] != 1 ) { 00350 /* TODO for now I treat this as a full disc */ 00351 o->fabricated_disc_status= BURN_DISC_FULL; 00352 return 1; 00353 } 00354 00355 /* ok, PVM found, set size */ 00356 size = (off_t) iso_read_lsb(pvm->vol_space_size, 4); 00357 size *= (off_t) 2048; /* block size in bytes */ 00358 isoburn_set_start_byte(o, size, 0); 00359 o->fabricated_disc_status= BURN_DISC_APPENDABLE; 00360 } else if (!strncmp((char*)pvm->std_identifier, "CDXX1", 5)) { 00361 00362 /* empty image */ 00363 isoburn_set_start_byte(o, o->zero_nwa * 2048, 0); 00364 o->fabricated_disc_status= BURN_DISC_BLANK; 00365 } else { 00366 /* treat any disc in an unknown format as full */ 00367 o->fabricated_disc_status= BURN_DISC_FULL; 00368 } 00369 return 1; 00370 }
1.5.6