2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* 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 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>
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
/* The official xorriso options API. "No shortcuts" */
|
|
|
|
#include "xorriso.h"
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
/* The inner description of XorrisO */
|
|
|
|
#include "xorriso_private.h"
|
|
|
|
|
|
|
|
/* The inner isofs- and burn-library interface */
|
|
|
|
#include "xorrisoburn.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *handler_prefix= NULL;
|
2007-10-17 13:02:32 +00:00
|
|
|
char *queue_sev, *print_sev;
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Starting up libraries ...\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
|
|
|
|
if(handler_prefix==NULL) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot allocate memory for initializing libraries");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
ret= isoburn_initialize();
|
|
|
|
if(ret==0) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Cannot initialize libraries");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
free(handler_prefix);
|
|
|
|
return(0);
|
|
|
|
}
|
2007-10-18 18:57:19 +00:00
|
|
|
xorriso->libs_are_started= 1;
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
queue_sev= "DEBUG";
|
|
|
|
if(xorriso->library_msg_direct_print) {
|
|
|
|
|
|
|
|
/* >>> need option for controlling this in XorrisO.
|
|
|
|
See also Xorriso_msgs_submit */;
|
|
|
|
|
2007-10-19 16:49:37 +00:00
|
|
|
print_sev= xorriso->report_about_text;
|
2007-10-17 13:02:32 +00:00
|
|
|
} else
|
|
|
|
print_sev= "NEVER";
|
|
|
|
iso_msgs_set_severities(queue_sev, print_sev, "libisofs : ");
|
|
|
|
burn_msgs_set_severities(queue_sev, print_sev, "libburn : ");
|
2007-10-16 21:09:36 +00:00
|
|
|
|
|
|
|
/* ??? >>> do we want united queues ? */
|
|
|
|
/* burn_set_messenger(iso_get_messenger()); */
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
sprintf(handler_prefix, "%s : ", xorriso->progname);
|
2007-10-15 15:27:51 +00:00
|
|
|
burn_set_signal_handling(handler_prefix, NULL, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Library startup done.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
free(handler_prefix);
|
|
|
|
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);
|
|
|
|
sprintf(xorriso->info_text, "No drive aquired %s", attempt);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
/* @param flag bit0=aquire as isoburn input drive
|
|
|
|
bit1=aquire as libburn output drive (as isoburn drive if bit0)
|
|
|
|
*/
|
|
|
|
int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct burn_drive_info *dinfo= NULL;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
enum burn_disc_status state;
|
|
|
|
struct iso_volset *volset;
|
|
|
|
struct isoburn_read_opts ropts;
|
|
|
|
|
|
|
|
|
|
|
|
if((flag&3)!=3) {
|
2007-10-16 21:09:36 +00:00
|
|
|
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);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
ret= Xorriso_give_up_drive(xorriso, flag&3);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
ret= isoburn_drive_scan_and_grab(&dinfo, adr, 1);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
if(ret<=0) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,"Cannot aquire drive '%s'", adr);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
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-10-19 20:41:34 +00:00
|
|
|
if(Sfile_str(xorriso->indev, adr, 0)<=0)
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if(flag&1) {
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->in_drive_handle= dinfo;
|
2007-10-19 20:41:34 +00:00
|
|
|
if(Sfile_str(xorriso->outdev, adr, 0)<=0)
|
|
|
|
return(-1);
|
|
|
|
} else
|
2007-10-15 15:27:51 +00:00
|
|
|
return(1);
|
|
|
|
|
|
|
|
drive= dinfo[0].drive;
|
|
|
|
|
|
|
|
/* check for invalid state */
|
|
|
|
state= isoburn_disc_get_status(drive);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
/* >>> show drive and media status */;
|
|
|
|
|
|
|
|
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
|
2007-10-20 17:10:04 +00:00
|
|
|
sprintf(xorriso->info_text, "Disc status unsuitable for writing");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
/* fill read opts */
|
|
|
|
ropts.norock= 0;
|
|
|
|
ropts.nojoliet= 0;
|
|
|
|
ropts.preferjoliet= 0;
|
|
|
|
ropts.uid= 0;
|
|
|
|
ropts.gid= 0;
|
|
|
|
ropts.mode= 0555;
|
|
|
|
|
|
|
|
if(isoburn_read_volset(drive, &ropts, &volset) <= 0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-17 20:02:45 +00:00
|
|
|
sprintf(xorriso->info_text,"Cannot read ISO image volset");
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
|
|
|
xorriso->in_volset_handle= volset;
|
|
|
|
ret= 1;
|
|
|
|
ex:
|
2007-10-18 22:56:43 +00:00
|
|
|
if(ret<0) {
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-18 22:56:43 +00:00
|
|
|
/* >>> give up drive */;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
}
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,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-10-15 15:27:51 +00:00
|
|
|
*/
|
|
|
|
int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int in_is_out_too;
|
|
|
|
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) {
|
2007-10-18 18:32:32 +00:00
|
|
|
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to give drive up", 0);
|
2007-10-19 17:35:20 +00:00
|
|
|
if(drive!=NULL)
|
|
|
|
isoburn_drive_release(drive,!!(flag&4));
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-18 22:56:43 +00:00
|
|
|
if(xorriso->in_volset_handle!=NULL)
|
|
|
|
iso_volset_free((struct iso_volset *) xorriso->in_volset_handle);
|
2007-10-18 14:48:35 +00:00
|
|
|
xorriso->in_volset_handle= NULL;
|
2007-10-15 22:40:39 +00:00
|
|
|
xorriso->volset_change_pending= 0;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-19 17:35:20 +00:00
|
|
|
if(dinfo!=NULL)
|
|
|
|
burn_drive_info_free(dinfo);
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->in_drive_handle= NULL;
|
2007-10-18 17:14:09 +00:00
|
|
|
xorriso->indev[0]= 0;
|
|
|
|
if(in_is_out_too) {
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->out_drive_handle= NULL;
|
2007-10-18 17:14:09 +00:00
|
|
|
xorriso->outdev[0]= 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 drive up", 2);
|
2007-10-19 17:35:20 +00:00
|
|
|
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-10-15 15:27:51 +00:00
|
|
|
}
|
2007-10-17 13:02:32 +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)
|
|
|
|
{
|
|
|
|
*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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-19 15:13:16 +00:00
|
|
|
/* @param flag bit0= do not write but only prepare and return size in sectors
|
|
|
|
*/
|
2007-10-15 15:27:51 +00:00
|
|
|
int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-20 19:48:36 +00:00
|
|
|
int ret, media_space;
|
2007-10-15 15:27:51 +00:00
|
|
|
struct isoburn_source_opts sopts;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
2007-10-18 22:17:46 +00:00
|
|
|
struct burn_disc *disc= NULL;
|
2007-10-15 15:27:51 +00:00
|
|
|
struct burn_write_opts *burn_options;
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to write", 2);
|
|
|
|
if(ret<=0)
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
sopts.level= 2;
|
|
|
|
sopts.flags= ECMA119_ROCKRIDGE;
|
|
|
|
if(xorriso->do_joliet)
|
2007-10-17 22:49:26 +00:00
|
|
|
sopts.flags|= ECMA119_JOLIET;
|
2007-10-15 15:27:51 +00:00
|
|
|
sopts.relaxed_constraints= 0;
|
|
|
|
sopts.copy_eltorito= 1;
|
|
|
|
sopts.no_cache_inodes= 0;
|
|
|
|
sopts.sort_files= 1;
|
|
|
|
sopts.default_mode= 0;
|
|
|
|
sopts.replace_dir_mode= 0;
|
|
|
|
sopts.dir_mode= 0555;
|
|
|
|
sopts.replace_file_mode= 0;
|
|
|
|
sopts.file_mode= 0444;
|
|
|
|
sopts.replace_uid= (xorriso->do_global_uid);
|
|
|
|
sopts.uid= xorriso->global_uid;
|
|
|
|
sopts.replace_gid= (xorriso->do_global_gid);
|
|
|
|
sopts.gid= xorriso->global_gid;
|
|
|
|
sopts.input_charset= NULL;
|
|
|
|
sopts.ouput_charset= NULL;
|
|
|
|
|
|
|
|
/* >>> -fs : isoburn_prepare_disc() needs fifo parameters */
|
|
|
|
|
|
|
|
if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,"Cannot prepare disc");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-18 22:17:46 +00:00
|
|
|
{ret= 0; goto ex;}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_make_write_options(xorriso, drive, &burn_options, 0);
|
|
|
|
if(ret<=0)
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-19 15:13:16 +00:00
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
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;}
|
|
|
|
}
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
isoburn_disc_write(burn_options, disc);
|
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
|
|
|
ret= Xorriso_pacifier_loop(xorriso, drive, 0);
|
|
|
|
if(ret<=0)
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-20 17:10:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
ret= isoburn_activate_session(drive);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
if(ret<=0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Could not write new set of volume descriptors");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2007-10-20 17:10:04 +00:00
|
|
|
|
2007-10-18 22:17:46 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(disc!=NULL)
|
|
|
|
burn_disc_free(disc);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-18 22:17:46 +00:00
|
|
|
return(ret);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-10-20 17:10:04 +00:00
|
|
|
enum burn_drive_status drive_status;
|
|
|
|
double start_time, current_time;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
start_time= Sfile_microtime(0);
|
2007-10-15 15:27:51 +00:00
|
|
|
while(burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
|
|
|
usleep(100002);
|
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
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) {
|
|
|
|
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);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
for(i= 0; i<10; i++) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso, 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
struct iso_volume *volume;
|
|
|
|
struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0};
|
|
|
|
char path[SfileadrL], *apt, *npt;
|
|
|
|
struct iso_tree_node_dir *dir;
|
|
|
|
struct iso_tree_node *node;
|
2007-10-15 20:37:53 +00:00
|
|
|
int done= 0, is_dir= 0, l;
|
2007-10-15 15:27:51 +00:00
|
|
|
struct stat stbuf;
|
|
|
|
|
2007-10-15 20:37:53 +00:00
|
|
|
if(xorriso->in_volset_handle==NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,"No volset is loaded.");
|
2007-10-15 20:37:53 +00:00
|
|
|
if(xorriso->indev[0]==0)
|
2007-10-18 18:32:32 +00:00
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" No -dev or -indev is selected.");
|
2007-10-15 20:37:53 +00:00
|
|
|
else
|
2007-10-18 18:32:32 +00:00
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" Possible program error with drive '%s'.", xorriso->indev);
|
2007-10-15 20:37:53 +00:00
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 20:37:53 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
strncpy(path, img_path, sizeof(path)-1);
|
|
|
|
path[sizeof(path)-1]= 0;
|
|
|
|
apt= npt= path;
|
|
|
|
volume= iso_volset_get_volume(
|
|
|
|
(struct iso_volset *) xorriso->in_volset_handle, 0);
|
|
|
|
|
|
|
|
if(lstat(disk_path, &stbuf) == -1) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot determine attributes of source file '%s'",disk_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2007-10-15 20:37:53 +00:00
|
|
|
if(S_ISDIR(stbuf.st_mode))
|
|
|
|
is_dir= 1;
|
2007-10-15 15:27:51 +00:00
|
|
|
else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Source file '%s' is of non-supported file type", disk_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
2007-10-15 20:37:53 +00:00
|
|
|
} else {
|
|
|
|
l= strlen(img_path);
|
|
|
|
if(l>0)
|
|
|
|
if(img_path[l-1]=='/')
|
|
|
|
l= 0;
|
|
|
|
if(l==0) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Source '%s' is not a directory. Target '%s' would be.",
|
2007-10-15 20:37:53 +00:00
|
|
|
disk_path, img_path);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 20:37:53 +00:00
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dir= iso_volume_get_root(volume);
|
|
|
|
if(dir==NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s' : no root node available", img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
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++;
|
2007-10-15 20:37:53 +00:00
|
|
|
if(done)
|
|
|
|
goto attach_source;
|
2007-10-15 15:27:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
node= iso_tree_volume_path_to_node(volume,path);
|
|
|
|
if(node!=NULL) {
|
|
|
|
if(iso_tree_node_get_type(node)!=LIBISO_NODE_DIR) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-15 20:37:53 +00:00
|
|
|
if(done) {
|
|
|
|
|
|
|
|
/* >>> handle overwrite situation */;
|
|
|
|
|
|
|
|
}
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s' : '%s' exists and is not a directory",
|
2007-10-15 20:37:53 +00:00
|
|
|
img_path, path);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
dir= (struct iso_tree_node_dir *) node;
|
2007-10-15 20:37:53 +00:00
|
|
|
} else if(is_dir || !done) {
|
2007-10-15 15:27:51 +00:00
|
|
|
dir= iso_tree_add_dir(dir, apt);
|
|
|
|
if(dir==NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s' : could not insert '%s'", img_path, path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(done) {
|
2007-10-15 20:37:53 +00:00
|
|
|
attach_source:;
|
2007-10-15 15:27:51 +00:00
|
|
|
if(is_dir) {
|
|
|
|
iso_tree_radd_dir(dir, disk_path, &behav);
|
|
|
|
} else {
|
|
|
|
node= iso_tree_add_node(dir, disk_path);
|
|
|
|
if(node == NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s'='%s' : libisofs_errno = %d",
|
|
|
|
img_path, disk_path, libisofs_errno);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2007-10-15 20:37:53 +00:00
|
|
|
iso_tree_node_set_name(node, apt);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
*npt= '/';
|
|
|
|
}
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-19 14:00:06 +00:00
|
|
|
sprintf(xorriso->info_text, "Added %s '%s'='%s'\n",
|
|
|
|
(is_dir ? "directory" : "node"), img_path, disk_path);
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-16 21:09:36 +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
|
|
|
|
ret= burn_text_to_sev(severity_name, severity_number, 0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret, error_code= 0, os_errno= 0, count= 0, pass;
|
|
|
|
char severity[80];
|
|
|
|
|
2007-10-18 18:57:19 +00:00
|
|
|
if(!xorriso->libs_are_started)
|
|
|
|
return(1);
|
2007-10-17 13:02:32 +00:00
|
|
|
for(pass= 0; pass< 2; pass++) {
|
|
|
|
while(1) {
|
|
|
|
if(pass==0)
|
|
|
|
ret= iso_msgs_obtain("ALL", &error_code, xorriso->info_text, &os_errno,
|
|
|
|
severity);
|
|
|
|
else
|
|
|
|
ret= burn_msgs_obtain("ALL", &error_code, xorriso->info_text, &os_errno,
|
|
|
|
severity);
|
|
|
|
if(ret<=0)
|
|
|
|
break;
|
|
|
|
Xorriso_msgs_submit(xorriso, error_code, xorriso->info_text, os_errno,
|
2007-10-17 15:01:49 +00:00
|
|
|
severity, (pass+1)<<2);
|
2007-10-17 13:02:32 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(xorriso->library_msg_direct_print && count>0) {
|
|
|
|
sprintf(xorriso->info_text," (%d library messages repeated by xorriso)\n",
|
|
|
|
count);
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
|
|
|
|
int Xorriso_toc(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-17 20:02:45 +00:00
|
|
|
int num_sessions= 0, num_tracks= 0, lba= 0, nwa= 0, pmin, psec, pframe, ret;
|
2007-10-17 18:30:37 +00:00
|
|
|
int track_count= 0, session_no, track_no, profile_no= -1;
|
|
|
|
int last_track_start= 0, last_track_size= -1;
|
|
|
|
char profile_name[80],*respt;
|
|
|
|
struct burn_disc *disc= NULL;
|
|
|
|
struct burn_session **sessions;
|
|
|
|
struct burn_track **tracks;
|
|
|
|
struct burn_toc_entry toc_entry;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
enum burn_disc_status s;
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to print Table Of Content", 2);
|
|
|
|
if(ret<=0)
|
2007-10-17 18:30:37 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
respt= xorriso->result_line;
|
|
|
|
|
2007-10-17 20:02:45 +00:00
|
|
|
sprintf(respt, "Drive current: -indev '%s'\n", xorriso->indev);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
sprintf(respt, "Drive type : vendor '%s' product '%s' revision '%s'\n",
|
|
|
|
dinfo[0].vendor, dinfo[0].product, dinfo[0].revision);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
sprintf(respt, "Media current: ");
|
|
|
|
ret= burn_disc_get_profile(drive, &profile_no, profile_name);
|
|
|
|
if (profile_no > 0 && ret > 0) {
|
|
|
|
if (profile_name[0])
|
|
|
|
sprintf(respt+strlen(respt), "%s\n", profile_name);
|
|
|
|
else
|
|
|
|
sprintf(respt+strlen(respt), "%4.4Xh\n", profile_no);
|
|
|
|
} else
|
|
|
|
sprintf(respt+strlen(respt), "is not recognizable\n");
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
|
|
|
|
sprintf(respt, "Media status : ");
|
|
|
|
s= isoburn_disc_get_status(drive);
|
|
|
|
if (s == BURN_DISC_FULL) {
|
|
|
|
sprintf(respt+strlen(respt), "is written , is closed\n");
|
|
|
|
} else if (s == BURN_DISC_APPENDABLE) {
|
|
|
|
sprintf(respt+strlen(respt), "is written , is appendable\n");
|
|
|
|
} else if (s == BURN_DISC_BLANK) {
|
|
|
|
sprintf(respt+strlen(respt), "is blank\n");
|
|
|
|
} else if (s == BURN_DISC_EMPTY)
|
|
|
|
sprintf(respt+strlen(respt), "is not present\n");
|
|
|
|
else
|
|
|
|
sprintf(respt+strlen(respt), "is not recognizable\n");
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
|
2007-10-17 21:42:37 +00:00
|
|
|
if(s != BURN_DISC_FULL && s != BURN_DISC_APPENDABLE)
|
2007-10-17 18:30:37 +00:00
|
|
|
return(1);
|
|
|
|
|
|
|
|
disc= burn_drive_get_disc(drive);
|
|
|
|
if (disc==NULL) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-17 21:42:37 +00:00
|
|
|
|
|
|
|
#define Xorriso_with_isoburn_get_min_start_bytE 1
|
|
|
|
#ifdef Xorriso_with_isoburn_get_min_start_bytE
|
|
|
|
{ off_t start_byte= 0;
|
|
|
|
ret= isoburn_get_min_start_byte(drive, &start_byte, 0);
|
|
|
|
nwa= start_byte / 2048;
|
|
|
|
}
|
|
|
|
#else
|
2007-10-17 18:30:37 +00:00
|
|
|
ret= isoburn_disc_track_lba_nwa(drive, NULL, 0, &lba, &nwa);
|
2007-10-17 21:42:37 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text, "Cannot obtain Table Of Content");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* fabricate TOC */
|
|
|
|
sprintf(respt, "Media content: session %2d ", 1);
|
|
|
|
sprintf(respt+strlen(respt), "track %2d %s lba: %9d\n", 1, "data ", 0);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
last_track_start= lba;
|
|
|
|
sprintf(respt, "Media content: session %2d ", 1);
|
|
|
|
sprintf(respt+strlen(respt), "leadout lba: %9d\n", nwa);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
last_track_size= nwa;
|
|
|
|
} else {
|
|
|
|
sessions= burn_disc_get_sessions(disc, &num_sessions);
|
|
|
|
for (session_no= 0; session_no<num_sessions; session_no++) {
|
|
|
|
tracks = burn_session_get_tracks(sessions[session_no], &num_tracks);
|
|
|
|
if (tracks==NULL)
|
|
|
|
continue;
|
|
|
|
for(track_no= 0; track_no<num_tracks; track_no++) {
|
|
|
|
track_count++;
|
|
|
|
burn_track_get_entry(tracks[track_no], &toc_entry);
|
|
|
|
if (toc_entry.extensions_valid & 1) {
|
|
|
|
/* DVD extension valid */
|
|
|
|
lba= toc_entry.start_lba;
|
|
|
|
} else {
|
|
|
|
lba= burn_msf_to_lba(toc_entry.pmin, toc_entry.psec, toc_entry.pframe);
|
|
|
|
}
|
|
|
|
sprintf(respt, "Media content: session %2d ", session_no+1);
|
|
|
|
sprintf(respt+strlen(respt), "track %2d %s lba: %9d\n",
|
|
|
|
track_count, ((toc_entry.control&7)<4?"audio":"data "), lba);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
last_track_start= lba;
|
|
|
|
}
|
|
|
|
burn_session_get_leadout_entry(sessions[session_no], &toc_entry);
|
|
|
|
if (toc_entry.extensions_valid & 1) {
|
|
|
|
lba= toc_entry.start_lba;
|
|
|
|
burn_lba_to_msf(lba, &pmin, &psec, &pframe);
|
|
|
|
} else {
|
|
|
|
lba= burn_msf_to_lba(pmin, psec, pframe);
|
|
|
|
lba= burn_msf_to_lba(toc_entry.pmin, toc_entry.psec, toc_entry.pframe);
|
|
|
|
}
|
|
|
|
sprintf(respt, "Media content: session %2d ", session_no+1);
|
2007-10-17 20:02:45 +00:00
|
|
|
sprintf(respt+strlen(respt), "leadout lba: %9d\n", lba);
|
2007-10-17 18:30:37 +00:00
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
last_track_size= lba - last_track_start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:02:45 +00:00
|
|
|
if (s == BURN_DISC_APPENDABLE && nwa>0) {
|
2007-10-17 21:42:37 +00:00
|
|
|
ret= isoburn_disc_track_lba_nwa(drive, NULL, 0, &lba, &nwa);
|
|
|
|
if(ret>0) {
|
|
|
|
sprintf(respt, "Media nwa : %ds\n", nwa);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
2007-10-17 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (disc!=NULL)
|
|
|
|
burn_disc_free(disc);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:14:09 +00:00
|
|
|
|
|
|
|
int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
char adr[BURN_DRIVE_ADR_LEN];
|
|
|
|
int i;
|
|
|
|
struct burn_drive_info *drive_list= NULL;
|
|
|
|
unsigned int drive_count;
|
|
|
|
char *respt, perms[8];
|
|
|
|
struct stat stbuf;
|
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "Beginning to scan for devices ...\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
|
|
|
|
burn_drive_clear_whitelist();
|
|
|
|
while(!burn_drive_scan(&drive_list, &drive_count)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(drive_count <= 0) {
|
|
|
|
|
|
|
|
/* >>> was a drive_list created at all ? */
|
|
|
|
/* >>> must it be freed ? */
|
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "No drives found");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Full drive scan done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
|
|
|
|
respt= xorriso->result_line;
|
|
|
|
for(i= 0; i < drive_count; i++) {
|
|
|
|
if(burn_drive_get_adr(&(drive_list[i]), adr)<=0)
|
|
|
|
strcpy(adr, "-get_adr_failed-");
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(stat(adr,&stbuf)==-1) {
|
|
|
|
sprintf(perms,"errno=%d",errno);
|
|
|
|
} else {
|
|
|
|
strcpy(perms,"------");
|
|
|
|
if(stbuf.st_mode&S_IRUSR) perms[0]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWUSR) perms[1]= 'w';
|
|
|
|
if(stbuf.st_mode&S_IRGRP) perms[2]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWGRP) perms[3]= 'w';
|
|
|
|
if(stbuf.st_mode&S_IROTH) perms[4]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWOTH) perms[5]= 'w';
|
|
|
|
}
|
|
|
|
sprintf(respt, "%d -dev '%s' %s : '%-8.8s' '%s' \n",
|
|
|
|
i, adr, perms, drive_list[i].vendor, drive_list[i].product);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
burn_drive_info_free(drive_list);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
int Xorriso_tell_media_space(struct XorrisO *xorriso,
|
|
|
|
int *media_space, int *free_space, int flag)
|
2007-10-18 18:32:32 +00:00
|
|
|
{
|
2007-10-20 19:48:36 +00:00
|
|
|
int ret;
|
2007-10-18 18:32:32 +00:00
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
struct burn_write_opts *burn_options;
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
(*free_space)= (*media_space)= 0;
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -tell_media_space", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
ret= Xorriso_make_write_options(xorriso, drive, &burn_options, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(-1);
|
2007-10-20 19:48:36 +00:00
|
|
|
(*free_space)= (*media_space)=
|
|
|
|
burn_disc_available_space(drive, burn_options) / (off_t) 2048;
|
2007-10-18 18:32:32 +00:00
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
if(xorriso->volset_change_pending) {
|
2007-10-18 18:32:32 +00:00
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
/* >>> care for modifying */
|
|
|
|
|
|
|
|
ret= Xorriso_write_growing(xorriso, 1);
|
|
|
|
if(ret>0)
|
|
|
|
(*free_space)-= ret;
|
|
|
|
}
|
2007-10-19 20:41:34 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-20 19:48:36 +00:00
|
|
|
return(1);
|
2007-10-18 18:32:32 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 20:41:34 +00:00
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
/* @param flag bit0=fast , bit1=deformat
|
|
|
|
@return 0=failure, did not touch media , -1=failure, altered media
|
|
|
|
1=success, altered media , 2=success, did not touch media
|
|
|
|
*/
|
2007-10-19 20:41:34 +00:00
|
|
|
int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-20 17:10:04 +00:00
|
|
|
int ret, do_deformat= 0;
|
2007-10-19 20:41:34 +00:00
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
enum burn_disc_status disc_state;
|
|
|
|
struct burn_progress p;
|
|
|
|
double percent = 1.0;
|
|
|
|
int current_profile;
|
|
|
|
char current_profile_name[80];
|
2007-10-20 17:10:04 +00:00
|
|
|
char mode_names[4][80]= {"all", "fast", "deformat", "deformat_quickest"};
|
2007-10-19 20:41:34 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -blank", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
burn_disc_get_profile(drive, ¤t_profile, current_profile_name);
|
|
|
|
|
|
|
|
/* >>> */;
|
|
|
|
|
|
|
|
disc_state = isoburn_disc_get_status(drive);
|
2007-10-20 17:10:04 +00:00
|
|
|
if(current_profile == 0x13) { /* overwriteable DVD-RW */
|
|
|
|
/* Depending on flag bit1 formatted DVD-RW will get blanked to sequential
|
|
|
|
state or pseudo blanked by invalidating an eventual ISO image. */
|
|
|
|
if(flag&2)
|
|
|
|
do_deformat= 1;
|
|
|
|
} else if(current_profile == 0x14) { /* sequential DVD-RW */
|
|
|
|
if((flag&1) && !(flag&2)) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-blank: DVD-RW present. Mode 'fast' defaulted to mode 'all'.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Mode 'deformat_quickest' produces single-session-only media.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
|
|
|
|
flag&= ~1;
|
|
|
|
}
|
2007-10-19 20:41:34 +00:00
|
|
|
} else if(disc_state == BURN_DISC_BLANK) {
|
|
|
|
sprintf(xorriso->info_text,"Blank media detected. Will leave it untouched");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return 2;
|
|
|
|
} else if(disc_state==BURN_DISC_FULL || disc_state==BURN_DISC_APPENDABLE) {
|
|
|
|
;
|
|
|
|
} else if(disc_state == BURN_DISC_EMPTY) {
|
|
|
|
sprintf(xorriso->info_text,"No media detected in drive");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
sprintf(xorriso->info_text, "Unsuitable drive and media state");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!isoburn_disc_erasable(drive)) {
|
|
|
|
sprintf(xorriso->info_text, "Media is not of erasable type");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-20 17:10:04 +00:00
|
|
|
if(xorriso->do_dummy) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-dummy mode prevents blanking of media in mode '%s'.",
|
|
|
|
mode_names[flag&3]);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Beginning to blank media in mode '%s'.\n",
|
|
|
|
mode_names[flag&3]);
|
2007-10-19 20:41:34 +00:00
|
|
|
Xorriso_info(xorriso,0);
|
2007-10-20 17:10:04 +00:00
|
|
|
|
|
|
|
if(do_deformat)
|
|
|
|
burn_disc_erase(drive, (flag&1));
|
|
|
|
else
|
|
|
|
isoburn_disc_erase(drive, (flag&1));
|
2007-10-19 20:41:34 +00:00
|
|
|
usleep(1000000);
|
|
|
|
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
|
|
|
|
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
|
|
|
|
percent = 1.0 + ((double) p.sector+1.0) / ((double) p.sectors) * 98.0;
|
|
|
|
sprintf(xorriso->info_text, "Blanking ( %.1f%% done )", percent);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
|
|
|
usleep(1000000);
|
|
|
|
}
|
2007-10-20 17:10:04 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-19 20:41:34 +00:00
|
|
|
sprintf(xorriso->info_text, "Blanking done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
/* @return 0=failure, did not touch media , -1=failure, altered media
|
|
|
|
1=success, altered media , 2=success, did not touch media
|
|
|
|
*/
|
2007-10-19 20:41:34 +00:00
|
|
|
int Xorriso_format_media(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-20 17:10:04 +00:00
|
|
|
int ret, mode_flag= 0;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
|
|
|
|
#ifdef NIX
|
|
|
|
struct burn_progress p;
|
|
|
|
double percent = 1.0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int current_profile;
|
|
|
|
char current_profile_name[80];
|
|
|
|
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -format", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
burn_disc_get_profile(drive, ¤t_profile, current_profile_name);
|
|
|
|
if(current_profile == 0x14) {
|
|
|
|
; /* ok DVD-RW sequential */
|
|
|
|
} else if(current_profile == 0x1a) {
|
|
|
|
mode_flag= 2;
|
|
|
|
} else {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Can only -format DVD+RW and sequential DVD-RW");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
sprintf(xorriso->info_text,"Media current: %s (%4.4xh)",
|
|
|
|
current_profile_name, current_profile);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xorriso->do_dummy) {
|
|
|
|
sprintf(xorriso->info_text, "-dummy mode prevents formatting of media.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Beginning to format media.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
burn_disc_format(drive, (off_t) 0, mode_flag);
|
|
|
|
|
|
|
|
ret= Xorriso_pacifier_loop(xorriso, drive, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
#ifdef NIX
|
|
|
|
|
|
|
|
usleep(1000000);
|
|
|
|
while(burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
|
|
|
|
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
|
|
|
|
percent = 1.0 + ((double) p.sector+1.0)
|
|
|
|
/ ((double) p.sectors) * 98.0;
|
|
|
|
sprintf(xorriso->info_text, "Formatting ( %.1f%% done )", percent);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
|
|
|
usleep(1000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
burn_disc_get_profile(dinfo[0].drive, ¤t_profile, current_profile_name);
|
|
|
|
sprintf(xorriso->info_text, "Media type now: %4.4xh \"%s\"\n",
|
|
|
|
current_profile, current_profile_name);
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
if(current_profile != 0x13 && current_profile != 0x1a) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Failed to change media profile to desired value.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text, "Formatting done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
2007-10-19 20:41:34 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|