~ubuntu-branches/ubuntu/precise/libisoburn/precise

« back to all changes in this revision

Viewing changes to libisoburn/burn_wrap.c

  • Committer: Bazaar Package Importer
  • Author(s): George Danchev
  • Date: 2011-05-26 16:21:32 UTC
  • mfrom: (9.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110526162132-9lzoagfaggnera53
Tags: 1.0.8.pl00-4
* [MA] Improve package descriptions and README.Debian.
* [MA] Migrate to format "3.0 (quilt)" and compatibility 8.
  + debian/control: Drop build-dep on 'cdbs'. Require debhelper (>= 8).
  + debian/rules: Reformulate using 'dh'.
  + debian/libisoburn{1,-dev,-doc}.docs: New files.
  + debian/xorriso.docs: Addition of upstream documents.
* [GD] Make sure doxygen documentaton (doc package) is not built
       when dpkg-buildpackage -B is called (i.e. autobuilders).
* [GD] Move doxygen, graphviz to Build-Depends-Indep.
* [GD] Add missing copyrights for debian packaging.
* [GD] Standards-Version: 3.9.2 (no changes needed).
* [GD] More package description and README.Debian improvements;
       thanks to Tony Mancill <tmancill@debian.org>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
*/
7
7
/* libburn wrappers for libisoburn 
8
8
 
9
 
   Copyright 2007 - 2010  Thomas Schmitt, <scdbackup@gmx.net> 
 
9
   Copyright 2007 - 2011  Thomas Schmitt, <scdbackup@gmx.net> 
10
10
   Provided under GPL version 2 or later.
11
11
*/
12
12
 
 
13
#ifdef HAVE_CONFIG_H
 
14
#include "../config.h"
 
15
#endif
 
16
 
13
17
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo 
14
18
#define Hardcoded_cd_rW 1
15
19
#define Hardcoded_cd_rw_c1     12999
27
31
#include <time.h>
28
32
#include <regex.h>
29
33
 
30
 
 
31
34
#ifndef Xorriso_standalonE
32
35
 
33
36
#include <libburn/libburn.h>
34
 
 
35
37
#include <libisofs/libisofs.h>
 
38
#ifdef Xorriso_with_libjtE
 
39
#include <libjte/libjte.h>
 
40
#endif
36
41
 
37
42
#else /* ! Xorriso_standalonE */
38
43
 
39
44
#include "../libisofs/libisofs.h"
40
45
#include "../libburn/libburn.h"
 
46
#ifdef Xorriso_with_libjtE
 
47
#include "../libjte/libjte.h"
 
48
#endif
41
49
 
42
50
#endif /* Xorriso_standalonE */
43
51
 
65
73
 
66
74
int isoburn_initialize(char msg[1024], int flag)
67
75
{
68
 
 int major, minor, micro, bad_match= 0;
69
 
 
70
 
 
71
 
/* First two ugly compile time checks for header version compatibility.
 
76
 int major, minor, micro, bad_match= 0, no_iso_init= 0;
 
77
 
 
78
 
 
79
/* First the ugly compile time checks for header version compatibility.
72
80
   If everthing matches, then they produce no C code. In case of mismatch,
73
81
   intentionally faulty C code will be inserted.
74
82
*/
104
112
 
105
113
#ifdef Isoburn_libisofs_dot_h_too_olD
106
114
LIBISOFS_MISCONFIGURATION = 0;
107
 
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisofs_dot_h_TOO_OLD__SEE_libisoburn_dot_h_AND_burn_wrap_dot_h = 0;
 
115
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisofs_dot_h_TOO_OLD__SEE_libisoburn_dot_h_AND_burn_wrap_dot_c = 0;
108
116
LIBISOFS_MISCONFIGURATION_ = 0;
109
117
#endif
110
118
 
145
153
LIBBURN_MISCONFIGURATION_ = 0;
146
154
#endif
147
155
 
 
156
 
 
157
#ifdef Xorriso_with_libjtE
 
158
 
 
159
/* The minimum requirement of libisoburn towards the libjte header
 
160
   at compile time is the same as the one of a usable libisfs itowards libjte.
 
161
   So the requirement is defined in libisofs/libisofs.h :
 
162
     iso_libjte_req_major , iso_libjte_req_minor , iso_libjte_req_micro
 
163
*/
 
164
 /* The indendation is an advise of man gcc to help old compilers ignoring */
 
165
 #if iso_libjte_req_major > LIBJTE_VERSION_MAJOR
 
166
 #define Libisofs_libjte_dot_h_too_olD 1
 
167
 #endif
 
168
 #if iso_libjte_req_major == LIBJTE_VERSION_MAJOR && iso_libjte_req_minor > LIBJTE_VERSION_MINOR
 
169
 #define Libisofs_libjte_dot_h_too_olD 1
 
170
 #endif
 
171
 #if iso_libjte_req_minor == LIBJTE_VERSION_MINOR && iso_libjte_req_micro > LIBJTE_VERSION_MICRO
 
172
 #define Libisofs_libjte_dot_h_too_olD 1
 
173
 #endif
 
174
 
 
175
#ifdef Libisofs_libjte_dot_h_too_olD
 
176
LIBJTE_MISCONFIGURATION = 0;
 
177
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libjte_dot_h_TOO_OLD__SEE_libisofs_dot_h_AND_burn_wrap.c_c = 0;
 
178
LIBJTE_MISCONFIGURATION_ = 0;
 
179
#endif
 
180
 
 
181
#endif /* Xorriso_with_libjtE */
 
182
 
 
183
 
148
184
/* End of ugly compile time tests (scroll up for explanation) */
149
185
 
150
186
 
151
 
 
152
187
 msg[0]= 0;
153
 
 if(iso_init()<0) {
154
 
   sprintf(msg+strlen(msg), "Cannot initialize libisofs\n");
155
 
   return(0);
 
188
 
 
189
#ifdef Xorriso_with_libjtE
 
190
 
 
191
 libjte__version(&major, &minor, &micro);
 
192
 sprintf(msg + strlen(msg), "libjte-%d.%d.%d ", major, minor, micro);
 
193
 if (libjte__is_compatible(LIBJTE_VERSION_MAJOR, LIBJTE_VERSION_MINOR,
 
194
                                LIBJTE_VERSION_MICRO, 0)) {
 
195
   sprintf(msg+strlen(msg), "ok, ");
 
196
 } else {
 
197
   sprintf(msg + strlen(msg),
 
198
           "- TOO OLD -, need at least libjte-%d.%d.%d ,\n",
 
199
           LIBJTE_VERSION_MAJOR, LIBJTE_VERSION_MINOR,
 
200
           LIBJTE_VERSION_MICRO);
 
201
   bad_match= 1;
 
202
   no_iso_init= 1; /* iso_init() will fail anyway */
 
203
 }
 
204
 
 
205
#endif /* Xorriso_with_libjtE */
 
206
 
 
207
 if(!no_iso_init) {
 
208
   if(iso_init()<0) {
 
209
     sprintf(msg+strlen(msg), "Cannot initialize libisofs\n");
 
210
     return(0);
 
211
   }
156
212
 }
157
213
 iso_lib_version(&major, &minor, &micro);
158
214
 sprintf(msg+strlen(msg), "libisofs-%d.%d.%d ", major, minor, micro);
184
240
   sprintf(msg+strlen(msg), "Cannot initialize libburn\n");
185
241
   return(0);
186
242
 }
 
243
 
187
244
 burn_version(&major, &minor, &micro);
188
245
 sprintf(msg+strlen(msg), "libburn-%d.%d.%d ", major, minor, micro);
189
246
 if(major > burn_header_version_major
229
286
}
230
287
 
231
288
 
 
289
/* API @since 0.6.4 */
 
290
int isoburn_libjte_req(int *major, int *minor, int *micro)
 
291
{
 
292
#ifdef Xorriso_with_libjtE
 
293
 *major= LIBJTE_VERSION_MAJOR;
 
294
 *minor= LIBJTE_VERSION_MINOR;
 
295
 *micro= LIBJTE_VERSION_MICRO;
 
296
#else
 
297
 *major= *minor= *micro= 0;
 
298
#endif /* ! Xorriso_with_libjtE */
 
299
 return(1);
 
300
}
 
301
 
 
302
 
232
303
int isoburn_set_msgs_submit(int (*msgs_submit)(void *handle, int error_code,
233
304
                                               char msg_text[], int os_errno,
234
305
                                               char severity[], int flag),
273
344
static int isoburn_welcome_media(struct isoburn **o, struct burn_drive *d,
274
345
                                 int flag)
275
346
{
276
 
 int ret, lba, nwa, profile, readonly= 0;
 
347
 int ret, lba, nwa, profile, readonly= 0, role, random_access;
 
348
 int emulation_started= 0;
277
349
 struct burn_multi_caps *caps= NULL;
278
350
 struct isoburn_toc_entry *t;
279
351
 char profile_name[80];
312
384
 (*o)->fabricated_disc_status= BURN_DISC_APPENDABLE;
313
385
#endif
314
386
 
315
 
 if(caps->start_adr)
 
387
 role= burn_drive_get_drive_role(d);
 
388
 random_access= caps->start_adr || role == 4;
 
389
 if(random_access)
316
390
   (*o)->emulation_mode= 1;
317
 
 if(caps->start_adr && !readonly) {       /* set emulation to overwriteable */
 
391
 if(random_access && !readonly) {       /* set emulation to overwriteable */
318
392
   ret= isoburn_is_intermediate_dvd_rw(d, 0);
319
393
   if(ret>0) {
320
394
     (*o)->min_start_byte= 0;
321
395
     (*o)->nwa= 0;
322
396
     (*o)->zero_nwa= 0;
323
397
   }
324
 
   if(flag&1) {
 
398
   if((flag & 1) && role != 4 && role != 5) {
325
399
     (*o)->nwa= (*o)->zero_nwa;
326
400
     (*o)->fabricated_disc_status= BURN_DISC_BLANK;
327
401
   } else {
330
404
       (*o)->emulation_mode= -1;
331
405
       goto ex;
332
406
     }
 
407
     emulation_started= 1;
333
408
     /* try to read emulated toc */
334
409
     ret= isoburn_emulate_toc(d, flag & 16);
335
410
     if(ret<0) {
370
445
     if((flag & 16) || track_count >= 2) {
371
446
       ret= 0; /* toc emulation off, or not overwriteable */
372
447
     } else {
 
448
       ret= isoburn_start_emulation(*o, 1);
 
449
       if(ret<=0) {
 
450
         (*o)->emulation_mode= -1;
 
451
         goto ex;
 
452
       }
 
453
       emulation_started= 1;
373
454
       ret= isoburn_emulate_toc(d, 1);
374
455
       if(ret<0)
375
456
         goto ex;
382
463
          CD-R TOC (profile 0x08) can be trusted. Others not.
383
464
          Do a scan search of ISO headers.
384
465
       */
 
466
       if(!emulation_started) {
 
467
         ret= isoburn_start_emulation(*o, 1);
 
468
         if(ret<=0) {
 
469
           (*o)->emulation_mode= -1;
 
470
           goto ex;
 
471
         }
 
472
       }
385
473
       ret= isoburn_emulate_toc(d, 1|2);
386
474
       if(ret<0)
387
475
         goto ex;
565
653
 
566
654
void isoburn_disc_erase(struct burn_drive *drive, int fast)
567
655
{
568
 
 int ret, do_pseudo_blank= 0;
 
656
 int ret, do_pseudo_blank= 0, role;
569
657
 struct isoburn *o;
570
658
 enum burn_disc_status s;
571
659
 char zero_buffer[Libisoburn_target_head_sizE];
578
666
     burn_drive_cancel(drive);
579
667
     goto ex;
580
668
   }
581
 
 
 
669
   role = burn_drive_get_drive_role(drive);
 
670
   if (role == 5) {
 
671
     /* libburn will truncate the random-access write-only file
 
672
        to zero size and change its state */
 
673
     burn_disc_erase(drive, fast);
 
674
     o->fabricated_disc_status= burn_disc_get_status(drive);
 
675
     o->nwa= 0;
 
676
     goto ex;
 
677
   }
582
678
   if(o->emulation_mode > 0) { /* might be readonly with emulated sessions */
583
679
     ret= burn_disc_get_multi_caps(drive, BURN_WRITE_NONE, &caps, 0);
584
680
     if(ret > 0 && caps->start_adr)
710
806
 return(1);
711
807
}
712
808
 
 
809
/* @param flag bit0= truncate (else do not truncate)
 
810
               bit1= do not warn if call is inappropriate to drive 
 
811
               bit2= only set if truncation is currently enabled
 
812
*/
 
813
int isoburn_set_truncate(struct burn_drive *drive, int flag)
 
814
{
 
815
 int ret;
 
816
 struct isoburn *o;
 
817
 
 
818
 ret= isoburn_find_emulator(&o, drive, 0);
 
819
 if(ret < 0)
 
820
   return ret;
 
821
 if(o == NULL) {
 
822
   if(!(flag & (2 | 4)))
 
823
     isoburn_msgs_submit(o, 0x00060000,
 
824
        "Drive type or role is inappropriate for truncation", 0, "WARNING", 0);
 
825
   return(0);
 
826
 }
 
827
 if(o->truncate || !(flag & 4))
 
828
   o->truncate= flag & 1;
 
829
 return(1);
 
830
}
 
831
 
713
832
 
714
833
void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
715
834
{
758
877
         return;
759
878
       }
760
879
       /* end of DVD-RW oriented check */
761
 
 
762
880
       burn_write_opts_set_start_byte(opts, nwa * (off_t) 2048);
763
881
     }
764
882
   }
790
908
 
791
909
 if(o->truncate) {
792
910
   ret= burn_drive_get_drive_role(drive);
793
 
   if(ret==2) {
 
911
   if(ret == 2 || ret == 5) {
794
912
     ret= burn_drive_d_get_adr(drive, adr);
795
913
     if(ret>0) {
796
914
       ret= lstat(adr, &stbuf);
797
915
       if(ret!=-1)
798
916
         if(S_ISREG(stbuf.st_mode))
799
 
           truncate(adr, nwa * (off_t) 2048);
 
917
           ret= truncate(adr, nwa * (off_t) 2048);
 
918
           /* (result of truncate intentionally ignored) */
800
919
     }
801
920
   }
802
921
 }
1071
1190
 unsigned char buffer[64*1024];
1072
1191
 int ret, info_mode, capacity, role;
1073
1192
 off_t data_count, to_read;
 
1193
 enum burn_disc_status s;
1074
1194
 
1075
1195
 info_mode= flag&255;
1076
1196
 *image_blocks= 0;
1077
1197
 if(flag&(1<<13)) {
1078
1198
   memcpy(buffer, info, 64*1024);
1079
1199
 } else {
 
1200
   memset(buffer, 0, 64 * 1024);
 
1201
   s= isoburn_disc_get_status(d);
1080
1202
   role = burn_drive_get_drive_role(d);
 
1203
   if (role == 3 || role == 5)
 
1204
 
 
1205
     /* >>> ??? return always 0 ? */
 
1206
     return(-1*!!(flag&(1<<15)));
 
1207
 
1081
1208
   ret = burn_get_read_capacity(d, &capacity, 0);
1082
 
   if (ret <= 0 && role == 2) {
 
1209
   if (ret <= 0 && (role == 2 || role == 4)) {
1083
1210
     /* Might be a block device on a system where libburn cannot determine its
1084
1211
        size.  Try to read anyway. */
1085
1212
     capacity = 0x7ffffff0;
1086
1213
     ret = 1;
1087
1214
   }
1088
 
   memset(buffer, 0, 64 * 1024);
1089
1215
   to_read= (off_t) capacity * ((off_t) 2048);
1090
1216
   if(ret > 0 && to_read >= (off_t) (36 * 1024)) {
1091
1217
     if(to_read >= (off_t) (64 * 1024))
1171
1297
 
1172
1298
 ret= burn_get_read_capacity(d, &readable_blocks, 0);
1173
1299
 if(ret <= 0) {
1174
 
 
1175
1300
   role = burn_drive_get_drive_role(d);
1176
 
   if (role == 2)
 
1301
   if (role == 2 || role == 4)
1177
1302
     /* Might be a block device on a system where libburn cannot determine its
1178
1303
        size.  Try to read anyway. */
1179
1304
     readable_blocks= 0x7ffffff0; /* try to read anyway */
1180
1305
   else
1181
1306
     readable_blocks= -1;
1182
1307
 }
 
1308
 if(o->fabricated_disc_status == BURN_DISC_BLANK)
 
1309
   {ret= 0; goto failure;}
1183
1310
 
1184
1311
 start_time= last_pacifier= time(NULL);
1185
1312
 lba= 0;
1187
1314
   ret= isoburn_read_iso_head(d, lba, &image_size, NULL, 0);
1188
1315
   if(ret<=0)
1189
1316
     {ret= 0; goto failure;}
1190
 
   lba= Libisoburn_overwriteable_starT;
 
1317
   lba= o->target_iso_head_size / 2048;
1191
1318
   with_enclosure= 1;
1192
1319
   if((flag & 16) && o->emulation_mode == 1) {
1193
1320
     ret= 1;
1214
1341
     /* growisofs aligns to 16 rather than 32. Overwriteable TOC emulation
1215
1342
        relies on not accidentially seeing inter-session trash data.
1216
1343
        But one can safely access 16 blocks earlier because a xorriso header
1217
 
        would have overwritten with the unused 16 blocks at its start.
 
1344
        would have been overwritten with the unused 16 blocks at its start.
1218
1345
        If libisoburn alignment would increase, then this would not be
1219
1346
        possible any more.
1220
1347
     */
1652
1779
 static int max_mode_names= 4;
1653
1780
 regex_t re;
1654
1781
 regmatch_t match[1];
 
1782
 enum burn_disc_status s;
1655
1783
 
1656
1784
 ret= isoburn_find_emulator(&o, d, 0);
1657
1785
 if(ret<0)
1712
1840
 
1713
1841
 } else if(adr_mode==3) {
1714
1842
   o->fabricated_msc1= adr_num;
 
1843
   s= isoburn_disc_get_status(d);
 
1844
   if(o->fabricated_msc1 > 0 && s != BURN_DISC_FULL
 
1845
      && s != BURN_DISC_APPENDABLE) {
 
1846
     isoburn_msgs_submit(o, 0x00060000,
 
1847
                         "Non-zero load offset given with blank input media",
 
1848
                         0, "FAILURE", 0);
 
1849
     ret= 0; goto ex;
 
1850
   }
1715
1851
   if((flag & 1) && o->fabricated_msc1 >= 16) {
1716
1852
     /* adr_num is possibly 16 blocks too high */
1717
1853
     ret= isoburn_read_iso_head(d, o->fabricated_msc1, &size,volid, 1|(1<<14));