Implemented a more reasonable solution for drive truncation with regular files

This commit is contained in:
Thomas Schmitt 2008-02-21 18:52:52 +00:00
parent c9067f4142
commit 4a27bf19e8
8 changed files with 59 additions and 17 deletions

View File

@ -273,6 +273,8 @@ ex:
/**
@param flag bit0= load
bit1= regard overwriteable media as blank
bit2= if the drive is a regular disk file: truncate it to
the write start address
*/
int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
char *adr, int flag)
@ -298,6 +300,12 @@ int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
if(ret<=0)
goto ex;
if(flag&4) {
ret= isoburn_find_emulator(&o, (*drive_infos)[0].drive, 0);
if(ret>0 && o!=NULL)
o->truncate= 1;
}
ret= 1;
ex:
if(ret<=0) {
@ -496,10 +504,13 @@ int isoburn_disc_track_lba_nwa(struct burn_drive *d,
void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
{
int ret;
off_t nwa= 0;
struct isoburn *o;
struct burn_drive *drive;
char reasons[BURN_REASONS_LEN],msg[160+BURN_REASONS_LEN];
char adr[BURN_DRIVE_ADR_LEN];
enum burn_write_types write_type;
struct stat stbuf;
drive= burn_write_opts_get_drive(opts);
ret= isoburn_find_emulator(&o, drive, 0);
@ -509,8 +520,10 @@ void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
o->wrote_well= -1;
if(o->emulation_mode!=0) {
burn_write_opts_set_multi(opts, 0);
if(o->emulation_mode>0 && o->nwa >= 0)
if(o->emulation_mode>0 && o->nwa >= 0) {
burn_write_opts_set_start_byte(opts, ((off_t) o->nwa) * (off_t) 2048);
nwa= o->nwa;
}
}
}
@ -539,6 +552,19 @@ void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
((off_t) Hardcoded_cd_rw_nwA) * (off_t) 2048);
#endif
if(o->truncate) {
ret= burn_drive_get_drive_role(drive);
if(ret==2) {
ret= burn_drive_d_get_adr(drive, adr);
if(ret>0) {
ret= lstat(adr, &stbuf);
if(ret!=-1)
if(S_ISREG(stbuf.st_mode))
truncate(adr, nwa * (off_t) 2048);
}
}
}
burn_disc_write(opts, disc);
}

View File

@ -69,6 +69,7 @@ int isoburn_new(struct isoburn **objpt, int flag)
o->emulation_mode= 0;
o->min_start_byte= 0;
o->nwa= 0;
o->truncate= 0;
#ifdef Libisoburn_no_fifO
o->iso_source= NULL;

View File

@ -42,8 +42,12 @@ struct isoburn {
/* Aligned start address to be used for processing (counted in blocks) */
int nwa;
/* Truncate to .nwa an eventual regular file serving as output drive */
int truncate;
/* Eventual freely fabricated isoburn_disc_get_status().
BURN_DISC_UNREADY means that normally emulated status is in effect.
BURN_DISC_UNREADY means that this variable is disabled
and normally emulated status is in effect.
*/
enum burn_disc_status fabricated_disc_status;

View File

@ -328,7 +328,8 @@ int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
@param flag bit0= attempt to load the disc tray.
Else: failure if not loaded.
bit1= regard overwriteable media as blank
bit2= if the drive is a regular disk file: truncate it to
the write start address
@return 1 = success , 0 = drive not found , <0 = other error
*/
int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "February 20, 2008"
.TH XORRISO 1 "February 21, 2008"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -1289,8 +1289,9 @@ persists until things happen like -commit, -rollback, -dev, or end of xorriso.
If no output file was chosen before or during a "mkisofs" option list, then
standard output (-outdev "-") will get into effect before pathspecs get
added. If -o points to a regular file, then it will be truncated to 0 bytes
before "mkisofs" options are processed. Directories and symbolic links
are no valid -o targets.
when finally writing begins. This truncation does not happen if the drive
is chosen by xorriso options before or after -as mkisofs.
Directories and symbolic links are no valid -o targets.
.br
Writing to stdout is possible only if -as "mkisofs" was among the start
arguments or if other start arguments pointed the output drive to

View File

@ -6524,11 +6524,13 @@ int Xorriso_genisofs(struct XorrisO *xorriso, char *whom,
if(adr[0]) {
if(strncmp(adr, "stdio:", 6)==0 && strncmp(adr, "stdio:/dev/fd/", 14)!=0) {
ret= Sfile_type(adr+6, 1);
if(ret==-1)
if(ret==-1) {
/* ok */;
else if(ret==1) {
/* >>> would prefer to do this later ... or leave it to libburn */;
#ifdef NIX
} else if(ret==1) {
/* <<< is now done in libisoburn by bit4 of Xorriso_option_dev() */
ret= truncate(adr+6, (off_t) 0);
if(ret==-1) {
@ -6540,6 +6542,8 @@ int Xorriso_genisofs(struct XorrisO *xorriso, char *whom,
sprintf(xorriso->info_text, "-as %s: Truncated existing -o %s",
whom, Text_shellsafe(adr+6, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
#endif /* NIX */
} else if(ret==2 || ret==3) {
sprintf(xorriso->info_text,
"-as %s: Cannot accept %s as target: -o %s",
@ -6548,7 +6552,8 @@ int Xorriso_genisofs(struct XorrisO *xorriso, char *whom,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
}
}
ret= Xorriso_option_dev(xorriso, adr, 2|8); /* overwriteable as blank */
/* Regard overwriteable as blank, truncate regular files on write start */
ret= Xorriso_option_dev(xorriso, adr, 2|8|16);
if(ret<=0)
goto ex;
}
@ -7505,6 +7510,8 @@ int Xorriso_option_cut_out(struct XorrisO *xorriso, char *disk_path,
bit1= use as outdev
bit2= do not -reassure
bit3= regard overwriteable media as blank
bit4= if the drive is a regular disk file: truncate it to
the write start address
@return <=0 error , 1 success, 2 revoked by -reassure
*/
int Xorriso_option_dev(struct XorrisO *xorriso, char *in_adr, int flag)
@ -7564,7 +7571,7 @@ int Xorriso_option_dev(struct XorrisO *xorriso, char *in_adr, int flag)
}
ret= Xorriso_give_up_drive(xorriso, flag&3);
} else
ret= Xorriso_aquire_drive(xorriso, adr, (flag&3)|((flag&8)>>1));
ret= Xorriso_aquire_drive(xorriso, adr, (flag&3)|((flag&(8|16))>>1));
if(ret<=0)
return(ret);
return(1);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.02.21.130047"
#define Xorriso_timestamP "2008.02.21.185203"

View File

@ -420,6 +420,8 @@ int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
/* @param flag bit0= aquire as isoburn input drive
bit1= aquire as libburn output drive (as isoburn drive if bit0)
bit2= regard overwriteable media as blank
bit3= if the drive is a regular disk file: truncate it to
the write start address
@return <=0 failure , 1= ok
2=success, but not writeable with bit1
3=success, but not blank and not ISO with bit0
@ -477,7 +479,7 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
}
if(dinfo==NULL) {
ret= isoburn_drive_aquire(&dinfo, libburn_adr, 1|((flag&4)>>1));
ret= isoburn_drive_aquire(&dinfo, libburn_adr, 1|((flag&(8|4))>>1));
Xorriso_process_msg_queues(xorriso,0);
if(ret<=0) {
sprintf(xorriso->info_text,"Cannot aquire drive '%s'", adr);