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

This commit is contained in:
2007-10-20 17:10:04 +00:00
parent b09ff95b4e
commit 1fa4b04229
4 changed files with 210 additions and 36 deletions

View File

@ -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);
}