|
|
|
@ -2436,6 +2436,72 @@ unsupported_type:;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= in_node is valid, do not resolve img_path
|
|
|
|
|
bit1= test mode: print DEBUG messages
|
|
|
|
|
@return <0 = error, 0 = not identical regular files , 1 = identical
|
|
|
|
|
2 = potentially depending on unknown disk file (e.g. -cut_out)
|
|
|
|
|
and hitting an existing disk file object
|
|
|
|
|
*/
|
|
|
|
|
int Xorriso_restore_is_identical(struct XorrisO *xorriso, void *in_node,
|
|
|
|
|
char *img_path, char *disk_path,
|
|
|
|
|
char type_text[5], int flag)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
unsigned int fs_id;
|
|
|
|
|
dev_t dev_id;
|
|
|
|
|
ino_t ino_id;
|
|
|
|
|
uint32_t dummy;
|
|
|
|
|
IsoStream *stream;
|
|
|
|
|
IsoImage *volume;
|
|
|
|
|
IsoNode *node;
|
|
|
|
|
struct stat stbuf;
|
|
|
|
|
|
|
|
|
|
memset(type_text, 0, 5);
|
|
|
|
|
if(flag&1) {
|
|
|
|
|
node= (IsoNode *) in_node;
|
|
|
|
|
} else {
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
|
if(ret<=0)
|
|
|
|
|
return(-1);
|
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, img_path, &node, 1);
|
|
|
|
|
if(ret<=0)
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret= iso_node_get_old_image_lba(node, &dummy, 0);
|
|
|
|
|
if(ret!=0)
|
|
|
|
|
return(0);
|
|
|
|
|
if(!LIBISO_ISREG(node))
|
|
|
|
|
return(0);
|
|
|
|
|
stream= iso_file_get_stream((IsoFile *) node);
|
|
|
|
|
memcpy(type_text, stream->class->type, 4);
|
|
|
|
|
iso_stream_get_id(stream, &fs_id, &dev_id, &ino_id);
|
|
|
|
|
if(flag&2) {
|
|
|
|
|
sprintf(xorriso->info_text, "%s : fs=%d dev=%.f ino=%.f (%s)",
|
|
|
|
|
img_path, fs_id, (double) dev_id, (double) ino_id, type_text);
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
|
|
|
|
}
|
|
|
|
|
ret= stat(disk_path, &stbuf);
|
|
|
|
|
if(ret==-1)
|
|
|
|
|
return(0);
|
|
|
|
|
if(flag&2) {
|
|
|
|
|
sprintf(xorriso->info_text, "%s : dev=%.f ino=%.f",
|
|
|
|
|
disk_path, (double) stbuf.st_dev, (double) stbuf.st_ino);
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
|
|
|
|
}
|
|
|
|
|
if(fs_id!=1)
|
|
|
|
|
return(2);
|
|
|
|
|
|
|
|
|
|
/* >>> obtain underlying dev_t ino_t of type "cout" */;
|
|
|
|
|
|
|
|
|
|
if(strcmp(type_text, "fsrc")!=0)
|
|
|
|
|
return(2);
|
|
|
|
|
if(stbuf.st_dev==dev_id && stbuf.st_ino==ino_id)
|
|
|
|
|
return(1);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= minimal transfer: access permissions only
|
|
|
|
|
bit1= keep directory open: keep owner, allow rwx for owner
|
|
|
|
|
and push directory onto xorriso->perm_stack
|
|
|
|
@ -2575,13 +2641,14 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
|
|
|
|
{
|
|
|
|
|
int ret= 0, write_fd= -1, wanted, wret, open_flags;
|
|
|
|
|
char *what= "[unknown filetype]", sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
|
|
|
|
char buf[32*1024];
|
|
|
|
|
char *link_target;
|
|
|
|
|
char buf[32*1024], type_text[5], temp_path[SfileadrL];
|
|
|
|
|
char *link_target, *open_path_pt;
|
|
|
|
|
off_t todo, size, seek_ret;
|
|
|
|
|
void *data_stream= NULL;
|
|
|
|
|
mode_t mode;
|
|
|
|
|
dev_t dev= 0;
|
|
|
|
|
struct stat stbuf;
|
|
|
|
|
struct utimbuf utime_buffer;
|
|
|
|
|
|
|
|
|
|
if(LIBISO_ISDIR(node)) {
|
|
|
|
|
what= "directory";
|
|
|
|
@ -2592,12 +2659,13 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
|
|
|
|
|
|
|
|
|
/* >>> need to exploit node rather than img_path */
|
|
|
|
|
ret= Xorriso_iso_file_open(xorriso, img_path, &data_stream, 0);
|
|
|
|
|
|
|
|
|
|
if(ret<=0)
|
|
|
|
|
goto ex;
|
|
|
|
|
|
|
|
|
|
open_flags= O_WRONLY|O_CREAT;
|
|
|
|
|
open_path_pt= disk_path;
|
|
|
|
|
ret= stat(open_path_pt, &stbuf);
|
|
|
|
|
if(flag&2) {
|
|
|
|
|
ret= stat(disk_path, &stbuf);
|
|
|
|
|
if(ret!=-1 && !S_ISREG(stbuf.st_mode)) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"Restore offset demanded. But filesystem path leads to non-data file %s",
|
|
|
|
@ -2605,20 +2673,42 @@ 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 {
|
|
|
|
|
/* If source and target are the same disk file then do not copy content */
|
|
|
|
|
ret= Xorriso_restore_is_identical(xorriso, (void *) node, img_path,
|
|
|
|
|
disk_path, type_text, 1);
|
|
|
|
|
if(ret<0)
|
|
|
|
|
goto ex;
|
|
|
|
|
if(ret==1) {
|
|
|
|
|
/* preliminarily emulate touch (might get overridden later) */
|
|
|
|
|
utime_buffer.actime= stbuf.st_atime;
|
|
|
|
|
utime_buffer.modtime= time(0);
|
|
|
|
|
utime(disk_path,&utime_buffer);
|
|
|
|
|
goto restore_properties;
|
|
|
|
|
}
|
|
|
|
|
if(ret==2) {
|
|
|
|
|
/* Extract to temporary file and rename only after copying */
|
|
|
|
|
ret= Xorriso_make_tmp_path(xorriso, disk_path, temp_path, &write_fd, 0);
|
|
|
|
|
if(ret<=0)
|
|
|
|
|
goto ex;
|
|
|
|
|
open_path_pt= temp_path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(write_fd==-1) {
|
|
|
|
|
open_flags= O_WRONLY|O_CREAT;
|
|
|
|
|
if(offset==0 || !(flag&2))
|
|
|
|
|
open_flags|= O_EXCL;
|
|
|
|
|
write_fd= open(open_path_pt, open_flags, S_IRUSR|S_IWUSR);
|
|
|
|
|
if(write_fd==-1)
|
|
|
|
|
goto cannot_restore;
|
|
|
|
|
}
|
|
|
|
|
if(offset==0 || !(flag&2))
|
|
|
|
|
open_flags|= O_EXCL;
|
|
|
|
|
write_fd= open(disk_path, open_flags, S_IRUSR|S_IWUSR);
|
|
|
|
|
if(write_fd==-1)
|
|
|
|
|
goto cannot_restore;
|
|
|
|
|
|
|
|
|
|
if(flag&2) {
|
|
|
|
|
todo= size= bytes;
|
|
|
|
|
seek_ret= lseek(write_fd, offset, SEEK_SET);
|
|
|
|
|
if(seek_ret == -1) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"Cannot address byte %.f in filesystem path %s",
|
|
|
|
|
(double) offset, Text_shellsafe(disk_path, sfe, 0));
|
|
|
|
|
(double) offset, Text_shellsafe(open_path_pt, sfe, 0));
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
|
|
|
|
|
goto cannot_restore;
|
|
|
|
|
}
|
|
|
|
@ -2637,7 +2727,7 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
|
|
|
|
if(wret != ret) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"Cannot write all bytes to disk filesystem path %s",
|
|
|
|
|
Text_shellsafe(disk_path, sfe, 0));
|
|
|
|
|
Text_shellsafe(open_path_pt, sfe, 0));
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -2646,6 +2736,18 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
|
|
|
|
write_fd= -1;
|
|
|
|
|
Xorriso_iso_file_close(xorriso, &data_stream, 0);
|
|
|
|
|
data_stream= NULL;
|
|
|
|
|
if(temp_path==open_path_pt) {
|
|
|
|
|
ret= rename(temp_path, disk_path);
|
|
|
|
|
if(ret==-1) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"Cannot rename temporary path %s to final disk path %s",
|
|
|
|
|
Text_shellsafe(temp_path, sfe, 0),
|
|
|
|
|
Text_shellsafe(disk_path, sfe2, 0));
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
|
|
|
|
|
unlink(temp_path);
|
|
|
|
|
ret= 0; goto ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret= (todo==0);
|
|
|
|
|
|
|
|
|
|
} else if(LIBISO_ISLNK(node)) {
|
|
|
|
@ -2727,6 +2829,8 @@ cannot_restore:;
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
|
|
|
|
ret= 0; goto ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_properties:;
|
|
|
|
|
if((flag&8) || LIBISO_ISLNK(node))
|
|
|
|
|
ret= 1;
|
|
|
|
|
else
|
|
|
|
@ -2741,20 +2845,30 @@ ex:;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Handle overwrite situation in disk filesystem.
|
|
|
|
|
@param node intended source of overwriting or NULL
|
|
|
|
|
@param flag
|
|
|
|
|
bit4= return 3 on rejection by exclusion or user
|
|
|
|
|
*/
|
|
|
|
|
int Xorriso_restore_overwrite(struct XorrisO *xorriso, char *img_path,
|
|
|
|
|
int Xorriso_restore_overwrite(struct XorrisO *xorriso,
|
|
|
|
|
IsoNode *node, char *img_path,
|
|
|
|
|
char *path, char *nominal_path,
|
|
|
|
|
struct stat *stbuf, int flag)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
|
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL], type_text[5];
|
|
|
|
|
|
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
if(xorriso->do_overwrite==1 ||
|
|
|
|
|
(xorriso->do_overwrite==2 && !S_ISDIR(stbuf->st_mode))) {
|
|
|
|
|
ret= Xorriso_rmx(xorriso, (off_t) 0, path, 1|8);
|
|
|
|
|
|
|
|
|
|
ret= Xorriso_restore_is_identical(xorriso, (void *) node, img_path,
|
|
|
|
|
path, type_text, (node!=NULL));
|
|
|
|
|
if(ret<0)
|
|
|
|
|
return(ret);
|
|
|
|
|
if(ret>0) /* will be handled properly by restore functions */
|
|
|
|
|
ret= Xorriso_reassure_restore(xorriso, path, 8);
|
|
|
|
|
else
|
|
|
|
|
ret= Xorriso_rmx(xorriso, (off_t) 0, path, 8);
|
|
|
|
|
if(ret<=0)
|
|
|
|
|
return(ret);
|
|
|
|
|
if(ret==3) {
|
|
|
|
@ -3055,11 +3169,11 @@ much_too_long:;
|
|
|
|
|
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, img_path, disk_path, disk_path,
|
|
|
|
|
&target_stbuf, 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;
|
|
|
|
|
stbuf_ret= -1; /* It might still exist but will be handled properly */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3218,11 +3332,11 @@ int Xorriso_restore(struct XorrisO *xorriso,
|
|
|
|
|
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, img_path, path, disk_path,
|
|
|
|
|
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 */
|
|
|
|
|
stbuf_ret= -1; /* now it is removed (or can be handled properly) */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new_dir_made= 0;
|
|
|
|
|