New option -paste_in

This commit is contained in:
Thomas Schmitt 2008-06-13 15:16:03 +00:00
parent 0d407b63ad
commit 26b3dcb1f5
6 changed files with 140 additions and 77 deletions

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 "Jun, 12, 2008"
.TH XORRISO 1 "Jun, 13, 2008"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -1641,6 +1641,18 @@ of -cut_out part files.
.br
With option "concat_split_off" such directories are
handled like any other ISO image directory.
.br
Note that some restore operations are inverse mappings of data manipulation
commands which have the same parameters. I.e. the disk_path stays the first
argument although the operation copies data from ISO image to disk.
.br
Other operations, like -cpx, have the iso_rr_paths first and the the disk_path
as last argument.
.TP
\fB\-paste_in\fR disk_path byte_offset byte_count iso_rr_path
Extract the content of a ISO data file iso_rr_path and write it into a data
file on disk beginning at the byte_offset. Write at most byte_count bytes.
This is the inverse mapping of option -cut_out.
.TP
\fB\-cpx\fR iso_rr_path [***] disk_path
Extract single leaf file objects from the ISO image and store them under

View File

@ -8834,7 +8834,8 @@ int Xorriso_option_cpx(struct XorrisO *xorriso, int argc, char **argv,
goto problem_handler;
}
}
ret= Xorriso_restore(xorriso, eff_origin, eff_dest, 16 | (!(flag&2)<<6));
ret= Xorriso_restore(xorriso, eff_origin, eff_dest, (off_t) 0, (off_t) 0,
16 | (!(flag&2)<<6));
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
if(ret==3 || (flag&1))
@ -8866,18 +8867,26 @@ ex:;
part_{partno}_of_{total_parts}_at_{offset}_with_{bytes}_of_{total_bytes}
*/
/* Option -cut_out */
/* Options -cut_out, -paste_in */
/* @param flag bit0= -paste_in rather than cut_out
*/
int Xorriso_option_cut_out(struct XorrisO *xorriso, char *disk_path,
char *start, char *count, char *iso_rr_path, int flag)
{
int ret;
double num;
off_t startbyte, bytecount;
char *cmd;
if(flag&1)
cmd= "paste_in";
else
cmd= "cut_out";
num= Scanf_io_size(start, 0);
if(num<0 || num > 1.0e18) { /* 10^18 = 10^3 ^ 6 < 2^10 ^ 6 = 2^60 */
sprintf(xorriso->info_text,
"-cut_out: startbyte address negative or much too large (%s)", start);
"-%s: startbyte address negative or much too large (%s)", cmd, start);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
@ -8885,19 +8894,29 @@ int Xorriso_option_cut_out(struct XorrisO *xorriso, char *disk_path,
num= Scanf_io_size(count, 0);
if(num<=0 || num > 1.0e18) {
sprintf(xorriso->info_text,
"-cut_out: bytecount zero, negative or much too large (%s)", count);
"-%s: bytecount zero, negative or much too large (%s)", cmd, count);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
bytecount= num;
sprintf(xorriso->info_text,
"-cut_out from %s , byte %.f to %.f, and graft as %s",
disk_path, (double) startbyte, (double) (startbyte+bytecount),
iso_rr_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
if(flag&1) {
sprintf(xorriso->info_text, "-paste_in from %s to %s, byte %.f to %.f",
disk_path, iso_rr_path,
(double) startbyte, (double) (startbyte+bytecount));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
ret= Xorriso_cut_out(xorriso, disk_path, startbyte, bytecount,
iso_rr_path, 0);
ret= Xorriso_paste_in(xorriso, disk_path, startbyte, bytecount,
iso_rr_path, 0);
} else {
sprintf(xorriso->info_text,
"-cut_out from %s , byte %.f to %.f, and graft as %s",
disk_path, (double) startbyte, (double) (startbyte+bytecount),
iso_rr_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
ret= Xorriso_cut_out(xorriso, disk_path, startbyte, bytecount,
iso_rr_path, 0);
}
return(ret);
}
@ -9778,6 +9797,8 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" By default \"off\" the inverse operation of xorriso from ISO",
" image to disk filesystem is disabled. \"on\" allows xorriso",
" to create, overwrite, delete files in the disk filesystem.",
" -paste_in disk_path byte_offset byte_count iso_rr_path",
" Copy ISO file content into a byte interval of a disk file.",
" -cpx iso_rr_path [***] disk_path",
" Copy leaf file objects from ISO image to disk filesystem.",
" -cpax iso_rr_path [***] disk_path",
@ -11645,7 +11666,7 @@ int Xorriso_count_args(struct XorrisO *xorriso, int argc, char **argv,
""
};
static char arg4_commands[][40]= {
"cut_out",
"cut_out", "paste_in",
""
};
static char argn_commands[][40]= {
@ -12047,6 +12068,17 @@ next_command:;
num2= 80;
ret= Xorriso_option_page(xorriso, num1, num2, 0);
} else if(strcmp(cmd,"paste_in")==0) {
(*idx)+= 4;
if((*idx)>argc) {
sprintf(xorriso->info_text,
"-paste_in: Not enough arguments. Needed are: disk_path start count so_rr_path");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0;
} else
ret= Xorriso_option_cut_out(xorriso, arg1, arg2,
argv[(*idx)-2], argv[(*idx)-1], 1);
} else if(strcmp(cmd,"path-list")==0 || strcmp(cmd,"path_list")==0) {
(*idx)++;
ret= Xorriso_option_path_list(xorriso, arg1, 0);

View File

@ -240,7 +240,9 @@ int Xorriso_option_cpri( struct XorrisO *xorriso, int argc, char **argv,
int Xorriso_option_cpx(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag);
/* Option -cut_out */
/* Options -cut_out, -paste_in */
/* @param flag bit0= -paste_in rather than cut_out
*/
int Xorriso_option_cut_out(struct XorrisO *xorriso, char *disk_path,
char *start, char *count, char *iso_rr_path, int flag);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.06.12.112644"
#define Xorriso_timestamP "2008.06.13.151630"

View File

@ -2257,7 +2257,7 @@ unsupported_type:;
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, iso_rr_path, eff_dest,
2|((flag&1)<<2));
2);
if(ret<=0)
return(ret);
@ -2536,8 +2536,10 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
if(write_fd==-1)
goto cannot_restore;
}
todo= size= iso_file_get_size((IsoFile *) node);
if(flag&2) {
todo= size= bytes;
if(bytes<size)
todo= size= bytes;
seek_ret= lseek(write_fd, offset, SEEK_SET);
if(seek_ret == -1) {
sprintf(xorriso->info_text,
@ -2546,8 +2548,7 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
goto cannot_restore;
}
} else
todo= size= iso_file_get_size((IsoFile *) node);
}
while(todo>0) {
wanted= sizeof(buf);
if(wanted>todo)
@ -2711,7 +2712,7 @@ int Xorriso_restore_overwrite(struct XorrisO *xorriso,
/*
@param flag
@param flag bit0= offset and bytes is valid for writing to regular file
bit1= do not report copied files
bit2= -follow, -not_*: this is not a command parameter
bit3= keep directory open: keep owner, allow rwx for owner
@ -2721,10 +2722,10 @@ int Xorriso_restore_overwrite(struct XorrisO *xorriso,
int Xorriso_restore_disk_object(struct XorrisO *xorriso,
char *img_path, IsoNode *node,
char *disk_path,
int flag)
off_t offset, off_t bytes, int flag)
{
int ret, i, split_count= 0, partno, total_parts, leaf_is_split= 0;
off_t offset, bytes, total_bytes;
off_t total_bytes;
char *part_name, part_path[SfileadrL], *img_path_pt;
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
IsoImage *volume;
@ -2784,8 +2785,8 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
img_path_pt= img_path;
ret= Xorriso_tree_restore_node(xorriso, node, img_path_pt, disk_path,
(off_t) 0, (off_t) 0,
(flag&(4|8)) | !!(flag&64));
offset, bytes,
(flag&(4|8)) | (!!(flag&64)) | ((flag&1)<<1));
if(ret>0 && (flag&8))
ret= Xorriso_restore_properties(xorriso, disk_path, node, 2 | !!(flag&64));
if(ret<=0) {
@ -3037,35 +3038,11 @@ much_too_long:;
source_is_split= Xorriso_is_split(xorriso, img_path, node, 1|2);
if(source_is_split)
do_not_dive= 1;
#ifdef NIX
/* >>> handle softlinks */;
/* does a disk file exist with this name ? */
stbuf_ret= lstat(disk_path, &target_stbuf);
if(stbuf_ret!=-1) {
target_is_dir= S_ISDIR(target_stbuf.st_mode);
if(!(target_is_dir && (source_is_dir && !source_is_split))) {
Xorriso_process_msg_queues(xorriso,0);
ret= Xorriso_restore_overwrite(xorriso, node, img_path, disk_path,
disk_path, &target_stbuf, 0);
if(ret<=0)
goto was_problem;
stbuf_ret= -1; /* It might still exist but will be handled properly */
}
}
#else /* NIX */
ret= Xorriso_handle_collision(xorriso, node, img_path, disk_path, disk_path,
&stbuf_ret, (source_is_dir && !source_is_split));
if(ret<=0 || ret==3)
goto was_problem;
#endif /* ! NIX */
if(stbuf_ret!=-1) { /* (Can only happen with directory) */
/* ??? >>> eventually open access to existing directory ? */;
@ -3075,7 +3052,7 @@ much_too_long:;
if(source_is_dir && !do_not_dive)
hflag|= 8; /* keep directory open for user */
ret= Xorriso_restore_disk_object(xorriso, img_path, node, disk_path,
hflag);
(off_t) 0, (off_t) 0, hflag);
if(ret<=0)
goto was_problem;
}
@ -3136,7 +3113,7 @@ ex:
>>> bit0= mkdir: graft in as empty directory, not as copy from iso
bit1= do not report copied files
bit2= -follow, -not_*: this is not a command parameter
??? <<< bit3= use offset and cut_size for cut_out_node
>>> bit3= use offset and cut_size for -paste_in
bit4= return 3 on rejection by exclusion or user
bit5= if directory then do not add sub tree
bit6= this is a copy action: do not fake times and ownership
@ -3144,7 +3121,8 @@ ex:
3 = rejected
*/
int Xorriso_restore(struct XorrisO *xorriso,
char *img_path, char *disk_path, int flag)
char *img_path, char *disk_path,
off_t offset, off_t bytes, int flag)
{
IsoImage *volume;
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL];
@ -3223,31 +3201,17 @@ int Xorriso_restore(struct XorrisO *xorriso,
source_is_dir= (is_dir || (flag&1) || !done);
source_is_split= done && leaf_is_split;
#ifdef NIX
if((flag&8) && done) {
/* >>> handle softlinks */;
/* ??? move down from Xorriso_paste_in() :
check whether target does not exist or both are regular */;
stbuf_ret= stat(path, &target_stbuf);
if(stbuf_ret!=-1) {
target_is_dir= S_ISDIR(target_stbuf.st_mode);
if(!(target_is_dir && (source_is_dir && !source_is_split))) {
ret= Xorriso_restore_overwrite(xorriso, node, img_path, path, disk_path,
&target_stbuf, flag&16);
if(ret<=0 || ret==3)
goto ex;
stbuf_ret= -1; /* now it is removed (or can be handled properly) */
}
}
#else /* NIX */
ret= Xorriso_handle_collision(xorriso, node, img_path, path, disk_path,
} else {
ret= Xorriso_handle_collision(xorriso, node, img_path, path, disk_path,
&stbuf_ret, (source_is_dir && !source_is_split));
if(ret<=0 || ret==3)
goto ex;
#endif /* ! NIX */
if(ret<=0 || ret==3)
goto ex;
}
new_dir_made= 0;
if(stbuf_ret==-1 && (source_is_dir && !source_is_split)) {
@ -3294,7 +3258,7 @@ attach_source:;
}
} else {
ret= Xorriso_restore_disk_object(xorriso, img_path, node, path,
flag & (2|4|64));
offset, bytes, (flag & (2|4|64)) | !!(flag&8));
if(ret<=0)
goto ex;
}
@ -3313,6 +3277,55 @@ ex:;
}
/* @param flag bit0= -follow, -not: disk_path is not a command parameter
*/
int Xorriso_paste_in(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;
IsoNode *node;
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_dest,
2|4);
if(ret<=0)
return(ret);
ret= Xorriso_path_is_excluded(xorriso, disk_path, !(flag&1));
if(ret!=0)
return(0);
ret= stat(eff_dest, &stbuf);
if(ret!=-1 && !S_ISREG(stbuf.st_mode)) {
Xorriso_msgs_submit(xorriso, 0, eff_dest, 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"-paste_in: DISK file %s exists and is not a data file",
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_source, 2);
if(ret<=0)
return(ret);
ret= Xorriso_fake_stbuf(xorriso, eff_source, &stbuf, &node, 0);
if(ret<=0)
return(0);
if(!S_ISREG(stbuf.st_mode)) {
Xorriso_msgs_submit(xorriso, 0, eff_dest, 0, "ERRFILE", 0);
sprintf(xorriso->info_text, "-paste_in: ISO file %s is not a data file",
Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
/* >>> eventually obtain parameters from file name */;
ret= Xorriso_restore(xorriso, 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;

View File

@ -216,6 +216,9 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
int Xorriso_cut_out(struct XorrisO *xorriso, char *disk_path,
off_t startbyte, off_t bytecount, char *iso_rr_path, int flag);
int Xorriso_paste_in(struct XorrisO *xorriso, char *disk_path,
off_t startbyte, off_t bytecount, char *iso_rr_path, int flag);
struct SplitparT;
/* @param flag bit0= in_node is valid, do not resolve iso_adr
@ -236,7 +239,7 @@ int Xorriso_is_split(struct XorrisO *xorriso, char *path, void *node,
>>> bit0= mkdir: graft in as empty directory, not as copy from iso
bit1= do not report copied files
bit2= -follow, -not_*: this is not a command parameter
??? <<< bit3= use offset and cut_size for cut_out_node
bit3= use offset and cut_size for -paste_in
bit4= return 3 on rejection by exclusion or user
bit5= if directory then do not add sub tree
bit6= this is a copy action: do not fake times and ownership
@ -244,7 +247,8 @@ int Xorriso_is_split(struct XorrisO *xorriso, char *path, void *node,
3 = rejected
*/
int Xorriso_restore(struct XorrisO *xorriso,
char *img_path, char *disk_path, int flag);
char *img_path, char *disk_path,
off_t offset, off_t cut_size, int flag);
/* @param flag bit0= in_node is valid, do not resolve img_path