New option -cut_out

This commit is contained in:
2008-03-09 14:22:14 +00:00
parent 1d489a7297
commit b3540fafb6
7 changed files with 166 additions and 42 deletions

View File

@ -1433,10 +1433,14 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
}
/* Ticket 132 : Workaround for missing feature iso_tree_add_new_node() */
/* Ticket 132 : Former workaround for missing feature iso_tree_add_new_node()
which is now available and gets used here.
@param flag bit3= cut_out_node: offset and size are valid
*/
int Xorriso_tree_graft_node(struct XorrisO *xorriso, IsoImage *volume,
IsoDir *dir, char *disk_path, char *img_name,
char *nominal_source, char *nominal_target,
off_t offset, off_t cut_size,
IsoNode **node, int flag)
{
int ret;
@ -1473,7 +1477,11 @@ int Xorriso_tree_graft_node(struct XorrisO *xorriso, IsoImage *volume,
#else /* Xorriso_workaround_ticket_132 */
ret= iso_tree_add_new_node(volume, dir, img_name, disk_path, node);
if(flag&8)
ret= iso_tree_add_new_cut_out_node(volume, dir, img_name, disk_path,
offset, cut_size, node);
else
ret= iso_tree_add_new_node(volume, dir, img_name, disk_path, node);
#endif /* Xorriso_workaround_ticket_132 */
@ -1691,13 +1699,13 @@ cannot_lstat:;
#ifdef NIX
ret= iso_tree_add_node(volume, dir, srcpt, &node);
if(ret<0) {
Xorriso_report_iso_error(xorriso, stbuf_src, ret,
Xorriso_report_iso_error(xorriso, "", ret,
"Cannot add node to tree", 0, "FAILURE", 1|2);
goto was_problem;
}
#else
ret= Xorriso_tree_graft_node(xorriso, volume, dir, srcpt, img_name,
stbuf_src, img_path,
"", img_path, (off_t) 0, (off_t) 0,
&node, 0);
#endif
}
@ -1835,10 +1843,12 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
@param flag bit0= mkdir: graft in as empty directory, not as copy from disk
bit1= do not report added files
bit2= -follow: this is not a command parameter
bit3= use offset and cut_size for cut_out_node
@return <=0 = error , 1 = added simple node , 2 = added directory
*/
int Xorriso_graft_in(struct XorrisO *xorriso, void *boss_iter,
char *disk_path, char *img_path, int flag)
char *disk_path, char *img_path,
off_t offset, off_t cut_size, int flag)
{
IsoImage *volume;
char path[SfileadrL], *apt, *npt, *cpt, sfe[5*SfileadrL], sfe2[5*SfileadrL];
@ -2014,11 +2024,6 @@ handle_path_node:;
}
if(done) {
attach_source:;
xorriso->pacifier_count++;
if(xorriso->pacifier_count%100 && !(flag&2))
Xorriso_pacifier_callback(xorriso, "files added",
xorriso->pacifier_count,
xorriso->pacifier_total, "", 0);
if(flag&1) {
/* directory node was created above */;
@ -2051,9 +2056,9 @@ attach_source:;
}
#else
ret= Xorriso_tree_graft_node(xorriso, volume, dir, disk_path_pt, apt,
disk_path, img_path, &node, 0);
disk_path, img_path,
offset, cut_size, &node, flag&8);
if(ret<0) {
Xorriso_msgs_submit(xorriso, 0, disk_path, 0, "ERRFILE", 0);
sprintf(xorriso->info_text, "Grafting failed: %s = %s",
Text_shellsafe(img_path,sfe,0), Text_shellsafe(disk_path,sfe2,0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
@ -2062,6 +2067,12 @@ attach_source:;
#endif
xorriso->volset_change_pending= 1;
iso_node_set_name(node, apt);
xorriso->pacifier_count++;
if(xorriso->pacifier_count%100 && !(flag&2))
Xorriso_pacifier_callback(xorriso, "files added",
xorriso->pacifier_count,
xorriso->pacifier_total, "", 0);
}
} else
*npt= '/';
@ -2071,6 +2082,69 @@ attach_source:;
}
/* @param flag bit0= -follow: disk_path is not a command parameter
*/
int Xorriso_cut_out(struct XorrisO *xorriso, char *disk_path,
off_t startbyte, off_t bytecount, char *iso_rr_path, int flag)
{
int ret;
char eff_source[SfileadrL], eff_dest[SfileadrL], sfe[SfileadrL*5];
struct stat stbuf;
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_source,
2|4);
if(ret<=0)
return(ret);
if(lstat(eff_source, &stbuf)==-1) {
Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0);
sprintf(xorriso->info_text, "-cut_out: Cannot determine type of %s",
Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
if((stbuf.st_mode&S_IFMT) == S_IFLNK) {
if(!(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&1))))
goto unsupported_type;
if(stat(eff_source, &stbuf)==-1) {
Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"-cut_out: Cannot determine link target type of %s",
Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
return(0);
}
}
if(S_ISREG(stbuf.st_mode)) {
if(stbuf.st_size<startbyte) {
Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"-cut_out: Byte offset %.f larger than file size %.f",
(double) startbyte, (double) stbuf.st_size);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
} else {
unsupported_type:;
Xorriso_msgs_submit(xorriso, 0, eff_source, 0, "ERRFILE", 0);
sprintf(xorriso->info_text, "-cut_out: Unsupported file type %s with %s",
Ftypetxt(stbuf.st_mode, 0), Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, iso_rr_path, eff_dest,
2|((flag&1)<<2));
if(ret<=0)
return(ret);
ret= Xorriso_graft_in(xorriso, NULL, eff_source, eff_dest,
startbyte, bytecount, 8);
return(ret);
}
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
{
int ret, error_code= 0, os_errno= 0, count= 0, pass, imgid, tunneled;
@ -3643,7 +3717,8 @@ int Xorriso_rename(struct XorrisO *xorriso, void *boss_iter,
cpt= dir_adr+strlen(dir_adr);
*cpt= 0;
if(dir_adr[0]!=0) {
ret= Xorriso_graft_in(xorriso, boss_iter, NULL, dir_adr, 1);
ret= Xorriso_graft_in(xorriso, boss_iter, NULL, dir_adr,
(off_t) 0, (off_t) 0, 1);
if(ret<=0)
return(ret);
}
@ -3731,7 +3806,7 @@ int Xorriso_mkdir(struct XorrisO *xorriso, char *path, int flag)
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 2);
if(ret<0)
return(-2);
ret= Xorriso_graft_in(xorriso, NULL, NULL, eff_path, 1);
ret= Xorriso_graft_in(xorriso, NULL, NULL, eff_path, (off_t) 0, (off_t) 0, 1);
if(ret<=0)
return(-2);
if(!(flag&1)) {