Implemented options -format and -blank deformat, -close and closed media

master
Thomas Schmitt 16 years ago
parent 4c7bf645c2
commit 91fe875266

@ -707,6 +707,16 @@ int Sfile_home_adr_s(char *filename, char *fileadr, int fa_size, int flag)
}
/** Return a double representing seconds and microseconds since 1 Jan 1970 */
double Sfile_microtime(int flag)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv,&tz);
return((double) (tv.tv_sec+1.0e-6*tv.tv_usec));
}
#endif /* Xorriso_sfile_externaL */
@ -2701,9 +2711,9 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
}
is_default= 0;
if(xorriso->dialog)
sprintf(line,"-dialog\n");
sprintf(line,"-dialog on\n");
else {
sprintf(line,"-dialog_reset\n");
sprintf(line,"-dialog off\n");
is_default= 1;
}
if(!(is_default && no_defaults))
@ -3160,7 +3170,7 @@ int Xorriso_option_ban_stdio_write(struct XorrisO *xorriso, int flag)
/* @param flag bit0= format rather than blank */
int Xorriso_option_blank(struct XorrisO *xorriso, char *mode, int flag)
{
char drive_name[SfileadrL], *cmd= "-blank";
char drive_name[SfileadrL], *cmd= "-blank", sfe[4*SfileadrL];
int ret, aq_flag= 2, mode_flag;
if(flag&1)
@ -3183,19 +3193,46 @@ int Xorriso_option_blank(struct XorrisO *xorriso, char *mode, int flag)
if(strcmp(mode, "all")==0 || strcmp(mode, "full")==0)
mode_flag= 0;
else
else if(strcmp(mode, "deformat")==0 || strcmp(mode, "deformat_sequential")==0)
mode_flag= 2;
else if(strcmp(mode, "deformat_quickest")==0 ||
strcmp(mode, "deformat_sequential_quickest")==0)
mode_flag= 3;
else if(strcmp(mode, "fast")==0 || mode[0]==0)
mode_flag= 1;
else {
sprintf(xorriso->info_text,
"%s: Unknown %s mode '%s'",
cmd, ((flag&1) ? "format" : "blank"), mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(flag&1)
ret= Xorriso_format_media(xorriso, mode_flag);
ret= Xorriso_format_media(xorriso, 0);
else
ret= Xorriso_blank_media(xorriso, mode_flag);
strcpy(drive_name, xorriso->outdev);
Xorriso_give_up_drive(xorriso, aq_flag);
if(ret<=0)
return(ret);
ret= Xorriso_aquire_drive(xorriso, drive_name, aq_flag);
if(ret<=0)
if(ret==0)
return(ret);
strcpy(drive_name, xorriso->outdev);
if(ret!=2) {
Xorriso_give_up_drive(xorriso, aq_flag);
if(ret<=0) { /* this is the return value of the blank|format function */
sprintf(xorriso->info_text,"Gave up -outdev %s",
Text_shellsafe(xorriso->outdev, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
return(ret);
}
sprintf(xorriso->info_text,"Re-aquiring -outdev %s",
Text_shellsafe(drive_name, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= Xorriso_aquire_drive(xorriso, drive_name, aq_flag);
if(ret<=0) {
sprintf(xorriso->info_text,"Could not re-aquire -outdev %s",
Text_shellsafe(xorriso->outdev, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(ret);
}
}
return(1);
}
@ -3372,6 +3409,7 @@ int Xorriso_option_commit(struct XorrisO *xorriso, int flag)
ret= Xorriso_write_growing(xorriso, 0);
if(ret<=0)
return(ret);
xorriso->volset_change_pending= 0;
if(flag&1)
@ -3460,7 +3498,7 @@ int Xorriso_option_dev(struct XorrisO *xorriso, char *adr, int flag)
if((flag&2) && xorriso->in_drive_handle != NULL &&
xorriso->in_drive_handle != xorriso->out_drive_handle) {
sprintf(xorriso->info_text,"Giving up -outdev %s",
Text_shellsafe(xorriso->indev, sfe, 0));
Text_shellsafe(xorriso->outdev, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
ret= Xorriso_give_up_drive(xorriso, flag&3);
@ -3683,8 +3721,10 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" Set output drive and switch from growing to modifying.",
" -ban_stdio_write",
" Allow for writing only the usage of optical drives.",
" -blank \"fast\"|\"all\"|\"format\"",
" -blank \"fast\"|\"all\"|\"deformat\"|\"deformat_quickest\"",
" Blank media resp. invalidate ISO image on media.",
" -format \"full\"",
" Format DVD-RW to overwriteable state or de-ice DVD+RW.",
" -V volume_id Specifies the volume ID text.",
"",
" -J Generate Joliet info additional to Rock Ridge info.",
@ -4604,6 +4644,10 @@ next_command:;
(*idx)+= 2;
ret= Xorriso_option_chowni(xorriso, arg1, arg2, argc, argv, idx, 0);
} else if(strcmp(cmd,"-close")==0) {
(*idx)++;
ret= Xorriso_option_close(xorriso, arg1, 0);
} else if(strcmp(cmd,"-commit")==0) {
ret= Xorriso_option_commit(xorriso, 0);
@ -4720,7 +4764,7 @@ next_command:;
if(ret==3)
goto ex;
} else if(strcmp(cmd,"-options_from_file")==0) {
} else if(strcmp(cmd,"-overwrite")==0) {
(*idx)++;
ret= Xorriso_option_overwrite(xorriso,arg1,0);

@ -185,5 +185,7 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag);
int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag);
#endif /* Xorriso_private_includeD */

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.20.170731"
#define Xorriso_timestamP "2007.10.20.171046"

@ -168,9 +168,8 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
/* >>> show drive and media status */;
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
sprintf(xorriso->info_text, "Unsuitable disc status");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
sprintf(xorriso->info_text, "Disc status unsuitable for writing");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
}
/* fill read opts */
ropts.norock= 0;
@ -325,6 +324,13 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
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;
}
ret= isoburn_activate_session(drive);
Xorriso_process_msg_queues(xorriso,0);
@ -334,7 +340,7 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
goto ex;
}
ret= 1;
ex:;
if(disc!=NULL)
@ -350,18 +356,38 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
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(burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
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));
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);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
for(i= 0; i<10; i++) {
@ -768,10 +794,13 @@ int Xorriso_tell_media_space(struct XorrisO *xorriso, int flag)
}
/* @param flag bit0=fast */
/* @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
*/
int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
{
int ret;
int ret, do_deformat= 0;
struct burn_drive_info *dinfo;
struct burn_drive *drive;
enum burn_disc_status disc_state;
@ -779,6 +808,7 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
double percent = 1.0;
int current_profile;
char current_profile_name[80];
char mode_names[4][80]= {"all", "fast", "deformat", "deformat_quickest"};
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
"on attempt to -blank", 2);
@ -790,8 +820,21 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
/* >>> */;
disc_state = isoburn_disc_get_status(drive);
if(current_profile == 0x13) {
; /* formatted DVD-RW will get blanked to sequential state */
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;
}
} 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);
@ -812,10 +855,21 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return 0;
}
sprintf(xorriso->info_text, "Beginning to %s-blank media.\n",
((flag&1)?"fast":"full"));
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]);
Xorriso_info(xorriso,0);
isoburn_disc_erase(drive, (flag&1));
if(do_deformat)
burn_disc_erase(drive, (flag&1));
else
isoburn_disc_erase(drive, (flag&1));
usleep(1000000);
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
@ -824,15 +878,89 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
usleep(1000000);
}
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, "Blanking done\n");
Xorriso_info(xorriso,0);
return(1);
}
/* @return 0=failure, did not touch media , -1=failure, altered media
1=success, altered media , 2=success, did not touch media
*/
int Xorriso_format_media(struct XorrisO *xorriso, int flag)
{
fprintf(stderr, ">>> XORRISO : -format not implemented yet\n");
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, &current_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, &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);
return(1);
}

Loading…
Cancel
Save