1
2 /*
3 cc -g -c isofs_wrap.c
4 */
5
6 /*
7 libisofs related functions of libisoburn.
8
9 Copyright 2007 - 2017 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
10 Thomas Schmitt <scdbackup@gmx.net>
11 Provided under GPL version 2 or later.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include "../config.h"
16 #endif
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdio.h>
21
22 #ifndef Xorriso_standalonE
23
24 #include <libburn/libburn.h>
25
26 #include <libisofs/libisofs.h>
27
28 #else /* ! Xorriso_standalonE */
29
30 #include "../libisofs/libisofs.h"
31 #include "../libburn/libburn.h"
32
33 #endif /* Xorriso_standalonE */
34
35 #include "libisoburn.h"
36 #include "isoburn.h"
37
38 #define BP(a,b) [(b) - (a) + 1]
39
40 struct ecma119_pri_vol_desc
41 {
42 uint8_t vol_desc_type BP(1, 1);
43 uint8_t std_identifier BP(2, 6);
44 uint8_t vol_desc_version BP(7, 7);
45 uint8_t unused1 BP(8, 8);
46 uint8_t system_id BP(9, 40);
47 uint8_t volume_id BP(41, 72);
48 uint8_t unused2 BP(73, 80);
49 uint8_t vol_space_size BP(81, 88);
50 uint8_t unused3 BP(89, 120);
51 uint8_t vol_set_size BP(121, 124);
52 uint8_t vol_seq_number BP(125, 128);
53 uint8_t block_size BP(129, 132);
54 uint8_t path_table_size BP(133, 140);
55 uint8_t l_path_table_pos BP(141, 144);
56 uint8_t opt_l_path_table_pos BP(145, 148);
57 uint8_t m_path_table_pos BP(149, 152);
58 uint8_t opt_m_path_table_pos BP(153, 156);
59 uint8_t root_dir_record BP(157, 190);
60 uint8_t vol_set_id BP(191, 318);
61 uint8_t publisher_id BP(319, 446);
62 uint8_t data_prep_id BP(447, 574);
63 uint8_t application_id BP(575, 702);
64 uint8_t copyright_file_id BP(703, 739);
65 uint8_t abstract_file_id BP(740, 776);
66 uint8_t bibliographic_file_id BP(777, 813);
67 uint8_t vol_creation_time BP(814, 830);
68 uint8_t vol_modification_time BP(831, 847);
69 uint8_t vol_expiration_time BP(848, 864);
70 uint8_t vol_effective_time BP(865, 881);
71 uint8_t file_structure_version BP(882, 882);
72 uint8_t reserved1 BP(883, 883);
73 uint8_t app_use BP(884, 1395);
74 uint8_t reserved2 BP(1396, 2048);
75 };
76
77 static
iso_read_lsb(const uint8_t * buf,int bytes)78 uint32_t iso_read_lsb(const uint8_t *buf, int bytes)
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 }
88
89
90 /* API function. See libisoburn.h
91 */
isoburn_get_attached_image(struct burn_drive * d)92 IsoImage *isoburn_get_attached_image(struct burn_drive *d)
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 }
106
107
108 /* API */
isoburn_get_attached_start_lba(struct burn_drive * d)109 int isoburn_get_attached_start_lba(struct burn_drive *d)
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 }
121
122
isoburn_idle_free_function(void * ignored)123 static void isoburn_idle_free_function(void *ignored)
124 {
125 return;
126 }
127
128
isoburn_root_defaults(IsoImage * image,int flag)129 int isoburn_root_defaults(IsoImage *image, int flag)
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 }
138
139
140 /* API function. See libisoburn.h
141 */
isoburn_read_image(struct burn_drive * d,struct isoburn_read_opts * read_opts,IsoImage ** image)142 int isoburn_read_image(struct burn_drive *d,
143 struct isoburn_read_opts *read_opts,
144 IsoImage **image)
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 iso_read_opts_set_new_inos(ropts, read_opts->noino);
279
280 iso_read_opts_set_no_joliet(ropts, read_opts->nojoliet);
281 iso_read_opts_set_no_iso1999(ropts, read_opts->noiso1999);
282 iso_read_opts_set_preferjoliet(ropts, read_opts->preferjoliet);
283 iso_read_opts_set_default_permissions(ropts,
284 read_opts->mode, read_opts->dirmode);
285 iso_read_opts_set_default_uid(ropts, read_opts->uid);
286 iso_read_opts_set_default_gid(ropts, read_opts->gid);
287 iso_read_opts_set_input_charset(ropts, read_opts->input_charset);
288 iso_read_opts_auto_input_charset(ropts, read_opts->auto_input_charset);
289 iso_read_opts_load_system_area(ropts, 1);
290 iso_read_opts_keep_import_src(ropts, 1);
291 ret= iso_image_set_truncate_mode(o->image, read_opts->truncate_mode,
292 read_opts->truncate_length);
293 if(ret < 0)
294 goto ex;
295
296 ds = isoburn_data_source_new(d, read_opts->displacement,
297 read_opts->displacement_sign,
298 read_opts->cache_tiles, read_opts->cache_tile_blocks);
299 if (ds == NULL) {
300 isoburn_report_iso_error(ret, "Cannot create IsoDataSource object", 0,
301 "FATAL", 0);
302 ret= -1; goto ex;
303 }
304 if(o->iso_data_source!=NULL)
305 iso_data_source_unref(o->iso_data_source);
306 o->iso_data_source= ds;
307 iso_image_attach_data(o->image, o->read_pacifier_handle,
308 isoburn_idle_free_function);
309 if(o->read_pacifier_handle==NULL)
310 iso_tree_set_report_callback(o->image, NULL);
311 else
312 iso_tree_set_report_callback(o->image, o->read_pacifier);
313
314 ret = iso_image_import(o->image, ds, ropts, &features);
315 iso_tree_set_report_callback(o->image, NULL);
316 iso_read_opts_free(ropts);
317 ropts= NULL;
318
319 if (ret < 0) {
320 isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0);
321 goto ex;
322 }
323 /* Important: do not return until free(features) */
324 if (image!=NULL) {
325 *image = o->image;
326 iso_image_ref(*image); /*protects object from premature free*/
327 }
328 read_opts->hasRR = iso_read_image_features_has_rockridge(features);
329 read_opts->hasJoliet = iso_read_image_features_has_joliet(features);
330 read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features);
331 read_opts->hasElTorito = iso_read_image_features_has_eltorito(features);
332 read_opts->size = iso_read_image_features_get_size(features);
333 ret= 1;
334 ex:;
335 if(msg != NULL)
336 free(msg);
337 if(ropts != NULL)
338 iso_read_opts_free(ropts);
339 if(features != NULL)
340 iso_read_image_features_destroy(features);
341 return(ret);
342 }
343
344
345 /* API function. See libisoburn.h
346 */
isoburn_attach_image(struct burn_drive * d,IsoImage * image)347 int isoburn_attach_image(struct burn_drive *d, IsoImage *image)
348 {
349 int ret;
350 struct isoburn *o;
351
352 ret = isoburn_find_emulator(&o, d, 0);
353 if (ret < 0 || o == NULL)
354 return 0;
355 if (image == NULL) {
356 isoburn_msgs_submit(o, 0x00060000,
357 "Program error: isoburn_attach_image: image==NULL",
358 0, "FATAL", 0);
359 return -1;
360 }
361 if(o->image != NULL)
362 iso_image_unref(o->image);
363 o->image = image;
364 o->image_start_lba = -1;
365 return(1);
366 }
367
368
369 /* API */
isoburn_attach_start_lba(struct burn_drive * d,int lba,int flag)370 int isoburn_attach_start_lba(struct burn_drive *d, int lba, int flag)
371 {
372 int ret;
373 struct isoburn *o;
374
375 ret = isoburn_find_emulator(&o, d, 0);
376 if(ret < 0)
377 return ret;
378 if(o == NULL)
379 return 0;
380 if(o->image == NULL)
381 return 0;
382 o->image_start_lba = lba;
383 return 1;
384 }
385
386
387 /* API function. See libisoburn.h
388 */
isoburn_activate_session(struct burn_drive * drive)389 int isoburn_activate_session(struct burn_drive *drive)
390 {
391 int ret, do_sync = 1;
392 struct isoburn *o;
393
394 ret = isoburn_find_emulator(&o, drive, 0);
395 if (ret < 0)
396 return -1;
397
398 if (o->emulation_mode != 1)
399 return 1; /* don't need to activate session */
400 if (o->fabricated_msc2 >= 0)
401 return 1; /* blind growing: do not alter anything outside the session */
402
403 if (!(o->fabricated_disc_status == BURN_DISC_APPENDABLE ||
404 (o->fabricated_disc_status == BURN_DISC_BLANK &&
405 o->zero_nwa > 0)))
406 return 1;
407 ret = burn_drive_get_drive_role(drive);
408 if (ret != 1)
409 do_sync = !! o->do_fsync;
410
411 ret = burn_random_access_write(drive, (off_t) 0, (char*)o->target_iso_head,
412 o->target_iso_head_size, do_sync);
413
414 return ret;
415 }
416
417
418 /** API @since 0.6.2
419 */
isoburn_get_img_partition_offset(struct burn_drive * drive,uint32_t * block_offset_2k)420 int isoburn_get_img_partition_offset(struct burn_drive *drive,
421 uint32_t *block_offset_2k)
422 {
423 int ret;
424 struct isoburn *o;
425
426 ret = isoburn_find_emulator(&o, drive, 0);
427 if(ret < 0 || o == NULL)
428 return -1;
429 *block_offset_2k= o->loaded_partition_offset;
430 if(o->loaded_partition_offset == 0)
431 return(0);
432 if(o->target_iso_head_size == (off_t) Libisoburn_target_head_sizE
433 + (off_t) 2048 * (off_t) o->loaded_partition_offset)
434 return(1);
435 return(2);
436 }
437
438
439 /* Check for MBR signature and a first partition that starts at a 2k block
440 and ends where the image ends.
441 If not too large or too small, accept its start as partition offset.
442 */
isoburn_inspect_partition(struct isoburn * o,uint32_t img_size,int flag)443 static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size,
444 int flag)
445 {
446 uint8_t *mbr, *part, *buf= NULL;
447 uint32_t offst, numsec;
448 struct ecma119_pri_vol_desc *pvm;
449 off_t data_count;
450 int ret;
451 char *msg= NULL;
452 static int max_offst= 512 - 32;
453
454 buf= (uint8_t *) calloc(1, 2048);
455 msg= calloc(1, 160);
456 if(buf == NULL || msg == NULL)
457 {ret= -1; goto ex;}
458
459 mbr= o->target_iso_head;
460 part= mbr + 446;
461 if(mbr[510] != 0x55 || mbr[511] != 0xAA)
462 {ret= 2; goto ex;} /* not an MBR */
463
464 /* Does the first partition entry look credible ? */
465 if(part[0] != 0x80 && part[0] != 0x00)
466 {ret= 2; goto ex;} /* Invalid partition status */
467 if(part[1] == 0 && part[2] == 0 && part[3] == 0)
468 {ret= 2; goto ex;} /* Zero C/H/S start address */
469
470 /* Does it match the normal ISO image ? */
471 offst= iso_read_lsb(part + 8, 4);
472 numsec= iso_read_lsb(part + 12, 4);
473 if(offst < 64)
474 {ret= 2; goto ex;} /* Zero or unusably small partition start */
475 if((offst % 4) || (numsec % 4))
476 {ret= 2; goto ex;} /* Not aligned to 2k */
477 if(numsec < 72)
478 {ret= 2; goto ex;} /* No room for volume descriptors */
479 offst/= 4;
480 numsec/= 4;
481 if(offst + numsec > img_size)
482 {ret= 2; goto ex;} /* Partition end exceeds image end */
483
484 /* Is there a PVD at the partition start ? */
485 ret = burn_read_data(o->drive, (off_t) (offst + 16) * (off_t) 2048,
486 (char*) buf, 2048, &data_count, 32);
487 if(ret <= 0)
488 {ret= 2; goto ex;}
489 pvm = (struct ecma119_pri_vol_desc *) buf;
490 if (strncmp((char*) pvm->std_identifier, "CD001", 5) != 0)
491 {ret= 2; goto ex;} /* not a PVD */
492 if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
493 || pvm->file_structure_version[0] != 1 )
494 {ret= 2; goto ex;} /* failed sanity check */
495
496 if(iso_read_lsb(pvm->vol_space_size, 4) + offst > img_size)
497 {ret= 2; goto ex;} /* Image ends do not match plausibly */
498
499 /* Now it is credible. Not yet clear is whether it is acceptable. */
500 o->loaded_partition_offset= offst;
501
502 /* If the partition start is too large: Report but do not accept. */
503 if(offst > (uint32_t) max_offst) {/* Not more than 1 MB of .target_iso_head */
504 sprintf(msg,
505 "Detected partition offset of %.f blocks. Maximum for load buffer is %d",
506 (double) offst, max_offst);
507 isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "WARNING", 0);
508 {ret= 3; goto ex;}
509 }
510
511 /* Accept partition start and adjust buffer size */
512 ret= isoburn_adjust_target_iso_head(o, offst, 0);
513 if(ret <= 0)
514 goto ex;
515
516 ret= 1;
517 ex:;
518 if(buf != NULL)
519 free(buf);
520 if(msg != NULL)
521 free(msg);
522 return(ret);
523 }
524
525
526 /** Initialize the emulation of multi-session on random access media.
527 The need for emulation is confirmed already.
528 @param o A freshly created isoburn object. isoburn_create_data_source() was
529 already called, nevertheless.
530 @param flag bit0= read-only
531 @return <=0 error , 1 = success
532 */
isoburn_start_emulation(struct isoburn * o,int flag)533 int isoburn_start_emulation(struct isoburn *o, int flag)
534 {
535 int ret, i, capacity = -1, role, dummy;
536 off_t data_count, to_read;
537 struct burn_drive *drive;
538 struct ecma119_pri_vol_desc *pvm;
539 enum burn_disc_status s;
540 char *path= NULL, *msg= NULL;
541
542 path= calloc(1, BURN_DRIVE_ADR_LEN);
543 msg= calloc(1, 2 * BURN_DRIVE_ADR_LEN);
544 if(path == NULL || msg == NULL)
545 {ret= -1; goto ex;}
546
547 if(o==NULL) {
548 isoburn_msgs_submit(NULL, 0x00060000,
549 "Program error: isoburn_start_emulation: o==NULL",
550 0, "FATAL", 0);
551 {ret= -1; goto ex;}
552 }
553
554 drive= o->drive;
555
556 if(flag & 1)
557 o->fabricated_disc_status= BURN_DISC_FULL;
558
559 /* We can assume 0 as start block for image.
560 The data there point to the most recent session.
561 */
562 role = burn_drive_get_drive_role(drive);
563 ret = burn_get_read_capacity(drive, &capacity, 0);
564 if (ret <= 0)
565 capacity = -1;
566 if (role == 5) { /* random access write-only medium */
567 s = burn_disc_get_status(drive);
568 o->fabricated_disc_status= s;
569 burn_disc_track_lba_nwa(drive, NULL, 0, &dummy, &(o->nwa));
570 if(o->nwa < o->zero_nwa)
571 o->zero_nwa= 0;
572 {ret= 1; goto ex;}
573 } else if (capacity > 0 || role == 2 || role == 4) {
574 /* Might be a block device on a system where libburn cannot determine its
575 size. Try to read anyway. */
576 to_read = o->target_iso_head_size;
577 memset(o->target_iso_head, 0, to_read);
578 if(capacity > 0 && (off_t) capacity * (off_t) 2048 < to_read)
579 to_read = (off_t) capacity * (off_t) 2048;
580 ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head,
581 to_read, &data_count, 32 | 8);
582 if (ret <= 0) {
583 /* an error means a disc with no ISO image */
584 o->media_read_error= 1;
585 if (ret == -2) {
586 path[0]= 0;
587 burn_drive_d_get_adr(drive, path);
588 sprintf(msg, "Pseudo drive '%s' does not allow reading", path);
589 isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "NOTE", 0);
590 o->fabricated_disc_status= BURN_DISC_BLANK;
591 } else if (capacity > 0)
592 o->fabricated_disc_status= BURN_DISC_FULL;
593 else if(!(flag & 1))
594 o->fabricated_disc_status= BURN_DISC_BLANK;
595 {ret= 1; goto ex;}
596 }
597 } else {
598 /* No read capacity means blank medium */
599 if(!(flag & 1))
600 o->fabricated_disc_status= BURN_DISC_BLANK;
601 {ret= 1; goto ex;}
602 }
603
604 /* check first 64K. If 0's, the disc is treated as a blank disc, and thus
605 overwritten without extra check. */
606 i = Libisoburn_target_head_sizE;
607 while (i && !o->target_iso_head[i-1])
608 --i;
609
610 if (!i) {
611 if(!(flag & 1))
612 o->fabricated_disc_status= BURN_DISC_BLANK;
613 {ret= 1; goto ex;}
614 }
615
616 pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
617
618 if (strncmp((char*)pvm->std_identifier, "CD001", 5) == 0) {
619 off_t size;
620
621 /* sanity check */
622 if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
623 || pvm->file_structure_version[0] != 1 ) {
624 /* TODO for now I treat this as a full disc */
625 o->fabricated_disc_status= BURN_DISC_FULL;
626 {ret= 1; goto ex;}
627 }
628
629 /* ok, PVM found, set size */
630 size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
631 ret= isoburn_inspect_partition(o, (uint32_t) size, 0);
632 if (ret <= 0)
633 goto ex;
634 size *= (off_t) 2048; /* block size in bytes */
635 isoburn_set_start_byte(o, size, 0);
636 if(!(flag & 1))
637 o->fabricated_disc_status= BURN_DISC_APPENDABLE;
638 } else if (strncmp((char*)pvm->std_identifier, "CDXX1", 5) == 0 ||
639 (strncmp((char*)pvm->std_identifier, "CDxx1", 5) == 0 &&
640 pvm->vol_desc_type[0] == 'x')) {
641
642 /* empty image */
643 isoburn_set_start_byte(o, o->zero_nwa * 2048, 0);
644 if(!(flag & 1))
645 o->fabricated_disc_status= BURN_DISC_BLANK;
646 } else {
647 /* treat any disc in an unknown format as full */
648 o->fabricated_disc_status= BURN_DISC_FULL;
649 }
650
651 ret= 1;
652 ex:;
653 if(path != NULL)
654 free(path);
655 if(msg != NULL)
656 free(msg);
657 return(ret);
658 }
659
660
661 /** Alters and writes the first 64 kB of a "medium" to invalidate
662 an ISO image. (It shall stay restorable by skilled humans, though).
663 The result shall especially keep libisoburn from accepting the medium
664 image as ISO filesystem.
665 @param o A fully activated isoburn object. isoburn_start_emulation()
666 was already called.
667 @return <=0 error , 1 = success
668 */
isoburn_invalidate_iso(struct isoburn * o,int flag)669 int isoburn_invalidate_iso(struct isoburn *o, int flag)
670 {
671 int end_ed_found= 0, i;
672 char *head;
673
674 head= (char *) o->target_iso_head;
675 /*
676 * replace CD001 with CDXX1 in PVM.
677 */
678 strncpy(head + 16 * 2048 + 1, "CDXX1", 5);
679
680 /* Invalidate further ECMA-119 volume descriptors and possible UDF volume
681 recognition sequence */
682 for(i= 17 * 2048; i < 32 * 2048; i+= 2048) {
683 if(end_ed_found) {
684 if(head[i] == 0 && strncmp(head + i + 1, "BEA01", 5) == 0)
685 strncpy(head + i + 1, "BEAX1", 5);
686 else if(head[i] == 0 && strncmp(head + i + 1, "NSR", 3) == 0)
687 strncpy(head + i + 1, "NSRX", 4);
688 else if(head[i] == 0 && strncmp(head + i + 1, "TEA", 3) == 0)
689 strncpy(head + i + 1, "TEAX", 4);
690 } else if(strncmp(head + i + 1, "CD001", 5) == 0) {
691 if(((unsigned char *) head)[i] == 0xff)
692 end_ed_found= 1;
693 strncpy(head + i + 3, "XX", 2);
694 }
695 }
696
697 return isoburn_activate_session(o->drive);
698 }
699
700
701 /* API @since 0.1.0 */
isoburn_set_read_pacifier(struct burn_drive * drive,int (* read_pacifier)(IsoImage *,IsoFileSource *),void * read_handle)702 int isoburn_set_read_pacifier(struct burn_drive *drive,
703 int (*read_pacifier)(IsoImage*, IsoFileSource*),
704 void *read_handle)
705 {
706 int ret;
707 struct isoburn *o;
708
709 ret = isoburn_find_emulator(&o, drive, 0);
710 if(ret < 0 || o == NULL)
711 return -1;
712 o->read_pacifier_handle= read_handle;
713 o->read_pacifier= read_pacifier;
714 return(1);
715 }
716
717