7
7
/* libburn wrappers for libisoburn
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.
14
#include "../config.h"
13
17
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo
14
18
#define Hardcoded_cd_rW 1
15
19
#define Hardcoded_cd_rw_c1 12999
31
34
#ifndef Xorriso_standalonE
33
36
#include <libburn/libburn.h>
35
37
#include <libisofs/libisofs.h>
38
#ifdef Xorriso_with_libjtE
39
#include <libjte/libjte.h>
37
42
#else /* ! Xorriso_standalonE */
39
44
#include "../libisofs/libisofs.h"
40
45
#include "../libburn/libburn.h"
46
#ifdef Xorriso_with_libjtE
47
#include "../libjte/libjte.h"
42
50
#endif /* Xorriso_standalonE */
66
74
int isoburn_initialize(char msg[1024], int flag)
68
int major, minor, micro, bad_match= 0;
71
/* First two ugly compile time checks for header version compatibility.
76
int major, minor, micro, bad_match= 0, no_iso_init= 0;
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.
145
153
LIBBURN_MISCONFIGURATION_ = 0;
157
#ifdef Xorriso_with_libjtE
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
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
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
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
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;
181
#endif /* Xorriso_with_libjtE */
148
184
/* End of ugly compile time tests (scroll up for explanation) */
154
sprintf(msg+strlen(msg), "Cannot initialize libisofs\n");
189
#ifdef Xorriso_with_libjtE
191
libjte__version(&major, &minor, µ);
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, ");
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);
202
no_iso_init= 1; /* iso_init() will fail anyway */
205
#endif /* Xorriso_with_libjtE */
209
sprintf(msg+strlen(msg), "Cannot initialize libisofs\n");
157
213
iso_lib_version(&major, &minor, µ);
158
214
sprintf(msg+strlen(msg), "libisofs-%d.%d.%d ", major, minor, micro);
184
240
sprintf(msg+strlen(msg), "Cannot initialize libburn\n");
187
244
burn_version(&major, &minor, µ);
188
245
sprintf(msg+strlen(msg), "libburn-%d.%d.%d ", major, minor, micro);
189
246
if(major > burn_header_version_major
289
/* API @since 0.6.4 */
290
int isoburn_libjte_req(int *major, int *minor, int *micro)
292
#ifdef Xorriso_with_libjtE
293
*major= LIBJTE_VERSION_MAJOR;
294
*minor= LIBJTE_VERSION_MINOR;
295
*micro= LIBJTE_VERSION_MICRO;
297
*major= *minor= *micro= 0;
298
#endif /* ! Xorriso_with_libjtE */
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,
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;
387
role= burn_drive_get_drive_role(d);
388
random_access= caps->start_adr || role == 4;
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);
320
394
(*o)->min_start_byte= 0;
322
396
(*o)->zero_nwa= 0;
398
if((flag & 1) && role != 4 && role != 5) {
325
399
(*o)->nwa= (*o)->zero_nwa;
326
400
(*o)->fabricated_disc_status= BURN_DISC_BLANK;
370
445
if((flag & 16) || track_count >= 2) {
371
446
ret= 0; /* toc emulation off, or not overwriteable */
448
ret= isoburn_start_emulation(*o, 1);
450
(*o)->emulation_mode= -1;
453
emulation_started= 1;
373
454
ret= isoburn_emulate_toc(d, 1);
578
666
burn_drive_cancel(drive);
669
role = burn_drive_get_drive_role(drive);
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);
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)
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
813
int isoburn_set_truncate(struct burn_drive *drive, int flag)
818
ret= isoburn_find_emulator(&o, drive, 0);
822
if(!(flag & (2 | 4)))
823
isoburn_msgs_submit(o, 0x00060000,
824
"Drive type or role is inappropriate for truncation", 0, "WARNING", 0);
827
if(o->truncate || !(flag & 4))
828
o->truncate= flag & 1;
714
833
void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
791
909
if(o->truncate) {
792
910
ret= burn_drive_get_drive_role(drive);
911
if(ret == 2 || ret == 5) {
794
912
ret= burn_drive_d_get_adr(drive, adr);
796
914
ret= lstat(adr, &stbuf);
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) */
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;
1075
1195
info_mode= flag&255;
1076
1196
*image_blocks= 0;
1077
1197
if(flag&(1<<13)) {
1078
1198
memcpy(buffer, info, 64*1024);
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)
1205
/* >>> ??? return always 0 ? */
1206
return(-1*!!(flag&(1<<15)));
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;
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))
1172
1298
ret= burn_get_read_capacity(d, &readable_blocks, 0);
1175
1300
role = burn_drive_get_drive_role(d);
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 */
1181
1306
readable_blocks= -1;
1308
if(o->fabricated_disc_status == BURN_DISC_BLANK)
1309
{ret= 0; goto failure;}
1184
1311
start_time= last_pacifier= time(NULL);
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.
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",
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));