"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xorriso/read_run.c" between
xorriso-1.5.2.tar.gz and xorriso-1.5.4.tar.gz

About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.

read_run.c  (xorriso-1.5.2):read_run.c  (xorriso-1.5.4)
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net> Copyright 2007-2020 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later. Provided under GPL version 2 or later.
This file contains functions which are needed to read data This file contains functions which are needed to read data
from ISO image. from ISO image.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "../config.h" #include "../config.h"
#endif #endif
skipping to change at line 525 skipping to change at line 525
Text_shellsafe(nfi, xorriso->info_text, 1 | 2); Text_shellsafe(nfi, xorriso->info_text, 1 | 2);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
ret= 1; ret= 1;
ex:; ex:;
Xorriso_free_meM(nfi); Xorriso_free_meM(nfi);
Xorriso_free_meM(nd); Xorriso_free_meM(nd);
Xorriso_free_meM(nfd); Xorriso_free_meM(nfd);
return(ret); return(ret);
} }
/* If defined the position accounting will be done by lseek() and used to
* verify the position accounting in struct Xorriso_sparse_statE.
* # def ine Xorriso_check_sparsE yes
*/
struct Xorriso_sparse_statE {
int use_lseek;
off_t cur_pos;
off_t after_last_written;
int warnings;
};
#ifdef Xorriso_check_sparsE
static int Xorriso_sparse_warn(struct XorrisO *xorriso,
struct Xorriso_sparse_statE *sparse_state,
int occasion, char *msg, int flag)
{
if(sparse_state->warnings & (1 << occasion))
return(1);
sparse_state->warnings|= 1 << occasion;
Xorriso_msgs_submit(xorriso, 0, msg, 0, "SORRY", 0);
return(1);
}
#endif /* Xorriso_check_sparsE */
static int Xorriso_sparse_init(struct XorrisO *xorriso,
struct Xorriso_sparse_statE **sparse_state,
int write_fd, int flag)
{
struct Xorriso_sparse_statE *o= NULL;
off_t cur_pos;
struct stat stbuf;
int ret;
*sparse_state= NULL;
/* Check whether sparse writing is disabled */
if(xorriso->sparse_min_gap <= 0)
{ret= 0; goto ex;}
/* Analyze write_fd */
ret= fstat(write_fd, &stbuf);
if(ret == -1)
{ret= 0; goto ex;}
if(!S_ISREG(stbuf.st_mode))
{ret= 0; goto ex;}
cur_pos= lseek(write_fd, (off_t) 0, SEEK_CUR);
if(cur_pos < stbuf.st_size)
{ret= 0; goto ex;}
Xorriso_alloc_meM(o, struct Xorriso_sparse_statE, 1);
/* Initialize sparse_state */
o->use_lseek= 1;
o->cur_pos= o->after_last_written= cur_pos;
o->warnings= 0;
ret= 1;
ex:;
if(ret >= 1)
*sparse_state= o;
else
Xorriso_free_meM(o);
return(ret);
}
static int Xorriso_sparse_zeroize(struct XorrisO *xorriso,
struct Xorriso_sparse_statE *sparse_state,
int write_fd, off_t start, off_t count,
int flag)
{
int ret, buf_size= 32 * 1024, buf_fill, wret;
off_t todo, seek_ret;
char *buf= NULL;
if(count <= 0)
{ret= 2; goto ex;}
Xorriso_alloc_meM(buf, char, buf_size);
seek_ret= lseek(write_fd, start, SEEK_SET);
if(seek_ret == -1)
{ret= -1; goto ex;}
sparse_state->cur_pos= seek_ret;
for(todo= count; todo > 0; ) {
if(buf_size < todo)
buf_fill= buf_size;
else
buf_fill= todo;
wret= write(write_fd, buf, buf_fill);
if(wret <= 0)
{ret= wret; goto ex;}
todo-= wret;
sparse_state->cur_pos+= wret;
}
ret= 1;
ex:;
Xorriso_free_meM(buf);
return(ret);
}
/* @param flag bit0= this is the last buffer of the stream
*/
static int Xorriso_sparse_write(struct XorrisO *xorriso,
struct Xorriso_sparse_statE *sparse_state,
int write_fd, char *buf, int count,
int flag)
{
int wret, i, ret;
off_t cur_pos= -1, seek_ret;
static char zero[32]= {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
if(sparse_state == NULL)
goto do_write;
if(!sparse_state->use_lseek)
goto do_write;
if(flag & 1)
goto do_write;
#ifdef Xorriso_check_sparsE
cur_pos= lseek(write_fd, (off_t) 0, SEEK_CUR);
if(cur_pos == -1)
goto do_write;
if(cur_pos != sparse_state->cur_pos) {
Xorriso_sparse_warn(xorriso, sparse_state, 0,
"cur_pos deviation in Xorriso_sparse_write:intro", 0);
sparse_state->cur_pos= cur_pos;
}
#else
cur_pos= sparse_state->cur_pos;
#endif
/* Check for all zeros */
if(count % 32)
goto do_write;
for(i= 0; i < count; i+= 32)
if(memcmp(buf + i, zero, 32))
break;
if(i < count)
goto do_write;
/* Omit write() until next non-zero buffer or end of writing */
#ifdef Xorriso_check_sparsE
/* Only for debugging: Do real lseek() instead of write() */
seek_ret= lseek(write_fd, cur_pos + count, SEEK_SET);
if(seek_ret == -1)
return(-1);
#endif
sparse_state->cur_pos= cur_pos + count;
return(count);
do_write:
if(sparse_state != NULL) {
/* Check whether the gap since after_last_written is too small.
If so: fill the whole gap by writing zeros.
*/
if(sparse_state->after_last_written < cur_pos) {
if(xorriso->sparse_min_gap > cur_pos - sparse_state->after_last_written) {
ret= Xorriso_sparse_zeroize(xorriso, sparse_state, write_fd,
sparse_state->after_last_written,
cur_pos - sparse_state->after_last_written, 0);
if(ret < 0)
return(ret);
if(ret == 0) {
seek_ret= lseek(write_fd, cur_pos, SEEK_SET);
if(seek_ret == -1)
return(-1);
sparse_state->cur_pos= seek_ret;
}
}
}
}
if(sparse_state != NULL) {
#ifdef Xorriso_check_sparsE
cur_pos= lseek(write_fd, (off_t) 0, SEEK_CUR);
if(cur_pos != sparse_state->cur_pos) {
Xorriso_sparse_warn(xorriso, sparse_state, 1,
"cur_pos deviation in Xorriso_sparse_write:do_write", 0);
sparse_state->cur_pos= cur_pos;
}
#else
/* lseek() has been delayed until now */
if(sparse_state->after_last_written != sparse_state->cur_pos) {
seek_ret= lseek(write_fd, sparse_state->cur_pos, SEEK_SET);
if(seek_ret == -1)
return(-1);
}
#endif /* ! Xorriso_check_sparsE */
}
wret= write(write_fd, buf, count);
if(sparse_state != NULL && wret > 0 && cur_pos >= 0)
sparse_state->cur_pos= sparse_state->after_last_written= cur_pos + wret;
return(wret);
}
static int Xorriso_sparse_finish(struct XorrisO *xorriso,
struct Xorriso_sparse_statE **sparse_state,
int write_fd, int flag)
{
int ret;
off_t cur_pos;
struct Xorriso_sparse_statE *o;
if(sparse_state == NULL)
return(0);
o= *sparse_state;
if(o == NULL)
return(1);
if(write_fd == -1)
{ret= 1; goto ex;}
#ifdef Xorriso_check_sparsE
cur_pos= lseek(write_fd, (off_t) 0, SEEK_CUR);
if(cur_pos == -1)
{ret= -1; goto ex;}
if(cur_pos != o->cur_pos) {
Xorriso_sparse_warn(xorriso, o, 2,
"cur_pos deviation in Xorriso_sparse_finish", 0);
o->cur_pos= cur_pos;
}
#else
cur_pos= o->cur_pos;
#endif /* ! Xorriso_check_sparsE */
if(o->after_last_written < cur_pos) {
/* Check whether the gap since after_last_written is too small.
If so: fill the whole gap by writing zeros, else: write a last zero byte.
*/
if(xorriso->sparse_min_gap > cur_pos - o->after_last_written)
ret= Xorriso_sparse_zeroize(xorriso, o, write_fd, o->after_last_written,
cur_pos - o->after_last_written, 0);
else
ret= Xorriso_sparse_zeroize(xorriso, o, write_fd, cur_pos - 1, (off_t) 1,
0);
if(ret <= 0)
goto ex;
}
ret= 1;
ex:;
Xorriso_free_meM(o);
*sparse_state= NULL;
return(ret);
}
/* @param flag bit0= Minimal transfer: access permissions only /* @param flag bit0= Minimal transfer: access permissions only
bit1= *_offset and bytes are valid for writing to regular file bit1= *_offset and bytes are valid for writing to regular file
bit2= This is not a parameter. Do not report if ignored bit2= This is not a parameter. Do not report if ignored
bit3= do not restore properties bit3= do not restore properties
bit4= issue pacifier messages with long lasting copying bit4= issue pacifier messages with long lasting copying
bit7= return 4 if restore fails from denied permission bit7= return 4 if restore fails from denied permission
do not issue error message do not issue error message
@return <0 severe error , 0 failure , 1 success , @return <0 severe error , 0 failure , 1 success ,
2 regularly not installed (disallowed device, UNIX domain socket) 2 regularly not installed (disallowed device, UNIX domain socket)
4 with bit7: permission to restore was denied 4 with bit7: permission to restore was denied
skipping to change at line 557 skipping to change at line 822
void *data_stream= NULL; void *data_stream= NULL;
mode_t mode; mode_t mode;
dev_t dev= 0; dev_t dev= 0;
struct stat stbuf; struct stat stbuf;
struct utimbuf utime_buffer; struct utimbuf utime_buffer;
IsoImage *volume; IsoImage *volume;
IsoBoot *bootcat; IsoBoot *bootcat;
uint32_t lba; uint32_t lba;
char *catcontent = NULL; char *catcontent = NULL;
off_t catsize; off_t catsize;
char disk_md5[16], iso_md5[16];
void *ctx= NULL;
int use_md5= 0, i, sparse_ret= 3;
struct Xorriso_sparse_statE *sparse_state= NULL;
Xorriso_alloc_meM(buf, char, buf_size); Xorriso_alloc_meM(buf, char, buf_size);
Xorriso_alloc_meM(temp_path, char, SfileadrL); Xorriso_alloc_meM(temp_path, char, SfileadrL);
if(!(flag & 2))
img_offset= bytes= 0;
if(LIBISO_ISDIR(node)) { if(LIBISO_ISDIR(node)) {
what= "directory"; what= "directory";
ret= mkdir(disk_path, 0777); ret= mkdir(disk_path, 0777);
l_errno= errno; l_errno= errno;
} else if(LIBISO_ISREG(node) || ISO_NODE_IS_BOOTCAT(node)) { } else if(LIBISO_ISREG(node) || ISO_NODE_IS_BOOTCAT(node)) {
if(ISO_NODE_IS_BOOTCAT(node)) { if(ISO_NODE_IS_BOOTCAT(node)) {
what= "boot catalog"; what= "boot catalog";
} else { } else {
what= "regular file"; what= "regular file";
ret= Xorriso_iso_file_open(xorriso, img_path, (void *) node, &data_stream, ret= Xorriso_iso_file_open(xorriso, img_path, (void *) node, &data_stream,
1); 1);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
if((xorriso->do_md5 & 65) == 65 && !(flag & 2)) {
ret= Xorriso_is_plain_image_file(xorriso, (void *) node, img_path, 0);
if(ret > 0) {
ret= Xorriso_get_md5(xorriso, (void *) node, img_path, iso_md5, 1);
if(ret > 0)
ret= Xorriso_md5_start(xorriso, &ctx, 0);
if(ret > 0) {
use_md5= 1;
} else if(xorriso->do_md5 & 128) {
sprintf(xorriso->info_text,
"Cannot obtain any recorded MD5 of file ");
Text_shellsafe(img_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= Xorriso_eval_problem_status(xorriso, 0, 1 | 2);
if(ret < 0)
{ret= 0; goto ex;}
}
}
}
} }
open_path_pt= disk_path; open_path_pt= disk_path;
ret= stat(open_path_pt, &stbuf); ret= stat(open_path_pt, &stbuf);
if(ret == -1 && errno == EACCES && (flag & 128)) if(ret == -1 && errno == EACCES && (flag & 128))
{ret= 4; goto ex;} {ret= 4; goto ex;}
if(flag&2) { if(flag&2) {
if(ret!=-1 && !S_ISREG(stbuf.st_mode)) { if(ret!=-1 && !S_ISREG(stbuf.st_mode)) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Restore offset demanded. But filesystem path leads to non-data file "); "Restore offset demanded. But filesystem path leads to non-data file ");
Text_shellsafe(disk_path, xorriso->info_text, 1); Text_shellsafe(disk_path, xorriso->info_text, 1);
skipping to change at line 647 skipping to change at line 937
l_errno= errno; l_errno= errno;
if(seek_ret == -1) { if(seek_ret == -1) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Cannot address byte %.f in filesystem path ", "Cannot address byte %.f in filesystem path ",
(double) disk_offset); (double) disk_offset);
Text_shellsafe(open_path_pt, xorriso->info_text, 1); Text_shellsafe(open_path_pt, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
goto cannot_restore; goto cannot_restore;
} }
} }
if(ISO_NODE_IS_FILE(node))
Xorriso_sparse_init(xorriso, &sparse_state, write_fd, 0);
while(todo>0) { while(todo>0) {
wanted= buf_size; wanted= buf_size;
if(wanted>todo) if(wanted>todo)
wanted= todo; wanted= todo;
if(ISO_NODE_IS_BOOTCAT(node)) { if(ISO_NODE_IS_BOOTCAT(node)) {
ret= todo; ret= todo;
buf_pt= catcontent; buf_pt= catcontent;
} else { } else {
ret= Xorriso_iso_file_read(xorriso, data_stream, buf, wanted, 0); ret= Xorriso_iso_file_read(xorriso, data_stream, buf, wanted, 0);
buf_pt= buf; buf_pt= buf;
skipping to change at line 688 skipping to change at line 981
todo= -1; todo= -1;
} }
if(ret <= 0) { if(ret <= 0) {
sprintf(xorriso->info_text, "Cannot read all bytes from ISO file "); sprintf(xorriso->info_text, "Cannot read all bytes from ISO file ");
Text_shellsafe(img_path, xorriso->info_text, 1); Text_shellsafe(img_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
} }
break; break;
} }
read_count+= ret; read_count+= ret;
if(use_md5)
Xorriso_md5_compute(xorriso, ctx, buf_pt, ret, 0);
if(img_offset > read_count - ret) { if(img_offset > read_count - ret) {
/* skip the desired amount of bytes */ /* skip the desired amount of bytes */
if(read_count <= img_offset) if(read_count <= img_offset)
continue; continue;
buf_pt= buf_pt + (img_offset - (read_count - ret)); buf_pt= buf_pt + (img_offset - (read_count - ret));
ret= read_count - img_offset; ret= read_count - img_offset;
} }
wret= write(write_fd, buf_pt, ret); if(sparse_state == NULL)
wret= write(write_fd, buf_pt, ret);
else
wret= Xorriso_sparse_write(xorriso, sparse_state, write_fd, buf_pt, ret,
0);
if(wret>=0) { if(wret>=0) {
todo-= wret; todo-= wret;
xorriso->pacifier_byte_count+= wret; xorriso->pacifier_byte_count+= wret;
if((flag&16) && if((flag&16) &&
xorriso->pacifier_byte_count - last_p_count >= 128*1024) { xorriso->pacifier_byte_count - last_p_count >= 128*1024) {
Xorriso_pacifier_callback(xorriso, "files restored", Xorriso_pacifier_callback(xorriso, "files restored",
xorriso->pacifier_count, xorriso->pacifier_count,
xorriso->pacifier_total, "", 2 | 4 | 8); xorriso->pacifier_total, "", 2 | 4 | 8);
last_p_count= xorriso->pacifier_byte_count; last_p_count= xorriso->pacifier_byte_count;
} }
} }
if(wret != ret) { if(wret != ret) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Cannot write all bytes to disk filesystem path "); "Cannot write all bytes to disk filesystem path ");
Text_shellsafe(open_path_pt, xorriso->info_text, 1); Text_shellsafe(open_path_pt, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
break; break;
} }
} }
if(write_fd != -1)
if(use_md5) {
ret= Xorriso_md5_end(xorriso, &ctx, disk_md5, 0);
if(ret <= 0) {
sprintf(xorriso->info_text,
"Internal problem with obtaining computed MD5 for extracted data of ");
goto bad_md5;
} else {
for(i= 0; i < 16; i++)
if(iso_md5[i] != disk_md5[i])
break;
if(i < 16) {
sprintf(xorriso->info_text,
"MD5 of extracted data does not match recorded MD5 of file ");
bad_md5:;
Text_shellsafe(img_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= Xorriso_eval_problem_status(xorriso, 0, 1 | 2);
if(ret < 0)
{ret= 0; goto ex;}
}
}
}
if(write_fd != -1) {
sparse_ret= Xorriso_sparse_finish(xorriso, &sparse_state, write_fd, 0);
close(write_fd); close(write_fd);
}
write_fd= -1; write_fd= -1;
if(todo > 0 && xorriso->extract_error_mode == 2) { if(todo > 0 && xorriso->extract_error_mode == 2) {
unlink(open_path_pt); unlink(open_path_pt);
target_deleted= 1; target_deleted= 1;
} }
if(! ISO_NODE_IS_BOOTCAT(node)) if(! ISO_NODE_IS_BOOTCAT(node))
Xorriso_iso_file_close(xorriso, &data_stream, 0); Xorriso_iso_file_close(xorriso, &data_stream, 0);
data_stream= NULL; data_stream= NULL;
if(temp_path==open_path_pt && !target_deleted) { if(temp_path==open_path_pt && !target_deleted) {
ret= rename(temp_path, disk_path); ret= rename(temp_path, disk_path);
skipping to change at line 741 skipping to change at line 1066
Text_shellsafe(temp_path, xorriso->info_text, 1); Text_shellsafe(temp_path, xorriso->info_text, 1);
strcat(xorriso->info_text, " to final disk path "); strcat(xorriso->info_text, " to final disk path ");
Text_shellsafe(disk_path, xorriso->info_text, 1 | 2); Text_shellsafe(disk_path, xorriso->info_text, 1 | 2);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
unlink(temp_path); unlink(temp_path);
ret= 0; goto ex; ret= 0; goto ex;
} }
} }
ret= -(todo > 0); ret= -(todo > 0);
l_errno= 0; l_errno= 0;
if(sparse_ret <= 0) {
strcpy(xorriso->info_text, "Could not finalize sparse extraction of ");
Text_shellsafe(disk_path, xorriso->info_text, 1 | 2);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text,
sparse_ret < 0 ? errno : 0, "FAILURE", 0);
}
} else if(LIBISO_ISLNK(node)) { } else if(LIBISO_ISLNK(node)) {
what= "symbolic link"; what= "symbolic link";
link_target= (char *) iso_symlink_get_dest((IsoSymlink *) node); link_target= (char *) iso_symlink_get_dest((IsoSymlink *) node);
ret= symlink(link_target, disk_path); ret= symlink(link_target, disk_path);
l_errno= errno; l_errno= errno;
} else if(LIBISO_ISCHR(node)) { } else if(LIBISO_ISCHR(node)) {
what= "character device"; what= "character device";
if(xorriso->allow_restore!=2) { if(xorriso->allow_restore!=2) {
skipping to change at line 839 skipping to change at line 1170
close(write_fd); close(write_fd);
if(ret <= 0 && xorriso->extract_error_mode == 2 && open_path_pt != NULL) if(ret <= 0 && xorriso->extract_error_mode == 2 && open_path_pt != NULL)
unlink(open_path_pt); unlink(open_path_pt);
} }
Xorriso_free_meM(buf); Xorriso_free_meM(buf);
Xorriso_free_meM(temp_path); Xorriso_free_meM(temp_path);
if(catcontent != NULL) if(catcontent != NULL)
free(catcontent); free(catcontent);
if(data_stream!=NULL) if(data_stream!=NULL)
Xorriso_iso_file_close(xorriso, &data_stream, 0); Xorriso_iso_file_close(xorriso, &data_stream, 0);
if(ctx != NULL)
Xorriso_md5_end(xorriso, &ctx, disk_md5, 0);
if(sparse_state != NULL)
Xorriso_sparse_finish(xorriso, &sparse_state, -1, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
return(ret); return(ret);
} }
/* Handle overwrite situation in disk filesystem. /* Handle overwrite situation in disk filesystem.
@param node intended source of overwriting or NULL @param node intended source of overwriting or NULL
@param flag @param flag
bit4= return 3 on rejection by exclusion or user bit4= return 3 on rejection by exclusion or user
bit6= permission to call Xorriso_make_accessible() bit6= permission to call Xorriso_make_accessible()
*/ */
skipping to change at line 1970 skipping to change at line 2305
if(mem_lut != xorriso->last_update_time) if(mem_lut != xorriso->last_update_time)
Xorriso_pacifier_callback(xorriso, "blocks read", Xorriso_pacifier_callback(xorriso, "blocks read",
xorriso->pacifier_count, 0, "", 1 | 8 | 16 | 32); xorriso->pacifier_count, 0, "", 1 | 8 | 16 | 32);
ret= 1; ret= 1;
ex:; ex:;
Xorriso_free_meM(eff_img_path); Xorriso_free_meM(eff_img_path);
Xorriso_free_meM(eff_disk_path); Xorriso_free_meM(eff_disk_path);
return(ret); return(ret);
} }
/* @param flag bit1= for Xorriso_check_interval(): no pacifier messages /* @param flag bit0= ignore node and img_path, operate on whole medium
bit1= for Xorriso_check_interval(): no pacifier messages
*/ */
int Xorriso_read_file_data(struct XorrisO *xorriso, IsoNode *node, int Xorriso_read_file_data(struct XorrisO *xorriso, IsoNode *node,
char *img_path, char *disk_path, char *img_path, char *disk_path,
off_t img_offset, off_t disk_offset, off_t img_offset, off_t disk_offset,
off_t bytes, int flag) off_t bytes, int flag)
{ {
int ret, i, lba_count= 0, *start_lbas= NULL, *end_lbas= NULL, read_chunk= 16; int ret, i, lba_count= 0, *start_lbas= NULL, *end_lbas= NULL, read_chunk= 16;
int lba, count, blocks, quality, spot, bad_extract= 0; int lba, count, blocks, quality, spot, bad_extract= 0;
int data_to_skip= 0;
uint32_t indev_blocks;
off_t size= 0, file_base_bytes= 0, file_processed_bytes= 0, img_adr; off_t size= 0, file_base_bytes= 0, file_processed_bytes= 0, img_adr;
off_t new_file_base_bytes, upto_file_bytes, start_byte= 0; off_t new_file_base_bytes, upto_file_bytes, start_byte= 0;
off_t *section_sizes = NULL; off_t *section_sizes = NULL;
struct SpotlisT *spotlist= NULL; struct SpotlisT *spotlist= NULL;
struct CheckmediajoB *job= NULL; struct CheckmediajoB *job= NULL;
upto_file_bytes= img_offset + bytes; upto_file_bytes= img_offset + bytes;
data_to_skip= img_offset % (off_t) 2048;
/* >>> make Xorriso_check_interval() ready for copying in byte granularity */ if(flag & 1) {
if(img_offset % (off_t) 2048) { lba_count= 1;
sprintf(xorriso->info_text, Xorriso_alloc_meM(start_lbas, int, 1);
"Image address offset is not a multiple of 2048"); Xorriso_alloc_meM(end_lbas, int, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_alloc_meM(section_sizes, off_t, 1);
ret= 0; goto ex; start_lbas[0]= 0;
} ret= Xorriso_obtain_indev_readsize(xorriso, &indev_blocks, 0);
if(ret > 0)
ret= Xorriso__start_end_lbas(node, &lba_count, &start_lbas, &end_lbas, end_lbas[0]= indev_blocks - 1;
&section_sizes, &size, 0); else
if(ret <= 0) { end_lbas[0]= 0x7ffffffe;
Xorriso_process_msg_queues(xorriso,0); size= ((off_t) end_lbas[0]) * 2048;
sprintf(xorriso->info_text, "File object "); section_sizes[0]= size;
Text_shellsafe(img_path, xorriso->info_text, 1); } else {
strcat(xorriso->info_text, ret= Xorriso__start_end_lbas(node, &lba_count, &start_lbas, &end_lbas,
" is currently not a data file from the loaded image"); &section_sizes, &size, 0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); if(ret <= 0) {
goto ex; Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, "File object ");
Text_shellsafe(img_path, xorriso->info_text, 1);
strcat(xorriso->info_text,
" is currently not a data file from the loaded image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto ex;
}
} }
if(img_offset + bytes < size && bytes > 0) if(img_offset + bytes < size && bytes > 0)
size= img_offset + bytes; size= img_offset + bytes;
ret= Checkmediajob_new(&job, 0); ret= Checkmediajob_new(&job, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
if(xorriso->check_media_default != NULL) if(xorriso->check_media_default != NULL)
Checkmediajob_copy(xorriso->check_media_default, job, 0); Checkmediajob_copy(xorriso->check_media_default, job, 0);
job->min_lba= -1; job->min_lba= -1;
skipping to change at line 2047 skipping to change at line 2393
} }
/* Eventually adjust first interval start */ /* Eventually adjust first interval start */
img_adr= ((off_t) lba) * (off_t) 2048; img_adr= ((off_t) lba) * (off_t) 2048;
if(file_base_bytes < img_offset) { if(file_base_bytes < img_offset) {
img_adr+= img_offset - file_base_bytes; img_adr+= img_offset - file_base_bytes;
lba= img_adr / (off_t) 2048; lba= img_adr / (off_t) 2048;
count= end_lbas[i] + 1 - lba; count= end_lbas[i] + 1 - lba;
file_base_bytes= img_offset; file_base_bytes= img_offset;
} }
/* Eventually omit surplus blocks */ /* Omit surplus blocks */
if(new_file_base_bytes > upto_file_bytes) if(new_file_base_bytes > upto_file_bytes)
count-= (new_file_base_bytes - upto_file_bytes) / (off_t) 2048; count-= (new_file_base_bytes - upto_file_bytes) / (off_t) 2048;
/* Adjust job */ /* Adjust job */
job->data_to_offset= file_processed_bytes - img_adr + disk_offset; job->data_to_offset= file_processed_bytes - img_adr + disk_offset;
job->data_to_limit= size - file_base_bytes; job->data_to_limit= size - file_base_bytes;
job->data_to_skip= data_to_skip;
data_to_skip= 0;
file_processed_bytes+= ((off_t) count) * (off_t) 2048; file_processed_bytes+= ((off_t) count) * (off_t) 2048;
ret= Xorriso_check_interval(xorriso, spotlist, job, lba, count, read_chunk, ret= Xorriso_check_interval(xorriso, spotlist, job, lba, count, read_chunk,
0, (flag & 2)); 0, (flag & 2));
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
if (ret == 2) { if (ret == 2) {
sprintf(xorriso->info_text, "Attempt aborted to extract data from "); sprintf(xorriso->info_text, "Attempt aborted to extract data from ");
Text_shellsafe(img_path, xorriso->info_text, 1); Text_shellsafe(img_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex; ret= 0; goto ex;
skipping to change at line 2108 skipping to change at line 2455
free((char *) start_lbas); free((char *) start_lbas);
if(end_lbas != NULL) if(end_lbas != NULL)
free((char *) end_lbas); free((char *) end_lbas);
if(section_sizes != NULL) if(section_sizes != NULL)
free((char *) section_sizes); free((char *) section_sizes);
Spotlist_destroy(&spotlist, 0); Spotlist_destroy(&spotlist, 0);
Checkmediajob_destroy(&job, 0); Checkmediajob_destroy(&job, 0);
return(ret); return(ret);
} }
int Xorriso_extract_boot_images(struct XorrisO *xorriso, char *disk_dir_path,
int flag)
{
int ret, img_count= 0, i, was_problem= 0;
char **imgs= NULL, *eff_path= NULL, *cpt, *eff_namept;
struct stat stbuf;
off_t byte_offset, byte_size;
Xorriso_alloc_meM(eff_path, char, SfileadrL);
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_dir_path,
eff_path, 2 | 4);
if(ret <= 0)
goto ex;
if(strlen(eff_path) > SfileadrL - 80) {
sprintf(xorriso->info_text,
"-extract_boot_images: disk_path is too long (%lu)\n",
(unsigned long int) strlen(eff_path));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
ret= stat(eff_path, &stbuf);
if(ret == 0) {
if(!S_ISDIR(stbuf.st_mode)) {
sprintf(xorriso->info_text,
"-extract_boot_images: disk_path is not a directory : ");
Text_shellsafe(eff_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
} else {
ret= mkdir(eff_path, 0777);
if(ret == -1) {
sprintf(xorriso->info_text,
"-extract_boot_images: cannot create directory : ");
Text_shellsafe(eff_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
ret= 0; goto ex;
}
}
strcat(eff_path, "/");
eff_namept= eff_path + strlen(eff_path);
ret= Xorriso_list_boot_images(xorriso, &imgs, &img_count, 0);
if(ret <= 0)
goto ex;
/* Interpret list and create files */
for(i= 0; i < img_count; i++) {
ret= Xorriso_eval_problem_status(xorriso, 1, 1 | 2);
if(ret < 0)
{ret= 0; goto ex;}
cpt= strchr(imgs[i], '/');
if(cpt == NULL)
continue;
*cpt= 0;
cpt+= 2;
ret= Sfile_text_to_off_t(cpt, &byte_offset, 0);
if(ret <= 0)
continue;
cpt+= ret;
if(*cpt == 0)
continue;
cpt++;
ret= Sfile_text_to_off_t(cpt, &byte_size, 0);
if(ret <= 0)
continue;
strcpy(eff_namept, imgs[i]);
sprintf(xorriso->info_text, "%s : offset=%.f size=%.f\n",
eff_path, (double) byte_offset, (double) byte_size);
Xorriso_info(xorriso, 0);
ret= stat(eff_path, &stbuf);
if(ret != -1) {
sprintf(xorriso->info_text,
"-extract_boot_images: File already exists on disk: ");
Text_shellsafe(eff_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
continue;
}
ret= Xorriso_read_file_data(xorriso, NULL, NULL, eff_path,
byte_offset, (off_t) 0, byte_size, 1);
if(ret <= 0)
was_problem= 1;
}
ret= Xorriso_eval_problem_status(xorriso, 1, 1 | 2);
if(ret < 0 || was_problem)
{ret= 0; goto ex;}
ret= 1;
ex:;
Xorriso_free_meM(eff_path);
Xorriso_list_boot_images(xorriso, &imgs, &img_count, 1 << 15);
return(ret);
}
/* @param node Opaque handle to IsoNode which is to be inquired instead of path if it is not NULL. /* @param node Opaque handle to IsoNode which is to be inquired instead of path if it is not NULL.
@param path is used as address if node is NULL. @param path is used as address if node is NULL.
@param flag bit0= do not report to result but only indicate outcome @param flag bit0= do not report to result but only indicate outcome
by return value by return value
bit1= silently ignore nodes without MD5 bit1= silently ignore nodes without MD5
bit2= do not only report mismatches but also matches bit2= do not only report mismatches but also matches
@return 3= not a data file @return 3= not a data file
2= no MD5 attached to node 2= no MD5 attached to node
1= ok, MD5 compared and matching 1= ok, MD5 compared and matching
0= not ok, MD5 mismatch 0= not ok, MD5 mismatch
 End of changes. 19 change blocks. 
24 lines changed or deleted 467 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)