LBA sorted processing of -compare_r and -update_r for smoother MMC reading

This commit is contained in:
2009-05-16 16:56:21 +00:00
parent 4fdf92da42
commit 9b33a3eaf6
5 changed files with 226 additions and 15 deletions

View File

@ -91,8 +91,8 @@ int Xorriso_read_file_data(struct XorrisO *xorriso, IsoNode *node,
int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
char *path, IsoNode **node, int flag);
int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *node, int lba,
char path[SfileadrL], int flag);
int Xorriso_path_from_lba(struct XorrisO *xorriso, IsoNode *node, int lba,
char path[SfileadrL], int flag);
#define LIBISO_ISDIR(node) (iso_node_get_type(node) == LIBISO_DIR)
@ -470,8 +470,8 @@ int Xorriso_record_boot_info(struct XorrisO *xorriso, int flag)
Xorriso__file_start_lba((IsoNode *) bootimg_node,
&(xorriso->loaded_boot_bin_lba), 0);
if(bootcat_node != NULL)
Xorriso_path_from_node(xorriso, (IsoNode *) bootcat_node, 0,
xorriso->loaded_boot_cat_path, 0);
Xorriso_path_from_lba(xorriso, (IsoNode *) bootcat_node, 0,
xorriso->loaded_boot_cat_path, 0);
return(1);
}
@ -1309,7 +1309,7 @@ int Xorriso_write_session(struct XorrisO *xorriso, int flag)
sprintf(xorriso->info_text, "Patching alleged isolinux boot image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= Xorriso_path_from_node(xorriso, NULL, xorriso->loaded_boot_bin_lba,
ret= Xorriso_path_from_lba(xorriso, NULL, xorriso->loaded_boot_bin_lba,
sfe, 1);
if(ret < 0)
goto ex;
@ -2470,6 +2470,7 @@ cannot_lstat:;
}
if(node==NULL) {
if(S_ISLNK(stbuf.st_mode)) {
/* ??? NG : A80107 : is this solved now ? */
@ -2488,6 +2489,7 @@ cannot_lstat:;
{ret= 0; goto was_problem;}
}
} else {
ret= Xorriso_tree_graft_node(xorriso, volume, dir, srcpt, img_name,
"", img_path, (off_t) 0, (off_t) 0,
&node, 0);
@ -4194,7 +4196,7 @@ no_boot:;
image= NULL;
if(ret != 1)
goto no_boot;
ret= Xorriso_path_from_node(xorriso, NULL, xorriso->loaded_boot_bin_lba,
ret= Xorriso_path_from_lba(xorriso, NULL, xorriso->loaded_boot_bin_lba,
path, 1);
if(ret > 0)
bin_path_valid= 1;
@ -6605,6 +6607,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
action= 0;
hflag= 16*!(flag&2);
ret= 1;
if(action==1) { /* rm (including rmdir) */
ret= Xorriso_fake_stbuf(xorriso, abs_path, &dir_stbuf, &node, 1);
if(ret>0) {
@ -6650,7 +6653,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_report_damage(xorriso, show_path, node, 0);
} else if(action == 22) {
ret= Xorriso_report_lba(xorriso, show_path, node, 0);
} else if(action == 23) {
} else if(action == 23) { /* internal: memorize path of last matching node */
ret= Findjob_set_found_path(job, show_path, 0);
} else if(action == 24) {
ret= Xorriso_getfacl(xorriso, (void *) node, show_path, NULL, 0);
@ -6666,6 +6669,11 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_set_filter(xorriso, (void *) node, show_path, target, 1 | 2);
} else if(action == 29) { /* show_stream */
ret= Xorriso_show_stream(xorriso, (void *) node, show_path, 1 | 2);
} else if(action == 30) { /* internal: count */
xorriso->node_counter++;
} else if(action == 31) { /* internal: register */
if(xorriso->node_counter < xorriso->node_array_size)
xorriso->node_array[xorriso->node_counter++]= (void *) node;
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
@ -7218,10 +7226,66 @@ ex:;
}
int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *in_node,
char path[SfileadrL], int flag)
{
int ret, i, comp_count= 0;
IsoNode *node, *parent, **components= NULL;
char *wpt, *npt;
for(node= in_node; 1; node= parent) {
parent= (IsoNode *) iso_node_get_parent(node);
if(parent == node)
break;
comp_count++;
}
if(comp_count == 0) {
strcpy(path, "/");
return(1);
}
components= calloc(comp_count, sizeof(IsoNode *));
if(components == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
ret= -1; goto ex;
}
i= comp_count;
for(node= in_node; 1; node= parent) {
parent= (IsoNode *) iso_node_get_parent(node);
if(parent == node)
break;
components[--i]= node;
}
wpt= path;
for(i= 0; i < comp_count; i++) {
npt= (char *) iso_node_get_name(components[i]);
if((wpt - path) + strlen(npt) + 1 >= SfileadrL) {
/* >>> path is getting much too long */;
ret= -1; goto ex;
}
*(wpt++)= '/';
strcpy(wpt, npt);
wpt+= strlen(npt);
*wpt= 0;
}
ret= 1;
ex:;
if(components != NULL)
free(components);
return(ret);
}
/* <<< The lookup from node pointer will be done by Xorriso_path_from_node()
(Currently it runs a full tree traversal)
Parameter node and flag bit0 will vanish then
*/
/* @param flag bit0= use lba rather than node pointer
*/
int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *node, int lba,
char path[SfileadrL], int flag)
int Xorriso_path_from_lba(struct XorrisO *xorriso, IsoNode *node, int lba,
char path[SfileadrL], int flag)
{
int ret;
struct FindjoB *job= NULL;
@ -7257,6 +7321,114 @@ int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *node, int lba,
}
int Xorriso__findi_sorted_cmp(const void *p1, const void *p2)
{
int ret;
IsoNode *n1, *n2;
n1= *((IsoNode **) p1);
n2= *((IsoNode **) p2);
ret= Xorriso__node_lba_cmp(&n1, &n2);
if(ret)
return (ret > 0 ? 1 : -1);
ret= iso_node_cmp_ino(n1, n2, 0);
return(ret);
}
/* @param flag bit0= do not dive into trees
bit1= do not perform job->action on resulting node array
*/
int Xorriso_findi_sorted(struct XorrisO *xorriso, struct FindjoB *job,
int filec, char **filev, int flag)
{
int i, ret;
struct FindjoB array_job;
struct stat dir_stbuf;
IsoNode *node;
char abs_path[SfileadrL];
/* <<< */
if(job->action>=9 && job->action<=13) { /* actions which have own findjobs */
/* >>> cannot deal with chained find yet */;
return(-1);
}
/* >>> if action == find : array_job would need to replace the hindmost */
memcpy(&array_job, job, sizeof(struct FindjoB));
/* Count matching nodes */
Xorriso_destroy_node_array(xorriso, 0);
array_job.action= 30; /* internal: count */
for(i= 0; i < filec; i++) {
if(flag & 1) {
xorriso->node_counter++;
continue;
}
array_job.start_path= filev[i];
ret= Xorriso_findi(xorriso, &array_job, NULL, (off_t) 0, NULL,
filev[i], &dir_stbuf, 0, 0);
if(ret <= 0)
goto ex;
}
if(xorriso->node_counter <= 0)
return(1);
/* Copy matching nodes into allocated array */
xorriso->node_array_size= xorriso->node_counter;
xorriso->node_array= calloc(xorriso->node_array_size, sizeof(IsoNode *));
if(xorriso->node_array == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
return(-1);
}
array_job.action= 31; /* internal: register */
xorriso->node_counter= 0;
for(i= 0; i < filec; i++) {
if(flag & 1) {
ret= Xorriso_get_node_by_path(xorriso, filev[i], NULL, &node, 0);
if(ret <= 0)
goto ex;
if(xorriso->node_counter < xorriso->node_array_size)
xorriso->node_array[xorriso->node_counter++]= (void *) node;
continue;
}
array_job.start_path= filev[i];
ret= Xorriso_findi(xorriso, &array_job, NULL, (off_t) 0, NULL,
filev[i], &dir_stbuf, 0, 0);
if(ret <= 0)
goto ex;
}
qsort(xorriso->node_array, xorriso->node_counter, sizeof(IsoNode *),
Xorriso__findi_sorted_cmp);
if(flag & 2)
return(1);
/* Perform job->action on xorriso->node_array */;
/* >>> if action == find : perform action of the hindmost */
for(i= 0; i < xorriso->node_counter; i++) {
node= xorriso->node_array[i];
ret= Xorriso_path_from_node(xorriso, node, abs_path, 0);
if(ret <= 0)
goto ex;
ret= Xorriso_findi_action(xorriso, job, NULL, (off_t) 0,
abs_path, abs_path, node, 0, 1);
if(ret <= 0)
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex;
}
ret= 1;
ex:;
return(ret);
}
/* @param flag bit0= do not mark image as changed */
int Xorriso_set_volid(struct XorrisO *xorriso, char *volid, int flag)
{