libisoburn/xorriso/xorrisoburn.c

4185 lines
128 KiB
C
Raw Normal View History

/* Adapter to libisoburn, libisofs and libburn for xorriso,
a command line oriented batch and dialog tool which creates, loads,
manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2.
*/
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
2007-10-15 15:27:51 +00:00
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h>
/* ------------------------------------------------------------------------ */
#ifndef Xorriso_standalonE
/* The library which does the ISO 9660 / RockRidge manipulations */
#include <libisofs/libisofs.h>
/* The library which does MMC optical drive operations */
#include <libburn/libburn.h>
/* The library which enhances overwriteable media with ISO 9660 multi-session
capabilities via the method invented by Andy Polyakov for growisofs */
#include <libisoburn/libisoburn.h>
/* The official xorriso options API. "No shortcuts" */
#include "xorriso.h"
/* The inner description of XorrisO */
#include "xorriso_private.h"
/* The inner isofs- and burn-library interface */
#include "xorrisoburn.h"
#else /* ! Xorriso_standalonE */
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#include "../libisoburn/libisoburn.h"
#include "xorriso.h"
#include "xorriso_private.h"
#include "xorrisoburn.h"
#endif /* Xorriso_standalonE */
2008-02-19 21:24:05 +00:00
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
2007-11-07 12:37:19 +00:00
int flag);
2008-02-06 21:45:31 +00:00
int Xorriso__read_pacifier(IsoImage *image, IsoFileSource *filesource);
#define LIBISO_ISDIR(node) (iso_node_get_type(node) == LIBISO_DIR)
#define LIBISO_ISREG(node) (iso_node_get_type(node) == LIBISO_FILE)
#define LIBISO_ISLNK(node) (iso_node_get_type(node) == LIBISO_SYMLINK)
#define LIBISO_ISCHR(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
S_ISCHR(iso_node_get_mode(node)))
#define LIBISO_ISBLK(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
S_ISBLK(iso_node_get_mode(node)))
#define LIBISO_ISFIFO(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
S_ISFIFO(iso_node_get_mode(node)))
#define LIBISO_ISSOCK(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
S_ISSOCK(iso_node_get_mode(node)))
2008-02-05 16:27:10 +00:00
/* CD specs say one shall not write tracks < 600 kiB */
#define Xorriso_cd_min_track_sizE 300
/* ------------------------------------------------------------------------ */
int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
{
2008-01-29 18:44:54 +00:00
int ret, major, minor, micro;
char *handler_prefix= NULL;
char *queue_sev, *print_sev, reason[1024];
/* First an ugly compile time check for header version compatibility.
If everthing matches, then no C code is produced. In case of mismatch,
intentionally faulty C code will be inserted.
*/
/* The minimum requirement of xorriso towards the libisoburn header
at compile time is defined in xorriso/xorrisoburn.h
xorriso_libisoburn_req_major
xorriso_libisoburn_req_minor
xorriso_libisoburn_req_micro
It gets compared against the version macros in libburn/libburn.h :
isoburn_header_version_major
isoburn_header_version_minor
isoburn_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: 'LIBISOBURN_MISCONFIGURATION' undeclared (first use in this function)
error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c' undeclared (first use in this function)
error: 'LIBISOBURN_MISCONFIGURATION_' undeclared (first use in this function)
*/
/* The indendation is an advise of man gcc to help old compilers ignoring */
#if xorriso_libisoburn_req_major > isoburn_header_version_major
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#if xorriso_libisoburn_req_major == isoburn_header_version_major && xorriso_libisoburn_req_minor > isoburn_header_version_minor
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#if xorriso_libisoburn_req_minor == isoburn_header_version_minor && xorriso_libisoburn_req_micro > isoburn_header_version_micro
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#ifdef Isoburn_libisoburn_dot_h_too_olD
LIBISOBURN_MISCONFIGURATION = 0;
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c = 0;
LIBISOBURN_MISCONFIGURATION_ = 0;
#endif
/* End of ugly compile time test (scroll up for explanation) */
sprintf(xorriso->info_text, "Starting up libraries ...\n");
Xorriso_info(xorriso, 0);
handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
if(handler_prefix==NULL) {
sprintf(xorriso->info_text,
"Cannot allocate memory for initializing libraries");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
reason[0]= 0;
ret= isoburn_initialize(reason, 0);
if(ret==0) {
sprintf(xorriso->info_text, "Cannot initialize libraries");
if(reason[0])
sprintf(xorriso->info_text+strlen(xorriso->info_text),
". Reason given:\n%s", reason);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
free(handler_prefix);
return(0);
}
2008-01-29 18:44:54 +00:00
ret= isoburn_is_compatible(isoburn_header_version_major,
isoburn_header_version_minor,
isoburn_header_version_micro, 0);
if(ret<=0) {
isoburn_version(&major, &minor, &micro);
sprintf(xorriso->info_text,
"libisoburn version too old: %d.%d.%d . Need at least: %d.%d.%d .\n",
major, minor, micro,
isoburn_header_version_major, isoburn_header_version_minor,
isoburn_header_version_micro);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
xorriso->libs_are_started= 1;
queue_sev= "DEBUG";
if(xorriso->library_msg_direct_print) {
/* >>> need option for controlling this in XorrisO.
See also Xorriso_msgs_submit */;
print_sev= xorriso->report_about_text;
} else
print_sev= "NEVER";
iso_set_msgs_severities(queue_sev, print_sev, "libsofs : ");
burn_msgs_set_severities(queue_sev, print_sev, "libburn : ");
/* ??? >>> do we want united queues ? */
/* burn_set_messenger(iso_get_messenger()); */
sprintf(handler_prefix, "%s : ", xorriso->progname);
2007-10-15 15:27:51 +00:00
burn_set_signal_handling(handler_prefix, NULL, 0);
Xorriso_process_msg_queues(xorriso,0);
if(reason[0]) {
sprintf(xorriso->info_text, "%s", reason);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
}
sprintf(xorriso->info_text, "Library startup done.\n");
Xorriso_info(xorriso, 0);
free(handler_prefix);
return(1);
}
2008-01-15 20:41:56 +00:00
/* @param flag bit0= global shutdown of libraries */
int Xorriso_detach_libraries(struct XorrisO *xorriso, int flag)
{
2008-01-15 20:41:56 +00:00
Xorriso_give_up_drive(xorriso, 3);
if(xorriso->in_volset_handle!=NULL) { /* standalone image */
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
xorriso->in_volset_handle= NULL;
}
2008-01-15 20:41:56 +00:00
if(flag&1) {
if(xorriso->libs_are_started==0)
return(0);
isoburn_finish();
}
return(1);
}
2007-10-18 18:32:32 +00:00
/* @param flag bit1= obtain outdrive, else indrive */
int Xorriso_get_drive_handles(struct XorrisO *xorriso,
struct burn_drive_info **dinfo,
struct burn_drive **drive,
char *attempt, int flag)
{
if(flag&2)
*dinfo= (struct burn_drive_info *) xorriso->out_drive_handle;
else
*dinfo= (struct burn_drive_info *) xorriso->in_drive_handle;
if(*dinfo==NULL) {
Xorriso_process_msg_queues(xorriso,0);
2007-11-14 14:28:44 +00:00
sprintf(xorriso->info_text, "No %s drive aquired %s",
(flag&2 ? "output" : "input"), attempt);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2007-10-18 18:32:32 +00:00
return(0);
}
*drive= (*dinfo)[0].drive;
2007-10-19 17:35:20 +00:00
return((*drive)!=NULL);
2007-10-18 18:32:32 +00:00
}
/* <<< 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_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
2008-02-11 19:49:03 +00:00
#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
int Xorriso__sev_to_text(int severity, char **severity_name,
int flag)
{
if(flag&1) {
*severity_name= "NEVER\nABORT\nFATAL\nFAILURE\nSORRY\nWARNING\nHINT\nNOTE\nUPDATE\nDEBUG\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";
2008-02-11 19:49:03 +00:00
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_ALL)
*severity_name= "ALL";
else {
*severity_name= "";
return(0);
}
return(1);
}
2008-02-11 19:49:03 +00:00
int Xorriso__text_to_sev(char *severity_name, int *severity_number, int flag)
{
int ret= 1;
if(severity_name[0]==0)
*severity_number= 0;
else if(strcmp(severity_name, "MISHAP")==0)
*severity_number= LIBDAX_MSGS_SEV_MISHAP;
else
ret= burn_text_to_sev(severity_name, severity_number, 0);
return(ret);
}
/* @param flag bit0=report libisofs error text */
int Xorriso_report_iso_error(struct XorrisO *xorriso, char *victim,
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;
char sfe[6*SfileadrL];
2008-02-06 18:35:11 +00:00
error_code= iso_error_get_code(iso_error_code);
2008-02-06 18:40:59 +00:00
if(error_code < 0x00030000 || error_code >= 0x00040000)
2008-02-06 18:35:11 +00:00
error_code= (error_code & 0xffff) | 0x00050000;
if(flag&1)
msg_text_pt= (char *) iso_error_to_msg(iso_error_code);
if(msg_text_pt==NULL)
msg_text_pt= msg_text;
2008-02-04 09:32:02 +00:00
iso_sev= iso_error_get_severity(iso_error_code);
sev_text_pt= min_severity;
2008-02-11 19:49:03 +00:00
Xorriso__text_to_sev(min_severity, &min_sev, 0);
if(min_sev < iso_sev)
/* >>> with libburn-0.4.4 do: burn_sev_to_text(iso_sev, &sev_text_pt, 0); */
Xorriso__sev_to_text(iso_sev, &sev_text_pt, 0);
strcpy(sfe, msg_text_pt);
if(victim[0]) {
strcat(sfe, ": ");
Text_shellsafe(victim, sfe+strlen(sfe), 0);
}
2008-02-06 18:35:11 +00:00
ret= Xorriso_msgs_submit(xorriso, error_code, sfe, os_errno, sev_text_pt, 4);
return(ret);
}
/* @param flag bit0= suppress DEBUG messages */
int Xorriso_set_image_severities(struct XorrisO *xorriso, int flag)
{
char *queue_sev, *print_sev;
if(flag&1)
queue_sev= "UPDATE";
else
queue_sev= "DEBUG";
if(xorriso->library_msg_direct_print)
print_sev= xorriso->report_about_text;
else
print_sev= "NEVER";
iso_set_msgs_severities(queue_sev, print_sev, "libisofs : ");
return(1);
}
int Xorriso_update_volid(struct XorrisO *xorriso, int flag)
{
int gret, sret= 1;
gret= Xorriso_get_volid(xorriso, xorriso->loaded_volid, 0);
if(gret<=0 || (!xorriso->volid_default) || xorriso->loaded_volid[0]==0)
sret= Xorriso_set_volid(xorriso, xorriso->volid, 1);
return(gret>0 && sret>0);
}
2007-11-14 14:28:44 +00:00
int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
{
int ret;
IsoImage *volset;
struct isoburn_read_opts *ropts;
2007-11-14 14:28:44 +00:00
struct burn_drive_info *dinfo= NULL;
struct burn_drive *drive= NULL;
if(xorriso->out_drive_handle != NULL) {
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
"on attempt to attach volset to drive", 2);
if(ret<=0)
return(ret);
}
if(xorriso->in_volset_handle!=NULL) {
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
2007-11-14 14:28:44 +00:00
xorriso->in_volset_handle= NULL;
xorriso->loaded_volid[0]= 0;
2007-11-14 14:28:44 +00:00
xorriso->volset_change_pending= 0;
}
ret= isoburn_ropt_new(&ropts, 0);
if(ret<=0)
return(ret);
/* Note: no return before isoburn_ropt_destroy() */
isoburn_ropt_set_extensions(ropts, isoburn_ropt_pretend_blank);
isoburn_ropt_set_input_charset(ropts, NULL);
2008-02-06 21:45:31 +00:00
isoburn_set_read_pacifier(drive, NULL, NULL);
ret= isoburn_read_image(drive, ropts, &volset);
2007-11-14 14:28:44 +00:00
Xorriso_process_msg_queues(xorriso,0);
isoburn_ropt_destroy(&ropts, 0);
2007-11-14 14:28:44 +00:00
if(ret<=0) {
sprintf(xorriso->info_text, "Failed to create new empty ISO image object");
Xorriso_report_iso_error(xorriso, "", ret, xorriso->info_text, 0, "FATAL",
0);
2007-11-14 14:28:44 +00:00
return(-1);
}
xorriso->in_volset_handle= (void *) volset;
Xorriso_update_volid(xorriso, 0);
2007-11-14 14:28:44 +00:00
xorriso->volset_change_pending= 0;
return(1);
}
/* @param flag bit0= aquire as isoburn input drive
bit1= aquire as libburn output drive (as isoburn drive if bit0)
bit2= regard overwriteable media as blank
bit3= if the drive is a regular disk file: truncate it to
the write start address
2007-11-14 14:28:44 +00:00
@return <=0 failure , 1= ok
2=success, but not writeable with bit1
3=success, but not blank and not ISO with bit0
2007-10-15 15:27:51 +00:00
*/
int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
{
int ret, hret, not_writeable= 0, has_what;
uint32_t size;
2007-11-14 14:28:44 +00:00
struct burn_drive_info *dinfo= NULL, *out_dinfo, *in_dinfo;
struct burn_drive *drive, *out_drive, *in_drive;
2007-10-15 15:27:51 +00:00
enum burn_disc_status state;
IsoImage *volset = NULL;
struct isoburn_read_opts *ropts= NULL;
char adr_data[SfileadrL], *libburn_adr, *boot_fate;
2007-10-15 15:27:51 +00:00
2007-11-14 14:28:44 +00:00
if((flag&3)==0) {
sprintf(xorriso->info_text,
"XORRISOBURN program error : Xorriso_aquire_drive bit0+bit1 not set");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
2007-10-15 15:27:51 +00:00
}
2007-11-14 14:28:44 +00:00
ret= Xorriso_give_up_drive(xorriso, (flag&3)|8);
2007-10-15 15:27:51 +00:00
if(ret<=0)
return(ret);
libburn_adr= adr;
if(strcmp(adr,"stdio:/dev/fd/1")==0) {
if(xorriso->dev_fd_1<0) {
sprintf(xorriso->info_text,
"-*dev \"stdio:/dev/fd/1\" was not a start argument. Cannot use it now.");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
} else {
sprintf(adr_data, "stdio:/dev/fd/%d", xorriso->dev_fd_1);
libburn_adr= adr_data;
}
}
2007-11-14 14:28:44 +00:00
if((flag&3)==1 && xorriso->out_drive_handle!=NULL) {
ret= Xorriso_get_drive_handles(xorriso, &out_dinfo, &out_drive,
"on attempt to compare new indev with outdev", 2);
if(ret<=0)
goto ex;
ret= burn_drive_equals_adr(out_drive, libburn_adr, 1);
2007-11-14 14:28:44 +00:00
if(ret==1)
dinfo= out_dinfo;
} else if((flag&3)==2 && xorriso->in_drive_handle!=NULL) {
ret= Xorriso_get_drive_handles(xorriso, &in_dinfo, &in_drive,
"on attempt to compare new indev with outdev", 0);
if(ret<=0)
goto ex;
ret= burn_drive_equals_adr(in_drive, libburn_adr, 1);
2007-11-14 14:28:44 +00:00
if(ret==1)
dinfo= in_dinfo;
}
if(dinfo==NULL) {
ret= isoburn_drive_aquire(&dinfo, libburn_adr, 1|((flag&(8|4))>>1));
2007-11-14 14:28:44 +00:00
Xorriso_process_msg_queues(xorriso,0);
if(ret<=0) {
sprintf(xorriso->info_text,"Cannot aquire drive '%s'", adr);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
2007-11-14 14:28:44 +00:00
}
2007-10-15 15:27:51 +00:00
}
2007-11-14 14:28:44 +00:00
drive= dinfo[0].drive;
state= isoburn_disc_get_status(drive);
Xorriso_process_msg_queues(xorriso,0);
if(flag&1) {
volset= isoburn_get_attached_image(drive);
if(volset != NULL) { /* The image object is already created */
iso_image_unref(volset);
}
}
2007-11-14 14:28:44 +00:00
2007-10-19 20:41:34 +00:00
if(flag&2) {
2007-10-15 15:27:51 +00:00
xorriso->out_drive_handle= dinfo;
2007-11-14 14:28:44 +00:00
if(Sfile_str(xorriso->outdev, adr, 0)<=0)
{ret= -1; goto ex;}
2007-11-14 14:28:44 +00:00
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
sprintf(xorriso->info_text, "Disc status unsuitable for writing");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
not_writeable= 1;
}
2007-10-19 20:41:34 +00:00
}
if(flag&1) {
2007-10-15 15:27:51 +00:00
xorriso->in_drive_handle= dinfo;
2007-11-14 14:28:44 +00:00
if(Sfile_str(xorriso->indev, adr, 0)<=0)
{ret= -1; goto ex;}
2007-11-14 14:28:44 +00:00
} else if(flag&2) {
if(xorriso->in_volset_handle==NULL) {
/* No volume loaded: create empty one */
ret= Xorriso_create_empty_iso(xorriso, 0);
if(ret<=0)
goto ex;
2007-11-14 14:28:44 +00:00
} else {
iso_image_ref((IsoImage *) xorriso->in_volset_handle);
ret= isoburn_attach_image(drive, (IsoImage *) xorriso->in_volset_handle);
2007-11-14 14:28:44 +00:00
if(ret<=0) {
sprintf(xorriso->info_text,
"Failed to attach ISO image object to outdev");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;}
2007-11-14 14:28:44 +00:00
}
}
Xorriso_toc(xorriso, 1|2);
{ret= 1+not_writeable; goto ex;}
2007-11-14 14:28:44 +00:00
}
2007-10-15 15:27:51 +00:00
2007-11-14 14:28:44 +00:00
if(xorriso->in_volset_handle!=NULL)
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
2007-11-14 14:28:44 +00:00
xorriso->in_volset_handle= NULL;
2007-10-15 15:27:51 +00:00
/* check for invalid state */
2007-11-14 14:28:44 +00:00
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE &&
state != BURN_DISC_FULL) {
sprintf(xorriso->info_text,
"Disc status not blank and unsuitable for reading");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
2007-10-15 15:27:51 +00:00
}
/* fill read opts */
ret= isoburn_ropt_new(&ropts, 0);
if(ret<=0)
goto ex;
isoburn_ropt_set_extensions(ropts, isoburn_ropt_noiso1999);
isoburn_ropt_set_default_perms(ropts, (uid_t) 0, (gid_t) 0, (mode_t) 0555);
isoburn_ropt_set_input_charset(ropts, NULL);
Xorriso_set_image_severities(xorriso, 1); /* No DEBUG messages */
2008-02-06 21:45:31 +00:00
Xorriso_pacifier_reset(xorriso, 0);
isoburn_set_read_pacifier(drive, Xorriso__read_pacifier, (void *) xorriso);
if(isoburn_read_image(drive, ropts, &volset) <= 0) {
Xorriso_process_msg_queues(xorriso,0);
Xorriso_set_image_severities(xorriso, 0);
2007-10-17 20:02:45 +00:00
sprintf(xorriso->info_text,"Cannot read ISO image volset");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2007-11-14 14:28:44 +00:00
ret= 3; goto ex;
2007-10-15 15:27:51 +00:00
}
Xorriso_pacifier_callback(xorriso, "nodes read", xorriso->pacifier_count, 0,
"", 1); /* report end count */
xorriso->in_volset_handle= (void *) volset;
Xorriso_set_image_severities(xorriso, 0);
Xorriso_update_volid(xorriso, 0);
2007-11-14 14:28:44 +00:00
if(xorriso->out_drive_handle != NULL &&
xorriso->out_drive_handle != xorriso->in_drive_handle) {
ret= Xorriso_get_drive_handles(xorriso, &out_dinfo, &out_drive,
"on attempt to attach ISO image volset to outdev", 2);
if(ret<=0)
goto ex;
iso_image_ref((IsoImage *) xorriso->in_volset_handle);
isoburn_attach_image(out_drive, xorriso->in_volset_handle);
2007-11-14 14:28:44 +00:00
}
Xorriso_process_msg_queues(xorriso,0);
isoburn_ropt_get_size_what(ropts, &size, &has_what);
if(has_what & isoburn_ropt_has_el_torito) {
if(xorriso->patch_isolinux_image)
boot_fate= "patched as isolinux image";
else if(xorriso->keep_boot_image)
boot_fate= "kept unchanged";
else
boot_fate= "discarded";
sprintf(xorriso->info_text,
"Detected El-Torito boot information which currently is set to be %s",
boot_fate);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
Xorriso_toc(xorriso, 1);
if(xorriso->loaded_volid[0]!=0) {
sprintf(xorriso->result_line,"Volume id : '%s'\n",xorriso->loaded_volid);
Xorriso_result(xorriso,0);
if(strcmp(xorriso->loaded_volid, xorriso->volid)!=0 &&
!xorriso->volid_default) {
sprintf(xorriso->result_line, "New volume id: '%s'\n", xorriso->volid);
Xorriso_result(xorriso,0);
}
}
2007-11-14 14:28:44 +00:00
ret= 1+not_writeable;
2007-10-15 15:27:51 +00:00
ex:
Xorriso_process_msg_queues(xorriso,0);
2007-11-14 14:28:44 +00:00
if(ret<=0) {
hret= Xorriso_give_up_drive(xorriso, flag&3);
if(hret<ret)
ret= hret;
2007-10-15 15:27:51 +00:00
}
if(ropts!=NULL)
isoburn_ropt_destroy(&ropts, 0);
2007-10-15 15:27:51 +00:00
return(ret);
}
/* @param flag bit0=input drive
bit1=output drive
2007-10-19 17:35:20 +00:00
bit2=eject
2007-11-14 14:28:44 +00:00
bit3=no info message or toc
2007-10-15 15:27:51 +00:00
*/
int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
{
2007-11-14 14:28:44 +00:00
int in_is_out_too, ret;
2007-10-15 15:27:51 +00:00
struct burn_drive_info *dinfo;
struct burn_drive *drive;
char sfe[5*SfileadrL];
2007-10-15 15:27:51 +00:00
in_is_out_too= (xorriso->in_drive_handle == xorriso->out_drive_handle);
if((flag&4) && in_is_out_too && (flag&(1|2))) {
if((flag&3)!=3) {
sprintf(xorriso->info_text,"Giving up for -eject whole -dev %s",
Text_shellsafe(xorriso->indev, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
flag|= 3; /* give up in/out drive to eject it */
}
2007-10-15 15:27:51 +00:00
if((flag&1) && xorriso->in_drive_handle != NULL) {
2007-10-18 18:32:32 +00:00
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
2007-11-14 14:28:44 +00:00
"on attempt to give up drive", 0);
if(!in_is_out_too) {
if(drive!=NULL && !in_is_out_too)
isoburn_drive_release(drive,!!(flag&4));
if(dinfo!=NULL && !in_is_out_too)
burn_drive_info_free(dinfo);
}
xorriso->in_drive_handle= NULL;
xorriso->indev[0]= 0;
2007-10-15 15:27:51 +00:00
2007-10-18 22:56:43 +00:00
if(xorriso->in_volset_handle!=NULL)
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
xorriso->in_volset_handle= NULL;
xorriso->loaded_volid[0]= 0;
2007-10-15 22:40:39 +00:00
xorriso->volset_change_pending= 0;
2007-10-15 15:27:51 +00:00
2007-11-14 14:28:44 +00:00
in_is_out_too= 0;
2007-10-15 15:27:51 +00:00
}
if((flag&2) && xorriso->out_drive_handle!=NULL) {
2007-10-18 18:32:32 +00:00
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
"on attempt to give up drive", 2);
2007-11-14 14:28:44 +00:00
if(!in_is_out_too) {
if(drive!=NULL)
isoburn_drive_release(drive,!!(flag&4));
if(dinfo!=NULL)
burn_drive_info_free(dinfo);
}
2007-10-15 15:27:51 +00:00
xorriso->out_drive_handle= NULL;
2007-10-19 20:41:34 +00:00
xorriso->outdev[0]= 0;
2007-11-14 14:28:44 +00:00
} else if((flag&1) && xorriso->out_drive_handle!=NULL) {
ret= Xorriso_create_empty_iso(xorriso, 0);
if(ret<=0)
return(ret);
if(!(flag&8)) {
sprintf(xorriso->info_text,
"Only the output drive remains. Created empty ISO image.\n");
Xorriso_info(xorriso, 0);
Xorriso_toc(xorriso, 1|2);
}
2007-10-15 15:27:51 +00:00
}
Xorriso_process_msg_queues(xorriso,0);
2007-10-15 15:27:51 +00:00
return(1);
}
2007-10-15 22:40:39 +00:00
2007-10-18 18:32:32 +00:00
int Xorriso_make_write_options(
struct XorrisO *xorriso, struct burn_drive *drive,
struct burn_write_opts **burn_options, int flag)
{
int drive_role;
2007-10-18 18:32:32 +00:00
*burn_options= burn_write_opts_new(drive);
if(*burn_options==NULL) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Cannot allocate option set");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2007-10-18 18:32:32 +00:00
return(0);
}
burn_write_opts_set_simulate(*burn_options, !!xorriso->do_dummy);
drive_role= burn_drive_get_drive_role(drive);
burn_write_opts_set_multi(*burn_options,
!(xorriso->do_close || drive_role==0 || drive_role==3));
2007-10-18 18:32:32 +00:00
burn_drive_set_speed(drive, xorriso->speed, xorriso->speed);
burn_write_opts_set_underrun_proof(*burn_options, 1);
return(1);
}
/* @param flag bit0= do not write but only prepare and return size in sectors
bit1= do not use isoburn wrappers
*/
int Xorriso_sanitize_image_size(struct XorrisO *xorriso,
struct burn_drive *drive, struct burn_disc *disc,
struct burn_write_opts *burn_options, int flag)
{
int ret, img_sectors, num_sessions= 0, num_tracks= 0, padding= 0, profile;
int media_space;
char profile_name[80];
struct burn_session **sessions;
struct burn_track **tracks;
ret= img_sectors= burn_disc_get_sectors(disc);
if(flag&1)
goto ex;
sessions= burn_disc_get_sessions(disc, &num_sessions);
if(sessions==NULL || num_sessions < 1) {
no_track:;
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Program error : no track in prepared disc");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;}
}
tracks= burn_session_get_tracks(sessions[0], &num_tracks);
if(tracks==NULL || num_tracks < 1)
goto no_track;
padding= 0;
ret= burn_disc_get_profile(drive, &profile, profile_name);
padding= xorriso->padding / 2048;
if(xorriso->padding > padding * 2048)
padding++;
if(img_sectors>0 && (profile==0x09 || profile==0x0a)) { /* CD-R , CD-RW */
if(img_sectors + padding < Xorriso_cd_min_track_sizE) {
padding= Xorriso_cd_min_track_sizE - img_sectors;
sprintf(xorriso->info_text,
"Expanded track to minimum size of %d sectors",
Xorriso_cd_min_track_sizE);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
}
burn_track_define_data(tracks[0], 0, padding * 2048, 0, BURN_MODE1);
Xorriso_process_msg_queues(xorriso,0);
if(flag&2)
media_space= burn_disc_available_space(drive, burn_options) /
(off_t) 2048;
else
media_space= isoburn_disc_available_space(drive, burn_options) /
(off_t) 2048;
if(media_space < img_sectors + padding) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Image size %ds exceeds free space on media %ds",
img_sectors + padding, media_space);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
}
ret= 1;
ex:;
return(ret);
}
2007-10-19 15:13:16 +00:00
/* @param flag bit0= do not write but only prepare and return size in sectors
*/
2007-11-14 14:28:44 +00:00
int Xorriso_write_session(struct XorrisO *xorriso, int flag)