|
|
|
|
|
|
|
|
|
|
|
/* 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>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/* The library which does the ISO 9660 / RockRidge manipulations */
|
|
|
|
/* >>> NG this is a botch name until somebody shows a better solution */
|
|
|
|
#include <libisofs/nglibisofs.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 */
|
|
|
|
/* >>> NG this is a botch name until somebody shows a better solution */
|
|
|
|
#include <libisoburn/ng_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 */
|
|
|
|
/* >>> NG */
|
|
|
|
#include "ng_xorrisoburn.h"
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
int flag);
|
|
|
|
|
|
|
|
#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)))
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *handler_prefix= NULL;
|
|
|
|
char *queue_sev, *print_sev;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
ret= isoburn_initialize();
|
|
|
|
if(ret==0) {
|
|
|
|
sprintf(xorriso->info_text, "Cannot initialize libraries");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
free(handler_prefix);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
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";
|
|
|
|
|
|
|
|
/* >>> NG How to set severities before isoburn_read_image() ?
|
|
|
|
iso_image_set_msgs_severities() demands an IsoImage
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
burn_set_signal_handling(handler_prefix, NULL, 0);
|
|
|
|
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text, "Library startup done.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
free(handler_prefix);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= global shutdown of libraries */
|
|
|
|
int Xorriso_detach_libraries(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if(flag&1) {
|
|
|
|
if(xorriso->libs_are_started==0)
|
|
|
|
return(0);
|
|
|
|
isoburn_finish();
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @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);
|
|
|
|
sprintf(xorriso->info_text, "No %s drive aquired %s",
|
|
|
|
(flag&2 ? "output" : "input"), attempt);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
*drive= (*dinfo)[0].drive;
|
|
|
|
return((*drive)!=NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= suppress DEBUG messages */
|
|
|
|
int Xorriso_set_image_severities(struct XorrisO *xorriso, IsoImage *volset,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
char *queue_sev, *print_sev;
|
|
|
|
|
|
|
|
if(volset==NULL)
|
|
|
|
return(0);
|
|
|
|
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_image_set_msgs_severities(volset, 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 && strcmp(xorriso->volid, "ISOIMAGE")==0)
|
|
|
|
strcpy(xorriso->volid, xorriso->loaded_volid);
|
|
|
|
else
|
|
|
|
sret= Xorriso_set_volid(xorriso, xorriso->volid, 1);
|
|
|
|
return(gret>0 && sret>0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
IsoImage *volset;
|
|
|
|
struct isoburn_read_opts ropts;
|
|
|
|
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);
|
|
|
|
xorriso->in_volset_handle= NULL;
|
|
|
|
xorriso->loaded_volid[0]= 0;
|
|
|
|
xorriso->volset_change_pending= 0;
|
|
|
|
}
|
|
|
|
memset(&ropts, sizeof(ropts), 0);
|
|
|
|
ropts.pretend_blank= 1;
|
|
|
|
ropts.input_charset= NULL;
|
|
|
|
ret= isoburn_read_image(drive, &ropts, &volset);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text, "Failed to create new empty ISO image object");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
xorriso->in_volset_handle= (void *) volset;
|
|
|
|
Xorriso_set_image_severities(xorriso, volset, 0);
|
|
|
|
Xorriso_update_volid(xorriso, 0);
|
|
|
|
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)
|
|
|
|
@return <=0 failure , 1= ok
|
|
|
|
2=success, but not writeable with bit1
|
|
|
|
3=success, but not blank and not ISO with bit0
|
|
|
|
*/
|
|
|
|
int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
|
|
|
|
{
|
|
|
|
int ret, hret, not_writeable= 0;
|
|
|
|
struct burn_drive_info *dinfo= NULL, *out_dinfo, *in_dinfo;
|
|
|
|
struct burn_drive *drive, *out_drive, *in_drive;
|
|
|
|
enum burn_disc_status state;
|
|
|
|
IsoImage *volset = NULL;
|
|
|
|
struct isoburn_read_opts ropts;
|
|
|
|
|
|
|
|
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(0);
|
|
|
|
}
|
|
|
|
ret= Xorriso_give_up_drive(xorriso, (flag&3)|8);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
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, adr, 1);
|
|
|
|
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, adr, 1);
|
|
|
|
if(ret==1)
|
|
|
|
dinfo= in_dinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dinfo==NULL) {
|
|
|
|
ret= isoburn_drive_scan_and_grab(&dinfo, adr, 1);
|
|
|
|
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, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
Xorriso_set_image_severities(xorriso, volset, 0);
|
|
|
|
iso_image_unref(volset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flag&2) {
|
|
|
|
xorriso->out_drive_handle= dinfo;
|
|
|
|
if(Sfile_str(xorriso->outdev, adr, 0)<=0)
|
|
|
|
return(-1);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(flag&1) {
|
|
|
|
xorriso->in_drive_handle= dinfo;
|
|
|
|
if(Sfile_str(xorriso->indev, adr, 0)<=0)
|
|
|
|
return(-1);
|
|
|
|
} 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)
|
|
|
|
return(ret);
|
|
|
|
} else {
|
|
|
|
iso_image_ref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
ret= isoburn_attach_image(drive, (IsoImage *) xorriso->in_volset_handle);
|
|
|
|
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);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Xorriso_toc(xorriso, 1|2);
|
|
|
|
return(1+not_writeable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xorriso->in_volset_handle!=NULL)
|
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
xorriso->in_volset_handle= NULL;
|
|
|
|
|
|
|
|
/* check for invalid state */
|
|
|
|
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);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* fill read opts */
|
|
|
|
memset(&ropts, sizeof(ropts), 0);
|
|
|
|
ropts.norock= 0;
|
|
|
|
ropts.nojoliet= 0;
|
|
|
|
ropts.preferjoliet= 0;
|
|
|
|
ropts.uid= 0;
|
|
|
|
ropts.gid= 0;
|
|
|
|
ropts.mode= 0555;
|
|
|
|
ropts.input_charset= NULL;
|
|
|
|
ropts.pretend_blank= 0;
|
|
|
|
|
|
|
|
Xorriso_set_image_severities(xorriso, volset, 1); /* No DEBUG messages */
|
|
|
|
if(isoburn_read_image(drive, &ropts, &volset) <= 0) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
Xorriso_set_image_severities(xorriso, volset, 0);
|
|
|
|
sprintf(xorriso->info_text,"Cannot read ISO image volset");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 3; goto ex;
|
|
|
|
}
|
|
|
|
xorriso->in_volset_handle= (void *) volset;
|
|
|
|
Xorriso_set_image_severities(xorriso, volset, 0);
|
|
|
|
Xorriso_update_volid(xorriso, 0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
Xorriso_process_msg_queues(xorriso,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) {
|
|
|
|
sprintf(xorriso->result_line, "New volume id: '%s'\n", xorriso->volid);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret= 1+not_writeable;
|
|
|
|
ex:
|
|
|
|
if(ret<=0) {
|
|
|
|
hret= Xorriso_give_up_drive(xorriso, flag&3);
|
|
|
|
if(hret<ret)
|
|
|
|
ret= hret;
|
|
|
|
}
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0=input drive
|
|
|
|
bit1=output drive
|
|
|
|
bit2=eject
|
|
|
|
bit3=no info message or toc
|
|
|
|
*/
|
|
|
|
int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int in_is_out_too, ret;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
|
|
|
|
in_is_out_too= (xorriso->in_drive_handle == xorriso->out_drive_handle);
|
|
|
|
|
|
|
|
if((flag&1) && xorriso->in_drive_handle != NULL) {
|
|
|
|
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"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;
|
|
|
|
|
|
|
|
if(xorriso->in_volset_handle!=NULL)
|
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
xorriso->in_volset_handle= NULL;
|
|
|
|
xorriso->loaded_volid[0]= 0;
|
|
|
|
xorriso->volset_change_pending= 0;
|
|
|
|
|
|
|
|
in_is_out_too= 0;
|
|
|
|
}
|
|
|
|
if((flag&2) && xorriso->out_drive_handle!=NULL) {
|
|
|
|
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to give drive up", 2);
|
|
|
|
if(!in_is_out_too) {
|
|
|
|
if(drive!=NULL)
|
|
|
|
isoburn_drive_release(drive,!!(flag&4));
|
|
|
|
if(dinfo!=NULL)
|
|
|
|
burn_drive_info_free(dinfo);
|
|
|
|
}
|
|
|
|
xorriso->out_drive_handle= NULL;
|
|
|
|
xorriso->outdev[0]= 0;
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_make_write_options(
|
|
|
|
struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
struct burn_write_opts **burn_options, int flag)
|
|
|
|
{
|
|
|
|
*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, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
burn_write_opts_set_simulate(*burn_options, !!xorriso->do_dummy);
|
|
|
|
burn_write_opts_set_multi(*burn_options, !xorriso->do_close);
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int Xorriso_write_session(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret, media_space;
|
|
|
|
struct isoburn_source_opts sopts;
|
|
|
|
struct burn_drive_info *dinfo, *source_dinfo;
|
|
|
|
struct burn_drive *drive, *source_drive;
|
|
|
|
struct burn_disc *disc= NULL;
|
|
|
|
struct burn_write_opts *burn_options;
|
|
|
|
off_t readcounter= 0,writecounter= 0;
|
|
|
|
int num_sessions= 0, num_tracks= 0;
|
|
|
|
struct burn_session **sessions;
|
|
|
|
struct burn_track **tracks;
|
|
|
|
enum burn_disc_status s;
|
|
|
|
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to write", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
memset(&sopts, 0, sizeof(sopts));
|
|
|
|
|
|
|
|
sopts.level= 2;
|
|
|
|
sopts.rockridge= 1;
|
|
|
|
sopts.joliet= !!xorriso->do_joliet;
|
|
|
|
sopts.omit_version_numbers= 0;
|
|
|
|
sopts.allow_deep_paths= 1;
|
|
|
|
sopts.max_37_char_filenames= 0;
|
|
|
|
sopts.no_force_dots= 0;
|
|
|
|
sopts.allow_lowercase= 0;
|
|
|
|
sopts.allow_full_ascii= 0;
|
|
|
|
sopts.joliet_longer_paths= 0;
|
|
|
|
sopts.copy_eltorito= 1;
|
|
|
|
sopts.sort_files= 1;
|
|
|
|
sopts.replace_dir_mode= 2*!!xorriso->do_global_mode;
|
|
|
|
sopts.dir_mode= xorriso->global_dir_mode;
|
|
|
|
sopts.replace_file_mode= 2*!!xorriso->do_global_mode;
|
|
|
|
sopts.file_mode= xorriso->global_file_mode;
|
|
|
|
sopts.replace_uid= 2*!!xorriso->do_global_uid;
|
|
|
|
sopts.uid= xorriso->global_uid;
|
|
|
|
sopts.replace_gid= 2*!!xorriso->do_global_gid;
|
|
|
|
sopts.gid= xorriso->global_gid;
|
|
|
|
sopts.output_charset= NULL;
|
|
|
|
sopts.fifo_size= xorriso->fs * 2048;
|
|
|
|
|
|
|
|
if(xorriso->out_drive_handle == xorriso->in_drive_handle ||
|
|
|
|
xorriso->in_drive_handle == NULL) {
|
|
|
|
ret= isoburn_prepare_disc(drive, &disc, &sopts);
|
|
|
|
} else {
|
|
|
|
s= isoburn_disc_get_status(drive);
|
|
|
|
if(s!=BURN_DISC_BLANK) {
|
|
|
|
s= burn_disc_get_status(drive);
|
|
|
|
if(s!=BURN_DISC_BLANK)
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-indev differs from -outdev and -outdev media is not blank");
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-indev differs from -outdev and -outdev media holds valid ISO image");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &source_dinfo, &source_drive,
|
|
|
|
"on attempt to get source for write", 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
ret= isoburn_prepare_new_image(source_drive, &disc, &sopts);
|
|
|
|
}
|
|
|
|
if (ret <= 0) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"Failed to prepare session write run");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret= Xorriso_make_write_options(xorriso, drive, &burn_options, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
|
|
|
|
ret= burn_disc_get_sectors(disc);
|
|
|
|
if(flag&1)
|
|
|
|
goto ex;
|
|
|
|
|
|
|
|
media_space= burn_disc_available_space(drive, burn_options) / (off_t) 2048;
|
|
|
|
if(media_space < ret) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"Image size %ds exceeds free space on media %ds",
|
|
|
|
ret, media_space);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
isoburn_disc_write(burn_options, disc);
|
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
|
|
|
ret= Xorriso_pacifier_loop(xorriso, drive, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
if(!isoburn_drive_wrote_well(drive)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"libburn indicates failure with writing.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
sessions= burn_disc_get_sessions(disc, &num_sessions);
|
|
|
|
if(num_sessions>0) {
|
|
|
|
tracks= burn_session_get_tracks(sessions[0], &num_tracks);
|
|
|
|
if(tracks!=NULL && num_tracks>0) {
|
|
|
|
burn_track_get_counters(tracks[0],&readcounter,&writecounter);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"ISO image produced: %d sectors. Written to media: %d sectors\n",
|
|
|
|
(int) readcounter/2048, (int) writecounter/2048);
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret= isoburn_activate_session(drive);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Could not write new set of volume descriptors");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
goto ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "Writing completed sucessfully.\n\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(disc!=NULL)
|
|
|
|
burn_disc_free(disc);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
int ret, size, free_bytes, i;
|
|
|
|
struct burn_progress progress;
|
|
|
|
char *status_text;
|
|
|
|
enum burn_drive_status drive_status;
|
|
|
|
double start_time, current_time;
|
|
|
|
|
|
|
|
start_time= Sfile_microtime(0);
|
|
|
|
while(burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
|
|
|
usleep(100002);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
drive_status= burn_drive_get_status(drive, &progress);
|
|
|
|
if(drive_status == BURN_DRIVE_IDLE)
|
|
|
|
break;
|
|
|
|
current_time= Sfile_microtime(0);
|
|
|
|
if(drive_status == BURN_DRIVE_WRITING && progress.sectors > 0) {
|
|
|
|
sprintf(xorriso->info_text, "Writing: sector %d of %d",
|
|
|
|
progress.sector, progress.sectors);
|
|
|
|
ret= isoburn_get_fifo_status(drive, &size, &free_bytes, &status_text);
|
|
|
|
if(ret>0 )
|
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" [fifo %s, %2d%% fill]", status_text,
|
|
|
|
(int) (100.0-100.0*((double) free_bytes)/(double) size));
|
|
|
|
} else if(drive_status == BURN_DRIVE_CLOSING_SESSION ||
|
|
|
|
drive_status == BURN_DRIVE_CLOSING_TRACK)
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Closing track/session. Working since %.f seconds",
|
|
|
|
current_time-start_time);
|
|
|
|
else if(drive_status == BURN_DRIVE_FORMATTING)
|
|
|
|
sprintf(xorriso->info_text, "Formatting. Working since %.f seconds",
|
|
|
|
current_time-start_time);
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Thank you for being patient since %.f seconds",
|
|
|
|
current_time-start_time);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
|
|
|
|
|
|
|
for(i= 0; i<10; i++) {
|
|
|
|
Xorriso_process_msg_queues(xorriso, 0);
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
if(xorriso->in_volset_handle==NULL) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"No ISO image present.");
|
|
|
|
if(xorriso->indev[0]==0 && xorriso->outdev[0]==0)
|
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" No -dev, -indev, or -outdev selected.");
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" Possible program error with drive '%s'.", xorriso->indev);
|
|
|
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
*volume= (IsoImage *) xorriso->in_volset_handle;
|
|
|
|
return(*volume != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0=do not complain about non existent node */
|
|
|
|
int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
|
|
|
|
char *path, IsoNode **node, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char sfe[5*SfileadrL], *path_pt;
|
|
|
|
|
|
|
|
path_pt= path;
|
|
|
|
if(path[0]==0)
|
|
|
|
path_pt= "/";
|
|
|
|
*node= NULL;
|
|
|
|
ret= iso_tree_path_to_node(volume, path_pt, node);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(ret<=0) {
|
|
|
|
if(!(flag&1)) {
|
|
|
|
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image",
|
|
|
|
Text_shellsafe(path_pt, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param eff_path returns resulting effective path.
|
|
|
|
Must provide at least SfileadrL bytes of storage.
|
|
|
|
@param flag bit0= do not produce problem events (unless faulty path format)
|
|
|
|
bit1= work purely literally, do not use libisofs
|
|
|
|
bit2= (with bit1) this is an address in the disk world
|
|
|
|
@return -1 = faulty path format, 0 = not found ,
|
|
|
|
1 = found simple node , 2 = found directory
|
|
|
|
*/
|
|
|
|
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
|
|
|
|
char *img_path, char eff_path[], int flag)
|
|
|
|
{
|
|
|
|
int ret, is_dir= 0, done= 0;
|
|
|
|
IsoImage *volume;
|
|
|
|
IsoDir *dir= NULL;
|
|
|
|
IsoNode *node= NULL;
|
|
|
|
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL], *cpt;
|
|
|
|
|
|
|
|
eff_path[0]= 0;
|
|
|
|
if(img_path[0]==0)
|
|
|
|
return(2); /* root directory */
|
|
|
|
|
|
|
|
if(!(flag&2)) {
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
apt= npt= path;
|
|
|
|
if(img_path[0]!='/') {
|
|
|
|
strcpy(path, wd);
|
|
|
|
ret= Sfile_add_to_path(path, img_path, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto much_too_long;
|
|
|
|
} else
|
|
|
|
if(Sfile_str(path, img_path, 0)<=0)
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
if(path[0]!='/') {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Internal error: Unresolvable relative addressing in iso_rr_path '%s'",
|
|
|
|
img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
} else if(path[1]==0)
|
|
|
|
return(2); /* root directory */
|
|
|
|
|
|
|
|
for(npt= apt; !done; apt= npt+1) {
|
|
|
|
npt= strchr(apt, '/');
|
|
|
|
if(npt==NULL) {
|
|
|
|
npt= apt+strlen(apt);
|
|
|
|
done= 1;
|
|
|
|
} else
|
|
|
|
*npt= 0;
|
|
|
|
if(*apt==0) {
|
|
|
|
*apt= '/';
|
|
|
|
apt++;
|
|
|
|
if(done)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(strcmp(apt,".")==0)
|
|
|
|
continue;
|
|
|
|
if(strcmp(apt,"..")==0) {
|
|
|
|
if(!(flag&2)) {
|
|
|
|
node= (IsoNode *) dir;
|
|
|
|
if(node==NULL) {
|
|
|
|
bonked_root:;
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Relative addressing in path exceeds root directory: %s",
|
|
|
|
Text_shellsafe(img_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
dir= iso_node_get_parent(node);
|
|
|
|
}
|
|
|
|
/* truncate eff_path */;
|
|
|
|
cpt= strrchr(eff_path, '/');
|
|
|
|
if(cpt==NULL) /* ??? if not flag&2 then this is a bug */
|
|
|
|
goto bonked_root;
|
|
|
|
*cpt= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret= Sfile_add_to_path(eff_path, apt, 0);
|
|
|
|
if(ret<=0) {
|
|
|
|
much_too_long:;
|
|
|
|
sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
|
|
|
|
(int) (strlen(eff_path)+strlen(apt)+1));
|
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if(!(flag&2)) {
|
|
|
|
dir= (IsoDir *) node;
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, eff_path, &node, flag&1);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
if(dir==NULL) /* could be false with "/dir/.." */
|
|
|
|
dir= iso_node_get_parent(node);
|
|
|
|
is_dir= LIBISO_ISDIR(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1+!!is_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_get_node_by_path(struct XorrisO *xorriso,
|
|
|
|
char *in_path, char *eff_path,
|
|
|
|
IsoNode **node, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char path[SfileadrL];
|
|
|
|
IsoImage *volume;
|
|
|
|
|
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(eff_path!=NULL)
|
|
|
|
strcpy(eff_path, path);
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
|
|
|
|
IsoNode *node, int flag)
|
|
|
|
{
|
|
|
|
iso_node_set_permissions(node, stbuf->st_mode & 07777);
|
|
|
|
iso_node_set_uid(node, stbuf->st_uid);
|
|
|
|
iso_node_set_gid(node, stbuf->st_gid);
|
|
|
|
iso_node_set_atime(node, stbuf->st_atime);
|
|
|
|
iso_node_set_mtime(node, stbuf->st_mtime);
|
|
|
|
iso_node_set_ctime(node, stbuf->st_ctime);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= recursion is active */
|
|
|
|
int Xorriso_add_tree(struct XorrisO *xorriso, IsoDir *dir,
|
|
|
|
char *img_dir_path, char *disk_dir_path,
|
|
|
|
struct LinkiteM *link_stack, int flag)
|
|
|
|
{
|
|
|
|
IsoImage *volume;
|
|
|
|
IsoNode *node;
|
|
|
|
int ret, target_is_dir, source_is_dir, source_is_link, fret, was_failure= 0;
|
|
|
|
int do_not_dive;
|
|
|
|
struct DirseQ *dirseq= NULL;
|
|
|
|
char *name, *img_name, *srcpt;
|
|
|
|
struct stat stbuf, hstbuf;
|
|
|
|
dev_t dir_dev;
|
|
|
|
struct LinkiteM *own_link_stack;
|
|
|
|
|
|
|
|
#ifdef Xorriso_fat_local_meM
|
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
|
|
|
char disk_path[2*SfileadrL], img_path[2*SfileadrL], link_target[SfileadrL];
|
|
|
|
#else /* Xorriso_fat_local_meM */
|
|
|
|
|
|
|
|
char *sfe= NULL, *sfe2= NULL;
|
|
|
|
char *disk_path= NULL, *img_path= NULL, *link_target= NULL;
|
|
|
|
|
|
|
|
/* Avoiding large local memory objects in order to save stack space */
|
|
|
|
sfe= malloc(5*SfileadrL);
|
|
|
|
sfe2= malloc(5*SfileadrL);
|
|
|
|
disk_path= malloc(2*SfileadrL);
|
|
|
|
img_path= malloc(2*SfileadrL);
|
|
|
|
link_target= malloc(SfileadrL);
|
|
|
|
if(sfe==NULL || sfe2==NULL || disk_path==NULL || img_path==NULL ||
|
|
|
|
link_target==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
|
|
|
own_link_stack= link_stack;
|
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
|
|
|
|
if(lstat(disk_dir_path, &stbuf)==-1)
|
|
|
|
goto cannot_open_dir;
|
|
|
|
dir_dev= stbuf.st_dev;
|
|
|
|
if(S_ISLNK(stbuf.st_mode)) {
|
|
|
|
if(!(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&1))))
|
|
|
|
{ret= 2; goto ex;}
|
|
|
|
if(stat(disk_dir_path, &stbuf)==-1)
|
|
|
|
goto cannot_open_dir;
|
|
|
|
if(dir_dev != stbuf.st_dev &&
|
|
|
|
!(xorriso->do_follow_mount || (xorriso->do_follow_param && !(flag&1))))
|
|
|
|
{ret= 2; goto ex;}
|
|
|
|
}
|
|
|
|
ret= Dirseq_new(&dirseq, disk_dir_path, 1);
|
|
|
|
if(ret<0) {
|
|
|
|
sprintf(xorriso->info_text,"Failed to create source filesystem iterator");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
if(ret==0) {
|
|
|
|
cannot_open_dir:;
|
|
|
|
sprintf(xorriso->info_text,"Cannot open as source directory: %s",
|
|
|
|
Text_shellsafe(disk_dir_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Sfile_str(disk_path, disk_dir_path,0)<=0)
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
if(disk_path[0]==0 || disk_path[strlen(disk_path)-1]!='/')
|
|
|
|
strcat(disk_path,"/");
|
|
|
|
name= disk_path+strlen(disk_path);
|
|
|
|
if(Sfile_str(img_path, img_dir_path, 0)<=0)
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
if(img_path[0] || img_path[strlen(img_path)-1]!='/')
|
|
|
|
strcat(img_path,"/");
|
|
|
|
img_name= img_path+strlen(img_path);
|
|
|
|
|
|
|
|
while(1) { /* loop over directory content */
|
|
|
|
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
|
|
|
srcpt= disk_path;
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
ret= Dirseq_next_adr(dirseq,name,0);
|
|
|
|
if(ret==0)
|
|
|
|
break;
|
|
|
|
if(ret<0) {
|
|
|
|
sprintf(xorriso->info_text,"Failed to obtain next directory entry");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
strcpy(img_name, name);
|
|
|
|
if(Xorriso_much_too_long(xorriso, strlen(img_path), 0)<=0)
|
|
|
|
{ret= 0; goto was_problem;}
|
|
|
|
if(Xorriso_much_too_long(xorriso, strlen(srcpt), 0)<=0)
|
|
|
|
{ret= 0; goto was_problem;}
|
|
|
|
if(lstat(srcpt, &stbuf)==-1) {
|
|
|
|
cannot_lstat:;
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot determine attributes of source file %s",
|
|
|
|
Text_shellsafe(srcpt, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
|
|
|
ret= 0; goto was_problem;
|
|
|
|
}
|
|
|
|
source_is_dir= 0;
|
|
|
|
source_is_link= S_ISLNK(stbuf.st_mode);
|
|
|
|
if(xorriso->do_follow_links && source_is_link) {
|
|
|
|
/* Xorriso_hop_link checks for wide link loops */
|
|
|
|
ret= Xorriso_hop_link(xorriso, srcpt, &own_link_stack, &hstbuf, 0);
|
|
|
|
if(ret<0)
|
|
|
|
goto was_problem;
|
|
|
|
if(ret==1) {
|
|
|
|
ret= Xorriso_resolve_link(xorriso, srcpt, link_target, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
|
|
|
srcpt= link_target;
|
|
|
|
if(lstat(srcpt, &stbuf)==-1)
|
|
|
|
goto cannot_lstat;
|
|
|
|
} else {
|
|
|
|
if(Xorriso_eval_problem_status(xorriso, 0, 1|2)<0)
|
|
|
|
{ret= 0; goto was_problem;}
|
|
|
|
}
|
|
|
|
} else if (S_ISLNK(stbuf.st_mode)) {
|
|
|
|
ret= Xorriso_resolve_link(xorriso, srcpt, link_target, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
|
|
|
}
|
|
|
|
do_not_dive= 0;
|
|
|
|
if(S_ISDIR(stbuf.st_mode)) {
|
|
|
|
source_is_dir= 1;
|
|
|
|
if(dir_dev != stbuf.st_dev && !xorriso->do_follow_mount)
|
|
|
|
do_not_dive= 1;
|
|
|
|
|
|
|
|
#ifdef NIX
|
|
|
|
} else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
|
|
|
|
sprintf(xorriso->info_text,"Source file %s %s non-supported file type",
|
|
|
|
Text_shellsafe(disk_path, sfe, 0),
|
|
|
|
source_is_link ? "leads to" : "is of");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto was_problem;
|
|
|
|
#endif /* NIX */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* does a node exist with this name ? */
|
|
|
|
node= NULL;
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, img_path, &node, 1);
|
|
|
|
if(ret>0) {
|
|
|
|
target_is_dir= LIBISO_ISDIR(node);
|
|
|
|
if(!(target_is_dir && source_is_dir)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
|
|
|
/* handle overwrite situation */;
|
|
|
|
if(xorriso->do_overwrite==1 ||
|
|
|
|
(xorriso->do_overwrite==2 && !target_is_dir)) {
|
|
|
|
ret= Xorriso_rmi(xorriso, NULL, img_path, 1|8);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
|
|
|
if(ret==3) {
|
|
|
|
sprintf(xorriso->info_text, "User revoked adding of: %s",
|
|
|
|
Text_shellsafe(img_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
ret= 0; goto was_problem;
|
|
|
|
}
|
|