Implemented options -outdev and -indev

This commit is contained in:
2007-11-14 14:28:44 +00:00
parent 1fd3c2b7f4
commit 85abb04821
5 changed files with 276 additions and 134 deletions

View File

@ -127,7 +127,8 @@ int Xorriso_get_drive_handles(struct XorrisO *xorriso,
*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);
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);
}
@ -136,83 +137,177 @@ int Xorriso_get_drive_handles(struct XorrisO *xorriso,
}
int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
{
int ret;
struct iso_volset *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_volset_free((struct iso_volset *) xorriso->in_volset_handle);
xorriso->in_volset_handle= NULL;
xorriso->volset_change_pending= 0;
}
memset(&ropts, sizeof(ropts), 0);
ropts.pretend_blank= 1;
ret= isoburn_read_volset(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= volset;
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;
struct burn_drive_info *dinfo= NULL;
struct burn_drive *drive;
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;
struct iso_volset *volset;
struct isoburn_read_opts ropts;
if((flag&3)!=3) {
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);
ret= Xorriso_give_up_drive(xorriso, (flag&3)|8);
if(ret<=0)
return(ret);
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);
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&2) {
xorriso->out_drive_handle= dinfo;
if(Sfile_str(xorriso->indev, adr, 0)<=0)
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->outdev, adr, 0)<=0)
if(Sfile_str(xorriso->indev, adr, 0)<=0)
return(-1);
} else
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_volset_ref(xorriso->in_volset_handle);
ret= isoburn_attach_volset(drive,
(struct iso_volset *) 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);
}
drive= dinfo[0].drive;
if(xorriso->in_volset_handle!=NULL)
iso_volset_free((struct iso_volset *) xorriso->in_volset_handle);
xorriso->in_volset_handle= NULL;
/* check for invalid state */
state= isoburn_disc_get_status(drive);
Xorriso_process_msg_queues(xorriso,0);
/* >>> show drive and media status */;
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);
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.pretend_blank= 0;
if(isoburn_read_volset(drive, &ropts, &volset) <= 0) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Cannot read ISO image volset");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
ret= 3; goto ex;
}
xorriso->in_volset_handle= volset;
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_volset_ref(xorriso->in_volset_handle);
isoburn_attach_volset(out_drive, xorriso->in_volset_handle);
}
Xorriso_process_msg_queues(xorriso,0);
Xorriso_toc(xorriso, 1);
ret= 1;
ret= 1+not_writeable;
ex:
if(ret<0) {
/* >>> give up drive */;
if(ret<=0) {
hret= Xorriso_give_up_drive(xorriso, flag&3);
if(hret<ret)
ret= hret;
}
Xorriso_process_msg_queues(xorriso,0);
return(ret);
@ -222,10 +317,11 @@ ex:
/* @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;
int in_is_out_too, ret;
struct burn_drive_info *dinfo;
struct burn_drive *drive;
@ -233,33 +329,45 @@ int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
if((flag&1) && xorriso->in_drive_handle != NULL) {
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
"on attempt to give drive up", 0);
if(drive!=NULL)
isoburn_drive_release(drive,!!(flag&4));
"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_volset_free((struct iso_volset *) xorriso->in_volset_handle);
xorriso->in_volset_handle= NULL;
xorriso->volset_change_pending= 0;
if(dinfo!=NULL)
burn_drive_info_free(dinfo);
xorriso->in_drive_handle= NULL;
xorriso->indev[0]= 0;
if(in_is_out_too) {
xorriso->out_drive_handle= NULL;
xorriso->outdev[0]= 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(drive!=NULL)
isoburn_drive_release(drive,!!(flag&4));
if(dinfo!=NULL)
burn_drive_info_free(dinfo);
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);
@ -287,19 +395,19 @@ int Xorriso_make_write_options(
/* @param flag bit0= do not write but only prepare and return size in sectors
*/
int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
int Xorriso_write_session(struct XorrisO *xorriso, int flag)
{
int ret, media_space;
struct isoburn_source_opts sopts;
struct burn_drive_info *dinfo;
struct burn_drive *drive;
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);
@ -327,9 +435,31 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
sopts.ouput_charset= NULL;
sopts.fifo_size= xorriso->fs * 2048;
if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) {
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,"Cannot prepare disc");
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;}
}
@ -341,6 +471,7 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
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);
@ -972,13 +1103,15 @@ int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
/* @param flag bit0=short report form
bit1=report about output drive
*/
int Xorriso_toc(struct XorrisO *xorriso, int flag)
{
int num_sessions= 0, num_tracks= 0, lba= 0, nwa= -1, pmin, psec, pframe, ret;
int track_count= 0, session_no, track_no, profile_no= -1;
int last_track_start= 0, last_track_size= -1, num_data= 0, is_data= 0;
char profile_name[80],*respt;
int is_inout_drive= 0;
char profile_name[80],*respt,*devadr;
struct burn_disc *disc= NULL;
struct burn_session **sessions;
struct burn_track **tracks;
@ -988,13 +1121,21 @@ int Xorriso_toc(struct XorrisO *xorriso, int flag)
enum burn_disc_status s;
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
"on attempt to print Table Of Content", 2);
"on attempt to print Table Of Content", flag&2);
if(ret<=0)
return(0);
respt= xorriso->result_line;
sprintf(respt, "Drive current: -indev '%s'\n", xorriso->indev);
if(strcmp(xorriso->indev, xorriso->outdev)==0)
is_inout_drive= 1;
if(flag&2)
devadr= xorriso->outdev;
else
devadr= xorriso->indev;
sprintf(respt, "Drive current: %s '%s'\n",
(is_inout_drive ? "-dev" : (flag&2 ? "-outdev" : "-indev")),
devadr);
Xorriso_result(xorriso,0);
sprintf(respt, "Drive type : vendor '%s' product '%s' revision '%s'\n",
dinfo[0].vendor, dinfo[0].product, dinfo[0].revision);
@ -1211,10 +1352,7 @@ int Xorriso_tell_media_space(struct XorrisO *xorriso,
burn_write_opts_free(burn_options);
if(xorriso->volset_change_pending) {
/* >>> care for modifying */
ret= Xorriso_write_growing(xorriso, 1);
ret= Xorriso_write_session(xorriso, 1);
if(ret>0)
(*free_space)-= ret;
}
@ -1321,12 +1459,6 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag)
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];
@ -1363,30 +1495,6 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag)
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, &current_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);