Removed branch

This commit is contained in:
Mario Danic
2008-03-12 09:28:21 +00:00
parent b636d4ae16
commit a1740048c5
39 changed files with 0 additions and 28704 deletions

View File

@ -1,892 +0,0 @@
/*
cc -g -c \
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE \
burn_wrap.c
*/
/* libburn wrappers for libisoburn
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
*/
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo
#define Hardcoded_cd_rW 1
#define Hardcoded_cd_rw_c1 12999
#define Hardcoded_cd_rw_nwA 152660
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef Xorriso_standalonE
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#else /* ! Xorriso_standalonE */
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#endif /* Xorriso_standalonE */
#include "libisoburn.h"
#include "isoburn.h"
/* The global list of isoburn objects. Usually there is only one. */
extern struct isoburn *isoburn_list_start; /* in isoburn.c */
int isoburn_initialize(char msg[1024], int flag)
{
int major, minor, micro, bad_match= 0;
/* First two ugly compile time checks for header version compatibility.
If everthing matches, then they produce no C code. In case of mismatch,
intentionally faulty C code will be inserted.
*/
#ifdef iso_lib_header_version_major
/* The minimum requirement of libisoburn towards the libisofs header
at compile time is defined in libisoburn/libisoburn.h :
isoburn_libisofs_req_major
isoburn_libisofs_req_minor
isoburn_libisofs_req_micro
It gets compared against the version macros in libisofs/libisofs.h :
iso_lib_header_version_major
iso_lib_header_version_minor
iso_lib_header_version_micro
If the header is too old then the following code shall cause failure of
cdrskin compilation rather than to allow production of a program with
unpredictable bugs or memory corruption.
The compiler messages supposed to appear in this case are:
error: 'LIBISOFS_MISCONFIGURATION' undeclared (first use in this function)
error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisofs_dot_h_TOO_OLD__SEE_libisoburn_dot_h_and_burn_wrap_dot_h' undeclared (first use in this function)
error: 'LIBISOFS_MISCONFIGURATION_' undeclared (first use in this function)
*/
/* The indendation is an advise of man gcc to help old compilers ignoring */
#if isoburn_libisofs_req_major > iso_lib_header_version_major
#define Isoburn_libisofs_dot_h_too_olD 1
#endif
#if isoburn_libisofs_req_major == iso_lib_header_version_major && isoburn_libisofs_req_minor > iso_lib_header_version_minor
#define Isoburn_libisofs_dot_h_too_olD 1
#endif
#if isoburn_libisofs_req_minor == iso_lib_header_version_minor && isoburn_libisofs_req_micro > iso_lib_header_version_micro
#define Isoburn_libisofs_dot_h_too_olD 1
#endif
#ifdef Isoburn_libisofs_dot_h_too_olD
LIBISOFS_MISCONFIGURATION = 0;
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisofs_dot_h_TOO_OLD__SEE_libisoburn_dot_h_and_burn_wrap_dot_h = 0;
LIBISOFS_MISCONFIGURATION_ = 0;
#endif
#endif /* iso_lib_header_version_major */
/* The minimum requirement of libisoburn towards the libburn header
at compile time is defined in libisoburn/libisoburn.h :
isoburn_libburn_req_major
isoburn_libburn_req_minor
isoburn_libburn_req_micro
It gets compared against the version macros in libburn/libburn.h :
burn_header_version_major
burn_header_version_minor
burn_header_version_micro
If the header is too old then the following code shall cause failure of
cdrskin compilation rather than to allow production of a program with
unpredictable bugs or memory corruption.
The compiler messages supposed to appear in this case are:
error: 'LIBBURN_MISCONFIGURATION' undeclared (first use in this function)
error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libburn_dot_h_TOO_OLD__SEE_libisoburn_dot_h_and_burn_wrap_dot_h' undeclared (first use in this function)
error: 'LIBBURN_MISCONFIGURATION_' undeclared (first use in this function)
*/
/* The indendation is an advise of man gcc to help old compilers ignoring */
#if isoburn_libburn_req_major > burn_header_version_major
#define Isoburn_libburn_dot_h_too_olD 1
#endif
#if isoburn_libburn_req_major == burn_header_version_major && isoburn_libburn_req_minor > burn_header_version_minor
#define Isoburn_libburn_dot_h_too_olD 1
#endif
#if isoburn_libburn_req_minor == burn_header_version_minor && isoburn_libburn_req_micro > burn_header_version_micro
#define Isoburn_libburn_dot_h_too_olD 1
#endif
#ifdef Isoburn_libburn_dot_h_too_olD
LIBBURN_MISCONFIGURATION = 0;
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libburn_dot_h_TOO_OLD__SEE_libisoburn_dot_h_and_burn_wrap_dot_h = 0;
LIBBURN_MISCONFIGURATION_ = 0;
#endif
/* End of ugly compile time tests (scroll up for explanation) */
msg[0]= 0;
if(iso_init()<0) {
sprintf(msg+strlen(msg), "Cannot initialize libisofs\n");
return(0);
}
iso_lib_version(&major, &minor, &micro);
sprintf(msg+strlen(msg), "libisofs-%d.%d.%d ", major, minor, micro);
#ifdef iso_lib_header_version_major
if(iso_lib_is_compatible(iso_lib_header_version_major,
iso_lib_header_version_minor,
iso_lib_header_version_micro)) {
sprintf(msg+strlen(msg), "ok, ");
} else {
sprintf(msg+strlen(msg),"- TOO OLD -, need at least libisofs-%d.%d.%d ,\n",
iso_lib_header_version_major, iso_lib_header_version_minor,
iso_lib_header_version_micro);
bad_match= 1;
}
#else
if(iso_lib_is_compatible(isoburn_libisofs_req_major,
isoburn_libisofs_req_minor,
isoburn_libisofs_req_micro)) {
sprintf(msg+strlen(msg), "suspicious, ");
} else {
sprintf(msg+strlen(msg),"- TOO OLD -, need at least libisofs-%d.%d.%d ,\n",
isoburn_libisofs_req_major, isoburn_libisofs_req_minor,
isoburn_libisofs_req_micro);
bad_match= 1;
}
#endif /* ! iso_lib_header_version_major */
if(!burn_initialize()) {
sprintf(msg+strlen(msg), "Cannot initialize libburn\n");
return(0);
}
burn_version(&major, &minor, &micro);
sprintf(msg+strlen(msg), "libburn-%d.%d.%d ", major, minor, micro);
if(major > burn_header_version_major
|| (major == burn_header_version_major
&& (minor > burn_header_version_minor
|| (minor == burn_header_version_minor
&& micro >= burn_header_version_micro)))) {
sprintf(msg+strlen(msg), "ok, ");
} else {
sprintf(msg+strlen(msg), "- TOO OLD -, need at least libburn-%d.%d.%d ,\n",
burn_header_version_major, burn_header_version_minor,
burn_header_version_micro);
bad_match= 1;
}
isoburn_version(&major, &minor, &micro);
sprintf(msg+strlen(msg), "for libisoburn-%d.%d.%d", major, minor, micro);
if(bad_match)
return(0);
isoburn_destroy_all(&isoburn_list_start, 0); /* isoburn_list_start= NULL */
return(1);
}
/* API @since 0.1.0 */
int isoburn_libisofs_req(int *major, int *minor, int *micro)
{
*major= iso_lib_header_version_major;
*minor= iso_lib_header_version_minor;
*micro= iso_lib_header_version_micro;
return(1);
}
/* API @since 0.1.0 */
int isoburn_libburn_req(int *major, int *minor, int *micro)
{
*major= burn_header_version_major;
*minor= burn_header_version_minor;
*micro= burn_header_version_micro;
return(1);
}
/** Examine the media and sets appropriate emulation if needed.
@param flag bit0= pretent blank on overwriteable media
*/
static int isoburn_welcome_media(struct isoburn **o, struct burn_drive *d,
int flag)
{
int ret, lba, nwa;
struct burn_multi_caps *caps= NULL;
ret= burn_disc_get_multi_caps(d, BURN_WRITE_NONE, &caps, 0);
if(ret<0) /* == 0 is read-only media, but it is too early to reject it here */
goto ex;
ret= isoburn_new(o, 0);
if(ret<=0)
goto ex;
(*o)->drive= d;
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
caps->start_adr= 0;
(*o)->fabricated_disc_status= BURN_DISC_APPENDABLE;
#endif
if(caps->start_adr) { /* set emulation to overwriteable */
(*o)->emulation_mode= 1;
if(flag&1) {
(*o)->nwa= 0;
(*o)->fabricated_disc_status= BURN_DISC_BLANK;
} else {
ret= isoburn_start_emulation(*o, 0);
if(ret<=0) {
(*o)->emulation_mode= -1;
goto ex;
}
}
} else {
/* >>> recognize unsuitable media (but allow read-only media) */;
#ifdef Hardcoded_cd_rW
(*o)->nwa= Hardcoded_cd_rw_nwA;
#else
ret= burn_disc_track_lba_nwa(d, NULL, 0, &lba, &nwa);
if(ret>0)
(*o)->nwa= nwa;
#endif
}
ret= 1;
ex:
if(caps!=NULL)
burn_disc_free_multi_caps(&caps);
return(ret);
}
/**
@param flag bit0= load
bit1= regard overwriteable media as blank
bit2= if the drive is a regular disk file: truncate it to
the write start address
*/
int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
char *adr, int flag)
{
int ret, conv_ret, drive_grabbed= 0;
char libburn_drive_adr[BURN_DRIVE_ADR_LEN];
struct isoburn *o= NULL;
char msg[BURN_MSGS_MESSAGE_LEN+4096];
conv_ret= burn_drive_convert_fs_adr(adr, libburn_drive_adr);
if(conv_ret<=0) {
sprintf(msg, "Unsuitable drive address: '%s'\n",adr);
msg[BURN_MSGS_MESSAGE_LEN-1]= 0;
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
ret= 0; goto ex;
}
ret= burn_drive_scan_and_grab(drive_infos, libburn_drive_adr, flag&1);
if(ret<=0)
goto ex;
drive_grabbed= 1;
ret= isoburn_welcome_media(&o, (*drive_infos)[0].drive, !!(flag&2));
if(ret<=0)
goto ex;
if(flag&4) {
ret= isoburn_find_emulator(&o, (*drive_infos)[0].drive, 0);
if(ret>0 && o!=NULL)
o->truncate= 1;
}
ret= 1;
ex:
if(ret<=0) {
if(drive_grabbed)
burn_drive_release((*drive_infos)[0].drive, 0);
isoburn_destroy(&o, 0);
}
return(ret);
}
int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
char *adr, int load)
{
int ret;
ret= isoburn_drive_aquire(drive_infos, adr, !!load);
return(ret);
}
int isoburn_drive_grab(struct burn_drive *drive, int load)
{
int ret;
struct isoburn *o= NULL;
ret= burn_drive_grab(drive, load);
if(ret<=0)
goto ex;
ret= isoburn_welcome_media(&o, drive, 0);
if(ret<=0)
goto ex;
ret= 1;
ex:
if(ret<=0)
isoburn_destroy(&o,0);
return(ret);
}
/** Retrieve media emulation and eventual isoburn emulator of drive.
@return -1 unsuitable media, 0 generic media, 1 emulated media.
*/
int isoburn_find_emulator(struct isoburn **pt,
struct burn_drive *drive, int flag)
{
int ret;
ret= isoburn_find_by_drive(pt, drive, 0);
if(ret<=0)
return(0);
if((*pt)->emulation_mode==-1) {
burn_msgs_submit(0x00060000,
"Unsuitable drive and media state", 0, "FAILURE", NULL);
return(-1);
}
if((*pt)->emulation_mode==0)
return(0);
return(1);
}
enum burn_disc_status isoburn_disc_get_status(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return(BURN_DISC_UNSUITABLE);
if(o!=NULL)
if(o->fabricated_disc_status!=BURN_DISC_UNREADY)
return(o->fabricated_disc_status);
if(ret==0)
return(burn_disc_get_status(drive));
/* emulated status */
if(o->emulation_mode==-1)
return(BURN_DISC_UNSUITABLE);
if(o->nwa>0)
return(BURN_DISC_APPENDABLE);
return(BURN_DISC_BLANK);
}
int isoburn_disc_erasable(struct burn_drive *d)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, d, 0);
if(ret>0)
if(o->emulation_mode==1)
return(1);
return burn_disc_erasable(d);
}
void isoburn_disc_erase(struct burn_drive *drive, int fast)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret>0) {
if(o->emulation_mode==-1) {
/* To cause a negative reply with burn_drive_wrote_well() */
burn_drive_cancel(drive);
return;
}
if(o->emulation_mode>0) {
ret= isoburn_invalidate_iso(o, 0);
if(ret<=0)
burn_drive_cancel(drive);
return;
}
}
burn_disc_erase(drive, fast);
}
off_t isoburn_disc_available_space(struct burn_drive *d,
struct burn_write_opts *opts)
{
int ret;
struct isoburn *o;
off_t avail;
ret= isoburn_find_emulator(&o, d, 0);
if(ret>0 && o!=NULL)
if(o->emulation_mode!=0)
burn_write_opts_set_start_byte(opts, ((off_t) o->nwa) * (off_t) 2048);
avail= burn_disc_available_space(d, opts);
return(avail);
}
int isoburn_disc_get_msc1(struct burn_drive *d, int *start_lba)
{
int ret;
struct isoburn *o;
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
*start_lba= Hardcoded_cd_rw_c1;
return(1);
#endif
if(isoburn_disc_get_status(d)!=BURN_DISC_APPENDABLE &&
isoburn_disc_get_status(d)!=BURN_DISC_FULL) {
burn_msgs_submit(0x00060000,
"Media contains no recognizable data", 0, "SORRY",NULL);
return(0);
}
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(0);
if(ret>0) if(o->emulation_mode>0) {
*start_lba= 0;
return(1);
}
return(burn_disc_get_msc1(d, start_lba));
}
int isoburn_disc_track_lba_nwa(struct burn_drive *d,
struct burn_write_opts *opts,
int trackno, int *lba, int *nwa)
{
int ret;
struct isoburn *o;
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
*lba= Hardcoded_cd_rw_c1;
*nwa= Hardcoded_cd_rw_nwA;
return(1);
#endif
*nwa= *lba= 0;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(0);
if(ret>0) if(o->emulation_mode>0) {
*lba= 0;
*nwa= o->nwa;
return(1);
}
if(burn_drive_get_drive_role(d) != 1)
return(1);
return(burn_disc_track_lba_nwa(d, opts, trackno, lba, nwa));
}
void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
{
int ret;
off_t nwa= 0;
struct isoburn *o;
struct burn_drive *drive;
char reasons[BURN_REASONS_LEN],msg[160+BURN_REASONS_LEN];
char adr[BURN_DRIVE_ADR_LEN];
enum burn_write_types write_type;
struct stat stbuf;
drive= burn_write_opts_get_drive(opts);
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return;
if(o!=NULL) {
o->wrote_well= -1;
if(o->emulation_mode!=0) {
burn_write_opts_set_multi(opts, 0);
if(o->emulation_mode>0 && o->nwa >= 0) {
burn_write_opts_set_start_byte(opts, ((off_t) o->nwa) * (off_t) 2048);
nwa= o->nwa;
}
}
}
write_type= burn_write_opts_auto_write_type(opts, disc, reasons, 0);
if (write_type == BURN_WRITE_NONE) {
sprintf(msg, "Failed to find a suitable write mode:\n%s", reasons);
burn_msgs_submit(0x00060000, msg, 0, "FAILURE", NULL);
if(o!=NULL)
o->wrote_well= 0;
/* To cause a negative reply with burn_drive_wrote_well() */
burn_drive_cancel(drive);
return;
}
/*
sprintf(reasons, "%d", (int) write_type);
fprintf(stderr, "isoburn_EXPERIMENTAL: write_type = %s\n",
(write_type == BURN_WRITE_SAO ? "SAO" :
(write_type == BURN_WRITE_TAO ? "TAO" : reasons)));
*/
#ifdef Hardcoded_cd_rW
/* <<< A70929 : hardcoded CD-RW with fabricated -msinfo */
fprintf(stderr, "Setting write address to LBA %d\n", Hardcoded_cd_rw_nwA);
burn_write_opts_set_start_byte(opts,
((off_t) Hardcoded_cd_rw_nwA) * (off_t) 2048);
#endif
if(o->truncate) {
ret= burn_drive_get_drive_role(drive);
if(ret==2) {
ret= burn_drive_d_get_adr(drive, adr);
if(ret>0) {
ret= lstat(adr, &stbuf);
if(ret!=-1)
if(S_ISREG(stbuf.st_mode))
truncate(adr, nwa * (off_t) 2048);
}
}
}
burn_disc_write(opts, disc);
}
void isoburn_drive_release(struct burn_drive *drive, int eject)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return;
if(o!=NULL) {
isoburn_destroy(&o, 0);
}
burn_drive_release(drive, eject);
}
void isoburn_finish(void)
{
isoburn_destroy_all(&isoburn_list_start, 0);
burn_finish();
iso_finish();
}
int isoburn_needs_emulation(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
enum burn_disc_status s;
s= isoburn_disc_get_status(drive);
if(s!=BURN_DISC_BLANK && s!=BURN_DISC_APPENDABLE)
return(-1);
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return(-1);
if(ret>0)
if(o->emulation_mode>0)
return(1);
return(0);
}
int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag)
{
int ret;
struct burn_drive *drive = o->drive;
struct burn_multi_caps *caps= NULL;
ret= burn_disc_get_multi_caps(drive, BURN_WRITE_NONE, &caps, 0);
if(ret<=0)
goto ex;
if(!caps->start_adr) {
burn_msgs_submit(0x00060000,
"Cannot set start byte address with this type of media",
0, "FAILURE", NULL);
{ret= 0; goto ex;}
}
o->min_start_byte= value;
if(value % caps->start_alignment)
value+= caps->start_alignment - (value % caps->start_alignment);
o->nwa= value/2048;
/* If suitable for alignment, round up to full 16 sector addresses */
if((o->nwa%16) && ((16*2048) % caps->start_alignment)==0 )
o->nwa+= 16 - (o->nwa%16);
ret= 1;
ex:
if(caps!=NULL)
burn_disc_free_multi_caps(&caps);
return(ret);
}
int isoburn_get_min_start_byte(struct burn_drive *d, off_t *start_byte,
int flag)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(-1);
if(ret==0)
return(0);
*start_byte= o->min_start_byte;
if(o->min_start_byte<=0)
return(0);
return(1);
}
int isoburn_drive_wrote_well(struct burn_drive *d)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(-1);
if(o!=NULL)
if(o->wrote_well>=0)
return(o->wrote_well);
ret= burn_drive_wrote_well(d);
return ret;
}
int isoburn_get_fifo_status(struct burn_drive *d, int *size, int *free_bytes,
char **status_text)
{
int ret;
struct isoburn *o;
#ifdef Libisoburn_no_fifO
size_t hsize= 0, hfree_bytes= 0;
#endif
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(-1);
#ifdef Libisoburn_no_fifO
if(o==NULL)
return(-1);
if(o->iso_source==NULL)
return(-1);
ret= iso_ring_buffer_get_status(o->iso_source, &hsize, &hfree_bytes);
if(hsize > 1024*1024*1024)
*size= 1024*1024*1024;
else
*size= hsize;
if(hfree_bytes > 1024*1024*1024)
*free_bytes= 1024*1024*1024;
else
*free_bytes= hfree_bytes;
*status_text= "";
if(ret==0)
*status_text= "standby";
else if(ret==1)
*status_text= "active";
else if(ret==2)
*status_text= "ending";
else if(ret==3)
*status_text= "failing";
else if(ret==4)
*status_text= "unused";
else if(ret==5)
*status_text= "abandoned";
else if(ret==6)
*status_text= "ended";
else if(ret==7)
*status_text= "aborted";
#else
if(o==NULL)
return(0);
if(o->fifo==NULL)
return(0);
ret= burn_fifo_inquire_status(o->fifo, size, free_bytes, status_text);
#endif /* ! Libisoburn_no_fifO */
return(ret);
}
#define Libisoburn_on_libisofs_after_0_6_2 yes
/* >>> todo: throw out the copies of libdax_msgs entrails */
/* <<< to be replaced by libburn-0.4.3 API call burn_sev_to_text().
This is a copy of libdax_msgs__sev_to_text() which is not exposed
by the API of of libburn-0.4.2 . As soon as xorriso gets based on
libburn-0.4.4 this redundancy is to be removed.
It is safe, nevertheless, because the severity codes are eternal.
*/
#define LIBDAX_MSGS_SEV_ALL 0x00000000
#define LIBDAX_MSGS_SEV_ERRFILE 0x08000000
#define LIBDAX_MSGS_SEV_DEBUG 0x10000000
#define LIBDAX_MSGS_SEV_UPDATE 0x20000000
#define LIBDAX_MSGS_SEV_NOTE 0x30000000
#define LIBDAX_MSGS_SEV_HINT 0x40000000
#define LIBDAX_MSGS_SEV_WARNING 0x50000000
#define LIBDAX_MSGS_SEV_SORRY 0x60000000
#define LIBDAX_MSGS_SEV_MISHAP 0x64000000
#define LIBDAX_MSGS_SEV_FAILURE 0x68000000
#define LIBDAX_MSGS_SEV_FATAL 0x70000000
#define LIBDAX_MSGS_SEV_ABORT 0x71000000
#define LIBDAX_MSGS_SEV_NEVER 0x7fffffff
/* @param flag bit0= -reserved-
bit1= this is a libburn severity
*/
int isoburn__sev_to_text(int severity, char **severity_name,
int flag)
{
#ifdef Libisoburn_on_libisofs_after_0_6_2
int ret;
#else
#ifdef Libisoburn_on__libburn_after_0_4_2
int ret;
#endif
#endif
#ifdef Libisoburn_on_libisofs_after_0_6_2
ret= iso_sev_to_text(severity, severity_name);
if(ret>0)
return(ret);
#endif /* Libisoburn_on_libisofs_after_0_6_2 */
#ifdef Libisoburn_on__libburn_after_0_4_2
ret= burn_sev_to_text(severity, severity_name, 0);
if(ret>0)
return(ret);
#endif
if(flag&1) {
*severity_name= "NEVER\nABORT\nFATAL\nFAILURE\nSORRY\nWARNING\nHINT\nNOTE\nUPDATE\nDEBUG\nERRFILE\nALL";
return(1);
}
*severity_name= "";
if(severity>=LIBDAX_MSGS_SEV_NEVER)
*severity_name= "NEVER";
else if(severity>=LIBDAX_MSGS_SEV_ABORT)
*severity_name= "ABORT";
else if(severity>=LIBDAX_MSGS_SEV_FATAL)
*severity_name= "FATAL";
else if(severity>=LIBDAX_MSGS_SEV_FAILURE)
*severity_name= "FAILURE";
else if(severity>=LIBDAX_MSGS_SEV_MISHAP)
*severity_name= "MISHAP";
else if(severity>=LIBDAX_MSGS_SEV_SORRY)
*severity_name= "SORRY";
else if(severity>=LIBDAX_MSGS_SEV_WARNING)
*severity_name= "WARNING";
else if(severity>=LIBDAX_MSGS_SEV_HINT)
*severity_name= "HINT";
else if(severity>=LIBDAX_MSGS_SEV_NOTE)
*severity_name= "NOTE";
else if(severity>=LIBDAX_MSGS_SEV_UPDATE)
*severity_name= "UPDATE";
else if(severity>=LIBDAX_MSGS_SEV_DEBUG)
*severity_name= "DEBUG";
else if(severity>=LIBDAX_MSGS_SEV_ERRFILE)
*severity_name= "ERRFILE";
else if(severity>=LIBDAX_MSGS_SEV_ALL)
*severity_name= "ALL";
else {
*severity_name= "";
return(0);
}
return(1);
}
int isoburn__text_to_sev(char *severity_name, int *severity_number, int flag)
{
int ret= 1;
#ifdef Libisoburn_on_libisofs_after_0_6_2
ret= iso_text_to_sev(severity_name, severity_number);
if(ret>0)
return(ret);
#endif /* Libisoburn_on_libisofs_after_0_6_2 */
#ifndef Libisoburn_on__libburn_after_0_4_2
if(severity_name[0]==0)
*severity_number= 0;
else if(strcmp(severity_name, "MISHAP")==0)
*severity_number= LIBDAX_MSGS_SEV_MISHAP;
else if(strcmp(severity_name, "ERRFILE")==0)
*severity_number= LIBDAX_MSGS_SEV_ERRFILE;
else
#endif /* ! Libisoburn_on__libburn_after_0_4_2 */
ret= burn_text_to_sev(severity_name, severity_number, 0);
return(ret);
}
int isoburn_report_iso_error(int iso_error_code, char msg_text[], int os_errno,
char min_severity[], int flag)
{
int error_code, iso_sev, min_sev, ret;
char *sev_text_pt, *msg_text_pt= NULL;
error_code= iso_error_get_code(iso_error_code);
if(error_code < 0x00030000 || error_code >= 0x00040000)
error_code= (error_code & 0xffff) | 0x00050000;
if(iso_error_code<0)
msg_text_pt= (char *) iso_error_to_msg(iso_error_code);
if(msg_text_pt==NULL)
msg_text_pt= msg_text;
iso_sev= iso_error_get_severity(iso_error_code);
sev_text_pt= min_severity;
#ifdef Libisoburn_on_libisofs_after_0_6_2
isoburn__text_to_sev(min_severity, &min_sev, 0);
if(min_sev < iso_sev)
isoburn__sev_to_text(iso_sev, &sev_text_pt, 0);
ret= iso_msgs_submit(error_code, msg_text_pt, os_errno, sev_text_pt, 0);
#else
burn_text_to_sev(min_severity, &min_sev, 0);
/* <<< Tunnel MISHAP through libburn which knows no MISHAP
with libburn-0.4.4 this is not necessary */
if(iso_sev==LIBDAX_MSGS_SEV_MISHAP) {
iso_sev= LIBDAX_MSGS_SEV_SORRY;
error_code= 0x0005ff73;
} else if(iso_sev==LIBDAX_MSGS_SEV_ERRFILE) { /* same with ERRFILE */
iso_sev= LIBDAX_MSGS_SEV_DEBUG;
error_code= 0x00051001;
}
if(min_sev < iso_sev)
isoburn__sev_to_text(iso_sev, &sev_text_pt, 0);
ret= burn_msgs_submit(error_code, msg_text_pt, os_errno, sev_text_pt, NULL);
#endif /* ! Libisoburn_on_libisofs_after_0_6_2 */
return(ret);
}

View File

@ -1,190 +0,0 @@
/*
data source for libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifndef Xorriso_standalonE
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#else /* ! Xorriso_standalonE */
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#endif /* Xorriso_standalonE */
#include "isoburn.h"
/* Cached reading of image tree data */
/* Current implementation : single tile 128 kB */
/* powers of 2 only ! */
#define Libisoburn_cache_blockS 64
struct isoburn_cached_drive {
struct burn_drive *drive;
char cache_data[Libisoburn_cache_blockS * 2048];
uint32_t cache_lba;
uint32_t last_error_lba;
uint32_t last_aligned_error_lba;
int cache_hits;
};
/* Debugging only: This reports cache loads on stderr.
#define Libisoburn_read_cache_reporT 1
*/
#define Libisoburn_use_read_cachE
#ifdef Libisoburn_use_read_cachE
int
ds_read_block(IsoDataSource *src, uint32_t lba, uint8_t *buffer)
{
int ret;
struct burn_drive *d;
off_t count;
uint32_t aligned_lba;
char msg[80];
struct isoburn_cached_drive *icd;
if(src == NULL || buffer == NULL)
return -1;
icd = (struct isoburn_cached_drive *) src->data;
d = (struct burn_drive*) icd->drive;
aligned_lba= lba & ~(Libisoburn_cache_blockS - 1);
if(aligned_lba == icd->cache_lba && icd->cache_lba != 0xffffffff) {
(icd->cache_hits)++;
memcpy(buffer, icd->cache_data + (lba - aligned_lba) * 2048, 2048);
count= 2048;
return 1;
}
icd->cache_lba= 0xffffffff; /* invalidate cache */
if(icd->last_aligned_error_lba == aligned_lba) {
ret = 0;
} else {
ret = burn_read_data(d, (off_t) aligned_lba * (off_t) 2048,
(char *) icd->cache_data,
Libisoburn_cache_blockS * 2048, &count, 0);
}
if (ret <= 0 ) {
icd->last_aligned_error_lba = aligned_lba;
/* Read-ahead failure ? Try to read 2048 directly. */
if(icd->last_error_lba == lba)
ret = 0;
else
ret = burn_read_data(d, (off_t) lba * (off_t) 2048, (char *) buffer,
2048, &count, 0);
if (ret > 0)
return 1;
icd->last_error_lba = lba;
sprintf(msg, "ds_read_block(%lu) returns -1", (unsigned long) lba);
burn_msgs_submit(0x00060000, msg, 0, "DEBUG", NULL);
return -1;
}
#ifdef Libisoburn_read_cache_reporT
fprintf(stderr, "After %3d hits, new load from %8x , count= %d\n",
icd->cache_hits, aligned_lba, (int) count);
#endif
icd->cache_lba= aligned_lba;
icd->cache_hits= 1;
memcpy(buffer, icd->cache_data + (lba - aligned_lba) * 2048, 2048);
count= 2048;
return 1;
}
#else /* Libisoburn_use_read_cachE */
static int
ds_read_block(IsoDataSource *src, uint32_t lba, uint8_t *buffer)
{
int ret;
struct burn_drive *d;
off_t count;
if(src == NULL || buffer == NULL)
return -1;
d = (struct burn_drive*) ((struct isoburn_cached_drive *) src->data)->drive;
ret = burn_read_data(d, (off_t) lba * (off_t) 2048, (char *) buffer,
2048, &count, 0);
if (ret <= 0 )
return -1;
return 1;
}
#endif /* ! Libisoburn_use_read_cachE */
static int
ds_open(IsoDataSource *src)
{
/* nothing to do, device is always grabbed */
return 1;
}
static int
ds_close(IsoDataSource *src)
{
/* nothing to do, device is always grabbed */
return 1;
}
static void
ds_free_data(IsoDataSource *src)
{
/* nothing to do */;
if(src->data != NULL)
free(src->data);
src->data= NULL;
}
IsoDataSource *
isoburn_data_source_new(struct burn_drive *d)
{
IsoDataSource *ret;
struct isoburn_cached_drive *icd= NULL;
if (d==NULL)
return NULL;
ret = malloc(sizeof(IsoDataSource));
icd = calloc(1,sizeof(struct isoburn_cached_drive));
if (ret == NULL || icd == NULL)
return NULL;
ret->refcount = 1;
ret->read_block = ds_read_block;
ret->open = ds_open;
ret->close = ds_close;
ret->free_data = ds_free_data;
ret->data = icd;
icd->drive = d;
icd->cache_lba = 0xffffffff;
icd->cache_hits = 0;
icd->last_error_lba = 0xffffffff;
icd->last_aligned_error_lba = 0xffffffff;
return ret;
}

View File

@ -1,839 +0,0 @@
/*
cc -g -c isoburn.c
*/
/*
Class core of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
/* ( derived from stub generated by CgeN on Sat, 01 Sep 2007 12:04:36 GMT ) */
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#ifndef Xorriso_standalonE
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#else /* ! Xorriso_standalonE */
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#endif /* Xorriso_standalonE */
#include "libisoburn.h"
#include "isoburn.h"
/* No more: version numbers out of configure.ac
major.minor.micro now comes from libisoburn.h
#include "../version.h"
*/
/* -------------------------- isoburn ----------------------- */
/* The global list of isoburn objects. Usually there is only one.
>>> we are not ready for multiple control threads yet. See >>> mutex .
Multiple burns under one control thread should work.
*/
struct isoburn *isoburn_list_start= NULL;
int isoburn_new(struct isoburn **objpt, int flag)
{
struct isoburn *o;
int i, ret;
*objpt= o= (struct isoburn *) malloc(sizeof(struct isoburn));
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Cannot allocate memory for isoburn control object",
0, "FATAL", NULL);
return(-1);
}
o->drive= NULL;
o->emulation_mode= 0;
o->min_start_byte= 0;
o->nwa= 0;
o->truncate= 0;
#ifdef Libisoburn_no_fifO
o->iso_source= NULL;
#else
o->fifo= NULL;
#endif
o->wrote_well= -1;
o->fabricated_disc_status= BURN_DISC_UNREADY;
for(i=0;i<65536;i++)
o->target_iso_head[i]= 0;
o->image= NULL;
o->read_pacifier= NULL;
o->read_pacifier_handle= NULL;
o->prev= NULL;
o->next= NULL;
ret= iso_image_new("ISOIMAGE", &o->image);
if(ret<0) {
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
goto failed;
}
isoburn_link(o, isoburn_list_start, 1);
return(1);
failed:;
isoburn_destroy(objpt, 0);
return(-1);
}
int isoburn_destroy(struct isoburn **objpt, int flag)
{
struct isoburn *o;
o= *objpt;
if(o==NULL)
return(0);
/* >>> mutex */
if(o==isoburn_list_start)
isoburn_list_start= o->next;
if(o->prev!=NULL)
o->prev->next= o->next;
if(o->next!=NULL)
o->next->prev= o->prev;
/* >>> end mutex */
if(o->image!=NULL)
iso_image_unref(o->image);
#ifdef Libisoburn_no_fifO
if(o->iso_source!=NULL)
burn_source_free(o->iso_source);
#else
if(o->fifo!=NULL)
burn_source_free(o->fifo);
#endif /* ! Libisoburn_no_fifO */
free((char *) o);
*objpt= NULL;
return(1);
}
int isoburn_destroy_all(struct isoburn **objpt, int flag)
{
struct isoburn *o,*n;
o= *objpt;
if(o==NULL)
return(0);
for(;o->prev!=NULL;o= o->prev);
for(;o!=NULL;o= n) {
n= o->next;
isoburn_destroy(&o,0);
}
*objpt= NULL;
return(1);
}
int isoburn_get_target_image(struct isoburn *o, IsoImage **pt, int flag)
{
*pt= o->image;
return(1);
}
int isoburn_get_prev(struct isoburn *o, struct isoburn **pt, int flag)
{
*pt= o->prev;
return(1);
}
int isoburn_get_next(struct isoburn *o, struct isoburn **pt, int flag)
{
*pt= o->next;
return(1);
}
int isoburn_link(struct isoburn *o, struct isoburn *link, int flag)
/*
bit0= insert as link->prev rather than as link->next
*/
{
/* >>> mutex */
if(isoburn_list_start==NULL ||
(isoburn_list_start==link && (flag&1)))
isoburn_list_start= o;
if(o->prev!=NULL)
o->prev->next= o->next;
if(o->next!=NULL)
o->next->prev= o->prev;
o->prev= o->next= NULL;
if(link==NULL)
return(1);
if(flag&1) {
o->next= link;
o->prev= link->prev;
if(o->prev!=NULL)
o->prev->next= o;
link->prev= o;
} else {
o->prev= link;
o->next= link->next;
if(o->next!=NULL)
o->next->prev= o;
link->next= o;
}
/* >>> end mutex */
return(1);
}
int isoburn_count(struct isoburn *o, int flag)
/* flag: bit1= count from start of list */
{
int counter= 0;
if(flag&2)
for(;o->prev!=NULL;o= o->prev);
for(;o!=NULL;o= o->next)
counter++;
return(counter);
}
int isoburn_by_idx(struct isoburn *o, int idx, struct isoburn **pt, int flag)
/* flag: bit0= fetch first (idx<0) or last (idx>0) item in list
bit1= address from start of list */
{
int i,abs_idx;
struct isoburn *npt;
if(flag&2)
for(;o->prev!=NULL;o= o->prev);
abs_idx= (idx>0?idx:-idx);
*pt= o;
for(i= 0;(i<abs_idx || (flag&1)) && *pt!=NULL;i++) {
if(idx>0)
npt= o->next;
else
npt= o->prev;
if(npt==NULL && (flag&1))
break;
*pt= npt;
}
return(*pt!=NULL);
}
int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag)
{
struct isoburn *o;
*pt= NULL;
for(o= isoburn_list_start;o!=NULL;o= o->next)
if(o->drive==d) {
*pt= o;
return(1);
}
return(0);
}
static
int isoburn_prepare_disc_aux(struct burn_drive *d, struct burn_disc **disc,
struct isoburn_imgen_opts *opts, int new_img)
{
struct burn_source *wsrc;
struct burn_session *session;
struct burn_track *track;
struct isoburn *o;
IsoWriteOpts *wopts= NULL;
enum burn_disc_status state;
int ret, fifo_chunks;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0 || o==NULL)
{ret= -1; goto ex;}
o->wrote_well= 0; /* early end will be registered as failure */
state = isoburn_disc_get_status(d);
if (state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE
&& (state != BURN_DISC_FULL || ! new_img)) {
/* unsuitable status */
burn_msgs_submit(0x00060000, "Unsuitable media state", 0, "FAILURE", NULL);
{ret= -2; goto ex;}
}
fifo_chunks= 32;
if(opts->fifo_size >= 64*1024 && opts->fifo_size <= 1024.0 * 1024.0 * 1024.0){
fifo_chunks= opts->fifo_size/2048;
if(fifo_chunks*2048 < opts->fifo_size)
fifo_chunks++;
}
ret = iso_write_opts_new(&wopts, 0);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create iso_write_opts", 0, "FATAL",0);
goto ex;
}
iso_write_opts_set_iso_level(wopts, opts->level);
iso_write_opts_set_rockridge(wopts, opts->rockridge);
iso_write_opts_set_joliet(wopts, opts->joliet);
iso_write_opts_set_iso1999(wopts, opts->iso1999);
iso_write_opts_set_omit_version_numbers(wopts, opts->omit_version_numbers);
iso_write_opts_set_allow_deep_paths(wopts, opts->allow_deep_paths);
iso_write_opts_set_allow_longer_paths(wopts, opts->allow_longer_paths);
iso_write_opts_set_max_37_char_filenames(wopts, opts->max_37_char_filenames);
iso_write_opts_set_no_force_dots(wopts, opts->no_force_dots);
iso_write_opts_set_allow_lowercase(wopts, opts->allow_lowercase);
iso_write_opts_set_allow_full_ascii(wopts, opts->allow_full_ascii);
iso_write_opts_set_relaxed_vol_atts(wopts, 1);
iso_write_opts_set_joliet_longer_paths(wopts, opts->joliet_longer_paths);
iso_write_opts_set_sort_files(wopts, opts->sort_files);
iso_write_opts_set_replace_mode(wopts, opts->replace_dir_mode,
opts->replace_file_mode, opts->replace_uid, opts->replace_gid);
iso_write_opts_set_default_dir_mode(wopts, opts->dir_mode);
iso_write_opts_set_default_file_mode(wopts, opts->file_mode);
iso_write_opts_set_default_uid(wopts, opts->uid);
iso_write_opts_set_default_gid(wopts, opts->gid);
iso_write_opts_set_output_charset(wopts, opts->output_charset);
#ifdef Libisoburn_no_fifO
iso_write_opts_set_fifo_size(wopts, fifo_chunks);
#endif /* Libisoburn_no_fifO */
if (new_img) {
iso_write_opts_set_ms_block(wopts, 0);
iso_write_opts_set_appendable(wopts, 0);
iso_write_opts_set_overwrite_buf(wopts, NULL);
} else {
int lba, nwa;
ret = isoburn_disc_track_lba_nwa(d, NULL, 0, &lba, &nwa);
if (ret != 1) {
burn_msgs_submit(0x00060000, "Cannot determine next writeable address", 0,
"FAILURE", NULL);
{ret= -3; goto ex;}
}
if (nwa == 0 && state == BURN_DISC_APPENDABLE) {
/* invalid nwa */
burn_msgs_submit(0x00060000, "Encountered 0 as next writeable address", 0,
"FAILURE", NULL);
{ret= -4; goto ex;}
}
iso_write_opts_set_ms_block(wopts, nwa);
iso_write_opts_set_appendable(wopts, 1);
iso_write_opts_set_overwrite_buf(wopts, o->target_iso_head);
}
ret = iso_image_create_burn_source(o->image, wopts, &wsrc);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create burn source", 0, "FAILURE", 0);
{ret= -1; goto ex;}
}
/* TODO check return values for failure. propertly clean-up on error */
#ifdef Libisoburn_no_fifO
o->iso_source= wsrc;
#else
o->fifo = burn_fifo_source_new(wsrc, 2048, fifo_chunks, 0);
burn_source_free(wsrc);
if (o->fifo == NULL) {
burn_msgs_submit(0x00060000, "Cannot attach fifo", 0, "FATAL", NULL);
{ret= -1; goto ex;}
}
#endif /* ! Libisoburn_no_fifO */
*disc = burn_disc_create();
session = burn_session_create();
burn_disc_add_session(*disc, session, BURN_POS_END);
track = burn_track_create();
#ifdef Libisoburn_no_fifO
burn_track_set_source(track, o->iso_source);
#else
burn_track_set_source(track, o->fifo);
#endif /* ! Libisoburn_no_fifO */
burn_session_add_track(session, track, BURN_POS_END);
/* give up local references */
burn_track_free(track);
burn_session_free(session);
o->wrote_well= -1; /* neutral */
ret= 1;
ex:
if(wopts!=NULL)
{iso_write_opts_free(wopts); wopts= NULL;}
return ret;
}
int isoburn_prepare_disc(struct burn_drive *d, struct burn_disc **disc,
struct isoburn_imgen_opts *opts)
{
return isoburn_prepare_disc_aux(d, disc, opts, 0);
}
int isoburn_prepare_new_image(struct burn_drive *d, struct burn_disc **disc,
struct isoburn_imgen_opts *opts,
struct burn_drive *out_drive)
{
int ret;
struct isoburn *in_o, *out_o;
ret= isoburn_prepare_disc_aux(d, disc, opts, 1);
if (ret<=0)
return ret;
#ifdef Libisoburn_no_fifO
/* Hand over source reference for optional fifo status inquiry */
if(out_drive==NULL)
return 1;
ret= isoburn_find_emulator(&out_o, out_drive, 0);
if(ret<0 || out_o==NULL)
return 1;
ret= isoburn_find_emulator(&in_o, d, 0);
if(ret<0 || in_o==NULL)
return 1; /* then without fifo status inquiry */
if(out_o->iso_source!=NULL)
burn_source_free(out_o->iso_source);
out_o->iso_source= in_o->iso_source;
in_o->iso_source= NULL;
#endif /* Libisoburn_no_fifO */
return 1;
}
/* API @since 0.1.0
@param flag bit0= this is a regular end, not an abort
give up source reference
*/
int isoburn_cancel_prepared_write(struct burn_drive *d,
struct burn_drive *output_drive, int flag)
{
int ret;
struct isoburn *o= NULL;
if(output_drive!=NULL) {
ret= isoburn_find_emulator(&o, output_drive, 0);
if(ret<0 || o==NULL)
o= NULL;
else if(o->iso_source==NULL)
o= NULL;
}
if(o==NULL) {
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(-1);
if(o==NULL)
return(0);
if(o->iso_source==NULL)
return(0);
}
if(o->iso_source->read!=NULL)
return(0);
if(o->iso_source->version<1)
return(0);
o->iso_source->cancel(o->iso_source);
burn_source_free(o->iso_source);
o->iso_source= NULL;
return(1);
}
/* API @since 0.1.0 */
int isoburn_sync_after_write(struct burn_drive *d,
struct burn_drive *output_drive, int flag)
{
return isoburn_cancel_prepared_write(d, output_drive, 1);
}
void isoburn_version(int *major, int *minor, int *micro)
{
*major= isoburn_header_version_major;
*minor= isoburn_header_version_minor;
*micro= isoburn_header_version_micro;
/* No more: values from version.h generated from version.h.in and
macro values defined in configure.ac
*major = ISOBURN_MAJOR_VERSION;
*minor = ISOBURN_MINOR_VERSION;
*micro = ISOBURN_MICRO_VERSION;
*/
}
int isoburn_is_compatible(int major, int minor, int micro, int flag)
{
int own_major, own_minor, own_micro;
isoburn_version(&own_major, &own_minor, &own_micro);
return(own_major > major ||
(own_major == major && (own_minor > minor ||
(own_minor == minor && own_micro >= micro))));
}
/* ----------------------------------------------------------------------- */
/*
Options for image reading.
*/
/* ----------------------------------------------------------------------- */
int isoburn_ropt_new(struct isoburn_read_opts **new_o, int flag)
{
struct isoburn_read_opts *o;
o= (*new_o)= calloc(1, sizeof(struct isoburn_read_opts));
if(o==NULL) {
burn_msgs_submit(0x00060000, "Cannot allocate memory for read options",
0, "FATAL", NULL);
return(-1);
}
o->norock= 0;
o->nojoliet= 0;
o->noiso1999= 1;
o->preferjoliet= 0;
o->uid= geteuid();
o->gid= getegid();
o->mode= 0444;
o->dirmode= 0555;
o->input_charset= NULL;
o->hasRR= 0;
o->hasJoliet= 0;
o->hasIso1999= 0;
o->hasElTorito= 0;
o->size= 0;
o->pretend_blank= 1;
return(1);
}
int isoburn_ropt_destroy(struct isoburn_read_opts **o, int flag)
{
if(*o==NULL)
return(0);
free(*o);
*o= NULL;
return(1);
}
int isoburn_ropt_set_extensions(struct isoburn_read_opts *o, int ext)
{
o->norock= !!(ext&1);
o->nojoliet= !!(ext&2);
o->noiso1999= !!(ext&4);
o->preferjoliet= !!(ext&8);
o->pretend_blank= !!(ext&16);
return(1);
}
int isoburn_ropt_get_extensions(struct isoburn_read_opts *o, int *ext)
{
*ext= (!!o->norock) | ((!!o->nojoliet)<<1) | ((!!o->noiso1999)<<2) |
((!!o->preferjoliet)<<3) | ((!!o->pretend_blank)<<4);
return(1);
}
int isoburn_ropt_set_default_perms(struct isoburn_read_opts *o,
uid_t uid, gid_t gid, mode_t mode)
{
mode_t dirmode;
o->uid= uid;
o->gid= gid;
o->mode= mode;
dirmode= mode;
if(dirmode & S_IRUSR)
dirmode|= S_IXUSR;
if(dirmode & S_IRGRP)
dirmode|= S_IXGRP;
if(dirmode & S_IROTH)
dirmode|= S_IXOTH;
o->dirmode= dirmode;
return(1);
}
int isoburn_ropt_get_default_perms(struct isoburn_read_opts *o,
uid_t *uid, gid_t *gid, mode_t *mode)
{
*uid= o->uid;
*gid= o->gid;
*mode= o->mode;
return(1);
}
int isoburn_ropt_set_default_dirperms(struct isoburn_read_opts *o,
mode_t mode)
{
o->dirmode= mode;
return(1);
}
int isoburn_ropt_get_default_dirperms(struct isoburn_read_opts *o,
mode_t *mode)
{
*mode= o->dirmode;
return(1);
}
int isoburn_ropt_set_input_charset(struct isoburn_read_opts *o,
char *input_charset)
{
o->input_charset= input_charset;
return(1);
}
int isoburn_igopt_get_in_charset(struct isoburn_read_opts *o,
char **input_charset)
{
*input_charset= o->input_charset;
return(1);
}
int isoburn_ropt_get_size_what(struct isoburn_read_opts *o,
uint32_t *size, int *has_what)
{
*size= o->size;
*has_what= (!!o->hasRR) | ((!!o->hasJoliet)<<1) |
((!!o->hasIso1999)<<2) | ((!!o->hasElTorito)<<3);
return(1);
}
/* ----------------------------------------------------------------------- */
/*
Options for image generation by libisofs and image transport to libburn.
*/
/* ----------------------------------------------------------------------- */
int isoburn_igopt_new(struct isoburn_imgen_opts **new_o, int flag)
{
struct isoburn_imgen_opts *o;
o= (*new_o)= calloc(1, sizeof(struct isoburn_imgen_opts));
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Cannot allocate memory for image generation options",
0, "FATAL", NULL);
return(-1);
}
o->level= 2;
o->rockridge= 1;
o->joliet= 0;
o->iso1999= 0;
o->omit_version_numbers= 0;
o->allow_deep_paths= 1;
o->allow_longer_paths= 0;
o->max_37_char_filenames= 0;
o->no_force_dots= 0;
o->allow_lowercase= 0;
o->allow_full_ascii= 0;
o->joliet_longer_paths= 0;
o->sort_files= 0;
o->replace_dir_mode= 0;
o->replace_file_mode= 0;
o->replace_uid= 0;
o->replace_gid= 0;
o->dir_mode= 0555;
o->file_mode= 0444;
o->uid= 0;
o->gid= 0;
o->output_charset= 0;
o->fifo_size= 4*1024*1024;
return(1);
}
int isoburn_igopt_destroy(struct isoburn_imgen_opts **o, int flag)
{
if(*o==NULL)
return(0);
free(*o);
*o= NULL;
return(1);
}
int isoburn_igopt_set_level(struct isoburn_imgen_opts *o, int level)
{
o->level= level;
return(1);
}
int isoburn_igopt_get_level(struct isoburn_imgen_opts *o, int *level)
{
*level= o->level;
return(1);
}
int isoburn_igopt_set_extensions(struct isoburn_imgen_opts *o, int ext)
{
o->rockridge= !!(ext&1);
o->joliet= !!(ext&2);
o->iso1999= !!(ext&4);
return(1);
}
int isoburn_igopt_get_extensions(struct isoburn_imgen_opts *o, int *ext)
{
*ext= (!!o->rockridge) | ((!!o->joliet)<<1) | ((!!o->iso1999)<<2);
return(1);
}
int isoburn_igopt_set_relaxed(struct isoburn_imgen_opts *o, int relax)
{
o->omit_version_numbers= !!(relax&1);
o->allow_deep_paths= !!(relax&2);
o->allow_longer_paths= !!(relax&4);
o->max_37_char_filenames= !!(relax&8);
o->no_force_dots= !!(relax&16);
o->allow_lowercase= !!(relax&32);
o->allow_full_ascii= !!(relax&64);
o->joliet_longer_paths= !!(relax&128);
return(1);
}
int isoburn_igopt_get_relaxed(struct isoburn_imgen_opts *o, int *relax)
{
*relax= (!!o->omit_version_numbers) | ((!!o->allow_deep_paths)<<1) |
((!!o->allow_longer_paths)<<2) | ((!!o->max_37_char_filenames)<<3) |
((!!o->no_force_dots)<<4) | ((!!o->allow_lowercase)<<5) |
((!!o->allow_full_ascii)<<6) | ((!!o->joliet_longer_paths)<<7);
return(1);
}
int isoburn_igopt_set_sort_files(struct isoburn_imgen_opts *o, int value)
{
o->sort_files= !!(value&1);
return(1);
}
int isoburn_igopt_get_sort_files(struct isoburn_imgen_opts *o, int *value)
{
*value= !!o->sort_files;
return(1);
}
int isoburn_igopt_set_over_mode(struct isoburn_imgen_opts *o,
int replace_dir_mode, int replace_file_mode,
mode_t dir_mode, mode_t file_mode)
{
o->replace_dir_mode= replace_dir_mode%3;
o->replace_file_mode= replace_file_mode%3;
o->dir_mode= dir_mode;
o->file_mode= file_mode;
return(1);
}
int isoburn_igopt_get_over_mode(struct isoburn_imgen_opts *o,
int *replace_dir_mode, int *replace_file_mode,
mode_t *dir_mode, mode_t *file_mode)
{
*replace_dir_mode= o->replace_dir_mode%3;
*replace_file_mode= o->replace_file_mode%3;
*dir_mode= o->dir_mode;
*file_mode= o->file_mode;
return(1);
}
int isoburn_igopt_set_over_ugid(struct isoburn_imgen_opts *o,
int replace_uid, int replace_gid,
uid_t uid, gid_t gid)
{
o->replace_uid= replace_uid%3;
o->replace_gid= replace_gid%3;
o->uid= uid;
o->gid= gid;
return(1);
}
int isoburn_igopt_get_over_ugid(struct isoburn_imgen_opts *o,
int *replace_uid, int *replace_gid,
uid_t *uid, gid_t *gid)
{
*replace_uid= o->replace_uid%3;
*replace_gid= o->replace_gid%3;
*uid= o->uid;
*gid= o->gid;
return(1);
}
int isoburn_igopt_set_out_charset(struct isoburn_imgen_opts *o,
char *output_charset)
{
o->output_charset= output_charset;
return(1);
}
int isoburn_igopt_get_out_charset(struct isoburn_imgen_opts *o,
char **output_charset)
{
*output_charset= o->output_charset;
return(1);
}
int isoburn_igopt_set_fifo_size(struct isoburn_imgen_opts *o, int fifo_size)
{
o->fifo_size= fifo_size;
return(1);
}
int isoburn_igopt_get_fifo_size(struct isoburn_imgen_opts *o, int *fifo_size)
{
*fifo_size= o->fifo_size;
return(1);
}

View File

@ -1,325 +0,0 @@
/*
Class struct of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
#ifndef Isoburn_includeD
#define Isoburn_includeD
/* <<< transition macro */
#define Libisoburn_no_fifO 1
/* for uint8_t */
#include <stdint.h>
struct isoburn {
/* The libburn drive to which this isoburn object is related
Most isoburn calls will use a burn_drive as object handle */
struct burn_drive *drive;
/* -1= inappropriate media state detected
0= libburn multi-session media, resp. undecided yet
1= random access media */
int emulation_mode;
/* Although rarely used, libburn can operate on several
drives simultaneously. */
struct isoburn *prev;
struct isoburn *next;
/* Start address as given by image examination (bytes, not blocks) */
off_t min_start_byte;
/* Aligned start address to be used for processing (counted in blocks) */
int nwa;
/* Truncate to .nwa an eventual regular file serving as output drive */
int truncate;
/* Eventual freely fabricated isoburn_disc_get_status().
BURN_DISC_UNREADY means that this variable is disabled
and normally emulated status is in effect.
*/
enum burn_disc_status fabricated_disc_status;
#ifndef Libisoburn_no_fifO
/* The fifo which is installed between track and libisofs burn_source
*/
struct burn_source *fifo;
#endif /* ! Libisoburn_no_fifO */
/* Indicator wether the most recent burn run worked :
-1 = undetermined, ask libburn , 0 = failure , 1 = success
To be inquired by isoburn_drive_wrote_well()
*/
int wrote_well;
/* Buffered ISO head from media (should that become part of
ecma119_read_opts ?) */
uint8_t target_iso_head[65536];
/* Libisofs image context */
IsoImage *image;
#ifdef Libisoburn_no_fifO
/* The burn source which transfers data from libisofs to libburn.
It has its own fifo.
*/
struct burn_source *iso_source;
#endif /* Libisoburn_no_fifO */
/* For iso_tree_set_report_callback() */
int (*read_pacifier)(IsoImage*, IsoFileSource*);
/* For iso_image_attach_data() */
void *read_pacifier_handle;
};
/* Creation and disposal function */
int isoburn_new(struct isoburn **objpt, int flag);
int isoburn_destroy(struct isoburn **objpt, int flag);
/* Eventual readers for public attributes */
/* ( put into separate .h file then ) */
int isoburn_get_emulation_mode(struct isoburn *o, int *pt, int flag);
int isoburn_get_target_volset(struct isoburn *o, IsoImage **pt, int flag);
/* List management */
int isoburn_get_prev(struct isoburn *o, struct isoburn **pt, int flag);
int isoburn_get_next(struct isoburn *o, struct isoburn **pt, int flag);
int isoburn_destroy_all(struct isoburn **objpt, int flag);
int isoburn_link(struct isoburn *o, struct isoburn *link, int flag);
int isoburn_count(struct isoburn *o, int flag);
int isoburn_by_idx(struct isoburn *o, int idx, struct isoburn **pt, int flag);
int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag);
/* Non API inner interfaces */
/* Submit a libisofs error to the libburn messenger. An application message
reader shall recognize the error code range and attribute it to the
libisofs message channel to which one cannot submit via API.
@param iso_error_code return value <= 0 from a libisofs API call.
@param default_msg_text is to be put out if iso_error_code leads to no
error message
@param os_errno operating system errno, submit 0 if none is known
@param min_severity minimum severity, might be be increased if libisofs
error severity surpasses min_severity.
@param flag Bitfield, submit 0 for now
*/
int isoburn_report_iso_error(int iso_error_code, char default_msg_text[],
int os_errno, char min_severity[], int flag);
/* Calls from burn_wrap.c into isofs_wrap.c */
int isoburn_start_emulation(struct isoburn *o, int flag);
int isoburn_invalidate_iso(struct isoburn *o, int flag);
/* Calls from isofs_wrap.c into burn_wrap.c */
/** Get an eventual isoburn object which is wrapped around the drive.
@param pt Eventually returns a pointer to the found object.
It is allowed to become NULL if return value is -1 or 0.
In this case, the drive is a genuine libburn drive
with no emulation activated by isoburn.
@param drive The drive to be searched for
@param flag unused yet
@return -1 unsuitable media, 0 generic media, 1 emulated media.
*/
int isoburn_find_emulator(struct isoburn **pt,
struct burn_drive *drive, int flag);
/** Set the start address for an emulated add-on session. The value will
be rounded up to the alignment necessary for the media. The aligned
value will be divided by 2048 and then put into o->nwa .
@param o The isoburn object to be programmed.
@param value The start address in bytes
@param flag unused yet
@return <=0 is failure , >0 success
*/
int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag);
/** Get a data source suitable for read from a drive using burn_read_data()
function.
@param d drive to read from. Must be grabbed.
@return the data source, NULL on error. Must be freed with libisofs
iso_data_source_unref() function. Note: this doesn't release
the drive.
*/
IsoDataSource *
isoburn_data_source_new(struct burn_drive *d);
/**
* Options for image reading.
(Comments here may be outdated. API getter/setter function descriptions
may override the descriptions here. Any difference is supposed to be a
minor correction only.)
*/
struct isoburn_read_opts {
unsigned int norock:1; /*< Do not read Rock Ridge extensions */
unsigned int nojoliet:1; /*< Do not read Joliet extensions */
unsigned int noiso1999:1; /*< Do not read ISO 9660:1999 enhanced tree */
unsigned int preferjoliet:1;
/*< When both Joliet and RR extensions are present, the RR
* tree is used. If you prefer using Joliet, set this to 1. */
uid_t uid; /**< Default uid when no RR */
gid_t gid; /**< Default uid when no RR */
mode_t mode; /**< Default mode when no RR (only permissions) */
mode_t dirmode; /**< Default mode for directories
when no RR (only permissions) */
/**
* Input charset for RR file names. NULL to use default locale charset.
*/
char *input_charset;
/* modified by the function isoburn_read_image */
unsigned int hasRR:1; /*< It will be set to 1 if RR extensions are present,
to 0 if not. */
unsigned int hasJoliet:1; /*< It will be set to 1 if Joliet extensions are
present, to 0 if not. */
/**
* It will be set to 1 if the image is an ISO 9660:1999, i.e. it has
* a version 2 Enhanced Volume Descriptor.
*/
unsigned int hasIso1999:1;
/** It will be set to 1 if El-Torito boot record is present, to 0 if not.*/
unsigned int hasElTorito:1;
uint32_t size; /**< Will be filled with the size (in 2048 byte block) of
* the image, as reported in the PVM. */
unsigned int pretend_blank:1; /* always create empty image */
};
/**
* Options for image generation by libisofs and image transport to libburn.
(Comments here may be outdated. API getter/setter function descriptions
may override the descriptions here. Any difference is supposed to be a
minor correction only.)
*/
struct isoburn_imgen_opts {
/* Options for image generation */
int level; /**< ISO level to write at. */
/** Which extensions to support. */
unsigned int rockridge :1;
unsigned int joliet :1;
unsigned int iso1999 :1;
/* relaxed constraints */
/*
* Relaxed constraints. Setting any of these to 1 break the specifications,
* but it is supposed to work on most moderns systems. Use with caution.
*/
/**
* Omit the version number (";1") at the end of the ISO-9660 identifiers.
* Version numbers are usually not used.
*/
unsigned int omit_version_numbers :1;
/**
* Allow ISO-9660 directory hierarchy to be deeper than 8 levels.
*/
unsigned int allow_deep_paths :1;
/**
* Allow path in the ISO-9660 tree to have more than 255 characters.
*/
unsigned int allow_longer_paths :1;
/**
* Allow a single file or directory hierarchy to have up to 37 characters.
* This is larger than the 31 characters allowed by ISO level 2, and the
* extra space is taken from the version number, so this also forces
* omit_version_numbers.
*/
unsigned int max_37_char_filenames :1;
/**
* ISO-9660 forces filenames to have a ".", that separates file name from
* extension. libisofs adds it if original filename doesn't has one. Set
* this to 1 to prevent this behavior
*/
unsigned int no_force_dots :1;
/**
* Allow lowercase characters in ISO-9660 filenames. By default, only
* uppercase characters, numbers and a few other characters are allowed.
*/
unsigned int allow_lowercase :1;
/**
* Allow all ASCII characters to be appear on an ISO-9660 filename. Note
* that "/" and "\0" characters are never allowed, even in RR names.
*/
unsigned int allow_full_ascii :1;
/**
* Allow paths in the Joliet tree to have more than 240 characters.
*/
unsigned int joliet_longer_paths :1;
unsigned int sort_files:1;
/**< If files should be sorted based on their weight. */
/**
* The following options set the default values for files and directory
* permissions, gid and uid. All these take one of three values: 0, 1 or 2.
* If 0, the corresponding attribute will be kept as set in the IsoNode.
* Unless you have changed it, it corresponds to the value on disc, so it
* is suitable for backup purposes. If set to 1, the corresponding attrib.
* will be changed by a default suitable value. Finally, if you set it to
* 2, the attrib. will be changed with the value specified in the options
* below. Note that for mode attributes, only the permissions are set, the
* file type remains unchanged.
*/
unsigned int replace_dir_mode :2;
unsigned int replace_file_mode :2;
unsigned int replace_uid :2;
unsigned int replace_gid :2;
mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */
mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */
uid_t uid; /** uid to use when replace_uid == 2. */
gid_t gid; /** gid to use when replace_gid == 2. */
char *output_charset; /**< NULL to use default charset */
/* Options for image transport */
/** The number of bytes to be used for the fifo which decouples libisofs
and libburn for better throughput and for reducing the risk of
interrupting signals hitting the libburn thread which operates the
MMC drive.
The size will be rounded up to the next full 2048.
Minimum is 64kiB, maximum is 1 GiB (but that is too much anyway).
*/
int fifo_size;
};
#endif /* Isoburn_includeD */

View File

@ -1,398 +0,0 @@
/*
cc -g -c isofs_wrap.c
*/
/*
libisofs related functions of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
Thomas Schmitt <scdbackup@gmx.net>
*/
#include <stdlib.h>
#include <string.h>
#ifndef Xorriso_standalonE
#include <libburn/libburn.h>
#include <libisofs/libisofs.h>
#else /* ! Xorriso_standalonE */
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#endif /* Xorriso_standalonE */
#include "isoburn.h"
#include "libisoburn.h"
#define BP(a,b) [(b) - (a) + 1]
struct ecma119_pri_vol_desc
{
uint8_t vol_desc_type BP(1, 1);
uint8_t std_identifier BP(2, 6);
uint8_t vol_desc_version BP(7, 7);
uint8_t unused1 BP(8, 8);
uint8_t system_id BP(9, 40);
uint8_t volume_id BP(41, 72);
uint8_t unused2 BP(73, 80);
uint8_t vol_space_size BP(81, 88);
uint8_t unused3 BP(89, 120);
uint8_t vol_set_size BP(121, 124);
uint8_t vol_seq_number BP(125, 128);
uint8_t block_size BP(129, 132);
uint8_t path_table_size BP(133, 140);
uint8_t l_path_table_pos BP(141, 144);
uint8_t opt_l_path_table_pos BP(145, 148);
uint8_t m_path_table_pos BP(149, 152);
uint8_t opt_m_path_table_pos BP(153, 156);
uint8_t root_dir_record BP(157, 190);
uint8_t vol_set_id BP(191, 318);
uint8_t publisher_id BP(319, 446);
uint8_t data_prep_id BP(447, 574);
uint8_t application_id BP(575, 702);
uint8_t copyright_file_id BP(703, 739);
uint8_t abstract_file_id BP(740, 776);
uint8_t bibliographic_file_id BP(777, 813);
uint8_t vol_creation_time BP(814, 830);
uint8_t vol_modification_time BP(831, 847);
uint8_t vol_expiration_time BP(848, 864);
uint8_t vol_effective_time BP(865, 881);
uint8_t file_structure_version BP(882, 882);
uint8_t reserved1 BP(883, 883);
uint8_t app_use BP(884, 1395);
uint8_t reserved2 BP(1396, 2048);
};
static
uint32_t iso_read_lsb(const uint8_t *buf, int bytes)
{
int i;
uint32_t ret = 0;
for (i=0; i<bytes; i++) {
ret += ((uint32_t) buf[i]) << (i*8);
}
return ret;
}
/* API function. See libisoburn.h
*/
IsoImage *isoburn_get_attached_image(struct burn_drive *d)
{
int ret;
struct isoburn *o= NULL;
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0)
return NULL;
if (o == NULL) {
return NULL;
}
iso_image_ref(o->image);
return o->image;
}
static void isoburn_idle_free_function(void *ignored)
{
return;
}
/* API function. See libisoburn.h
*/
int isoburn_read_image(struct burn_drive *d,
struct isoburn_read_opts *read_opts,
IsoImage **image)
{
int ret, int_num;
IsoReadOpts *ropts= NULL;
IsoReadImageFeatures *features= NULL;
uint32_t ms_block;
enum burn_disc_status status= BURN_DISC_BLANK;
IsoDataSource *ds= NULL;
struct isoburn *o= NULL;
if(read_opts==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_read_image: read_opts==NULL",
0, "FATAL", NULL);
return(-1);
}
if(d != NULL) {
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0 || o == NULL)
return 0;
status = isoburn_disc_get_status(d);
}
if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) {
/*
* Blank disc, we create a new image without files.
*/
if (d == NULL) {
/* New empty image without relation to a drive */
if (image==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_read_image: image==NULL",
0, "FATAL", NULL);
return -1;
}
/* create a new image */
ret = iso_image_new("ISOIMAGE", image);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
return ret;
}
} else {
/* Blank new image for the drive */
iso_image_unref(o->image);
ret = iso_image_new("ISOIMAGE", &o->image);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
return ret;
}
if (image) {
*image = o->image;
iso_image_ref(*image); /*protects object from premature free*/
}
}
return 1;
}
if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_read_image: incorrect disc status",
0, "FATAL", NULL);
return -4;
}
memset((char *) &ropts, 0, sizeof(ropts));
ret = isoburn_disc_get_msc1(d, &int_num);
if (ret <= 0)
return -2;
ms_block= int_num;
/* create the data source */
ret = iso_read_opts_new(&ropts, 0);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot create write opts", 0, "FATAL", 0);
return ret;
}
/* Important: do not return until iso_read_opts_free() */
iso_read_opts_set_start_block(ropts, ms_block);
iso_read_opts_set_no_rockridge(ropts, read_opts->norock);
iso_read_opts_set_no_joliet(ropts, read_opts->nojoliet);
iso_read_opts_set_no_iso1999(ropts, read_opts->noiso1999);
iso_read_opts_set_preferjoliet(ropts, read_opts->preferjoliet);
iso_read_opts_set_default_permissions(ropts,
read_opts->mode, read_opts->dirmode);
iso_read_opts_set_default_uid(ropts, read_opts->uid);
iso_read_opts_set_default_gid(ropts, read_opts->gid);
iso_read_opts_set_input_charset(ropts, read_opts->input_charset);
ds = isoburn_data_source_new(d);
iso_image_attach_data(o->image, o->read_pacifier_handle,
isoburn_idle_free_function);
if(o->read_pacifier_handle==NULL)
iso_tree_set_report_callback(o->image, NULL);
else
iso_tree_set_report_callback(o->image, o->read_pacifier);
ret = iso_image_import(o->image, ds, ropts, &features);
iso_tree_set_report_callback(o->image, NULL);
iso_read_opts_free(ropts);
iso_data_source_unref(ds);
if (ret < 0) {
isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0);
return ret;
}
/* Important: do not return until free(features) */
if (image!=NULL) {
*image = o->image;
iso_image_ref(*image); /*protects object from premature free*/
}
read_opts->hasRR = iso_read_image_features_has_rockridge(features);
read_opts->hasJoliet = iso_read_image_features_has_joliet(features);
read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features);
read_opts->hasElTorito = iso_read_image_features_has_eltorito(features);
read_opts->size = iso_read_image_features_get_size(features);
#ifdef NIX
read_opts->hasRR = features->hasRR;
read_opts->hasJoliet = features->hasJoliet;
read_opts->hasIso1999 = features->hasIso1999;
read_opts->hasElTorito = features->hasElTorito;
read_opts->size = features->size;
#endif
iso_read_image_features_destroy(features);
return 1;
}
/* API function. See libisoburn.h
*/
int isoburn_attach_image(struct burn_drive *d, IsoImage *image)
{
int ret;
struct isoburn *o;
if (image == NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_attach_image: image==NULL",
0, "FATAL", NULL);
return -1;
}
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0 || o == NULL)
return 0;
if(o->image != NULL)
iso_image_unref(o->image);
o->image = image;
return(1);
}
/* API function. See libisoburn.h
*/
int isoburn_activate_session(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
ret = isoburn_find_emulator(&o, drive, 0);
if (ret < 0)
return -1;
if (o->emulation_mode != 1)
return 1; /* don't need to activate session */
if (o->fabricated_disc_status != BURN_DISC_APPENDABLE)
return 1;
ret = burn_random_access_write(drive, 0, (char*)o->target_iso_head,
32*2048, 1);
return ret;
}
/** Initialize the emulation of multi-session on random access media.
The need for emulation is confirmed already.
@param o A freshly created isoburn object. isoburn_create_data_source() was
already called, nevertheless.
@return <=0 error , 1 = success
*/
int isoburn_start_emulation(struct isoburn *o, int flag)
{
int ret, i;
off_t data_count;
struct burn_drive *drive;
struct ecma119_pri_vol_desc *pvm;
if(o==NULL) {
burn_msgs_submit(0x00060000,
"Program error: isoburn_start_emulation: o==NULL",
0, "FATAL", NULL);
return -1;
}
drive= o->drive;
/* we can assume 0 as start block for image */
/* TODO what about ms? where we validate valid iso image in ms disc? */
ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head,
sizeof(o->target_iso_head), &data_count, 2);
/* an error means an empty disc */
if (ret <= 0) {
o->fabricated_disc_status= BURN_DISC_BLANK;
return 1;
}
/* check first 64K. If 0's, the disc is treated as a blank disc, and thus
overwritten without extra check. */
i = sizeof(o->target_iso_head);
while (i && !o->target_iso_head[i-1])
--i;
if (!i) {
o->fabricated_disc_status= BURN_DISC_BLANK;
return 1;
}
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
if (!strncmp((char*)pvm->std_identifier, "CD001", 5)) {
off_t size;
/* sanity check */
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
|| pvm->file_structure_version[0] != 1 ) {
/* TODO for now I treat this as a full disc */
o->fabricated_disc_status= BURN_DISC_FULL;
return 1;
}
/* ok, PVM found, set size */
size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
size *= (off_t) 2048; /* block size in bytes */
isoburn_set_start_byte(o, size, 0);
o->fabricated_disc_status= BURN_DISC_APPENDABLE;
} else if (!strncmp((char*)pvm->std_identifier, "CDXX1", 5)) {
/* empty image */
isoburn_set_start_byte(o, (off_t) 0, 0);
o->fabricated_disc_status= BURN_DISC_BLANK;
} else {
/* treat any disc in an unknown format as full */
o->fabricated_disc_status= BURN_DISC_FULL;
}
return 1;
}
/** 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.
@param o A fully activated isoburn object. isoburn_start_emulation()
was already called.
@return <=0 error , 1 = success
*/
int isoburn_invalidate_iso(struct isoburn *o, int flag)
{
/*
* replace CD001 with CDXX1 in PVM.
* I think this is enought for invalidating an iso image
*/
strncpy((char*)o->target_iso_head + 16 * 2048 + 1, "CDXX1", 5);
return isoburn_activate_session(o->drive);
}
/* API @since 0.1.0 */
int isoburn_set_read_pacifier(struct burn_drive *drive,
int (*read_pacifier)(IsoImage*, IsoFileSource*),
void *read_handle)
{
int ret;
struct isoburn *o;
ret = isoburn_find_emulator(&o, drive, 0);
if(ret < 0 || o == NULL)
return -1;
o->read_pacifier_handle= read_handle;
o->read_pacifier= read_pacifier;
return(1);
}

File diff suppressed because it is too large Load Diff