Updating sorted link array before usage after image manipulations

This commit is contained in:
Thomas Schmitt 2009-07-25 18:18:05 +00:00
parent d69acf1374
commit b3bdfec3b1
5 changed files with 193 additions and 44 deletions

View File

@ -5419,6 +5419,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->hln_count= 0; m->hln_count= 0;
m->hln_array= NULL; m->hln_array= NULL;
m->hln_targets= NULL; m->hln_targets= NULL;
m->hln_change_pending= 0;
m->di_do_widen= NULL; m->di_do_widen= NULL;
m->di_disk_paths= NULL; m->di_disk_paths= NULL;
m->di_iso_paths= NULL; m->di_iso_paths= NULL;
@ -5525,6 +5526,14 @@ int Xorriso_destroy(struct XorrisO **xorriso, int flag)
} }
int Xorriso_set_change_pending(struct XorrisO *xorriso, int flag)
{
xorriso->volset_change_pending= 1;
xorriso->hln_change_pending= 1;
return(1);
}
int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize,
int flag) int flag)
/* /*
@ -12975,8 +12984,7 @@ int Xorriso_restore_sorted(struct XorrisO *xorriso, int count,
{ {
int i, ret, with_node_array= 0, hflag= 0, hret; int i, ret, with_node_array= 0, hflag= 0, hret;
if(xorriso->hln_array == NULL && if(!(((xorriso->ino_behavior & 16) && xorriso->do_restore_sort_lba) ||
!(((xorriso->ino_behavior & 16) && xorriso->do_restore_sort_lba) ||
(xorriso->ino_behavior & 4) || (flag & 1))) { (xorriso->ino_behavior & 4) || (flag & 1))) {
ret= Xorriso_make_hln_array(xorriso, 0); ret= Xorriso_make_hln_array(xorriso, 0);
if(ret<=0) if(ret<=0)
@ -13007,7 +13015,7 @@ int Xorriso_restore_sorted(struct XorrisO *xorriso, int count,
/* Allocate and fill node array */ /* Allocate and fill node array */
if(xorriso->node_counter <= 0) if(xorriso->node_counter <= 0)
{ret= 2; goto ex;} {ret= 2; goto ex;}
ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, 0,
!xorriso->do_restore_sort_lba); !xorriso->do_restore_sort_lba);
if(ret<=0) if(ret<=0)
goto ex; goto ex;

View File

@ -420,10 +420,10 @@ files or trees to disk:
<P> <P>
<DL> <DL>
<DT><H3>Download as source code (see README):</H3></DT> <DT><H3>Download as source code (see README):</H3></DT>
<DD><A HREF="xorriso-0.4.0.pl00.tar.gz">xorriso-0.4.0.pl00.tar.gz</A> <DD><A HREF="xorriso-0.4.0.pl01.tar.gz">xorriso-0.4.0.pl01.tar.gz</A>
(1260 KB). (1260 KB).
</DD> </DD>
<DD>(Released 28 Jun 2009)</DD> <DD>(Released 20 Jul 2009)</DD>
</DL> </DL>
</DD> </DD>
</DL> </DL>
@ -460,6 +460,15 @@ Bug fixes towards xorriso-0.3.8.pl00:
</P> </P>
<P>
Bug fix towards xorriso-0.4.0.pl00:
<UL>
<LI>xorriso -as mkisofs did not understand the -C option of growisofs any more
</LI>
</UL>
</P>
<P> <P>
Enhancements towards previous stable version xorriso-0.3.8.pl00: Enhancements towards previous stable version xorriso-0.3.8.pl00:
<UL> <UL>
@ -513,15 +522,19 @@ cdrecord and mkisofs.</DT>
<DT><H3>Development snapshot, version 0.4.1 :</H3></DT> <DT><H3>Development snapshot, version 0.4.1 :</H3></DT>
<DD>Bug fixes towards xorriso-0.4.0.pl00: <DD>Bug fixes towards xorriso-0.4.0.pl00:
<UL> <UL>
<LI>- none yet -</LI> <LI>xorriso -as mkisofs did not understand the -C option of growisofs any more
</LI>
<!-- <!--
<LI>- none yet -</LI>
--> -->
</UL> </UL>
</DD> </DD>
<DD>Enhancements towards stable version 0.4.0.pl00: <DD>Enhancements towards stable version 0.4.0.pl01:
<UL> <UL>
<LI>- none yet -</LI> <LI>Options -lsl and lsdl now display correct link counts if -hardlinks is on
</LI>
<!-- <!--
<LI>- none yet -</LI>
--> -->
</UL> </UL>
</DD> </DD>

View File

@ -107,7 +107,7 @@ struct XorrisO { /* the global context of xorriso */
bit3= with update: bit3= with update:
Do not try to detect hardlink splits and joinings. Do not try to detect hardlink splits and joinings.
bit4= with extract: bit4= with extract:
Do not automatically create hln arrays Do not create or use hln arrays if sort_lba_on
*/ */
int do_joliet; int do_joliet;
@ -403,6 +403,7 @@ struct XorrisO { /* the global context of xorriso */
int hln_count; int hln_count;
void **hln_array; void **hln_array;
void **hln_targets; void **hln_targets;
int hln_change_pending; /* whether a change was made since hln creation */
/* >>> this should count all temp_mem and thus change its name */ /* >>> this should count all temp_mem and thus change its name */
off_t node_targets_availmem; off_t node_targets_availmem;
@ -432,6 +433,8 @@ struct XorrisO { /* the global context of xorriso */
}; };
int Xorriso_set_change_pending(struct XorrisO *xorriso, int flag);
int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag); int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag);
int Xorriso_result(struct XorrisO *xorriso, int flag); int Xorriso_result(struct XorrisO *xorriso, int flag);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2009.07.23.103728" #define Xorriso_timestamP "2009.07.25.181857"

View File

@ -208,21 +208,23 @@ int Xorriso_destroy_di_array(struct XorrisO *xorriso, int flag)
} }
int Xorriso_new_node_array(struct XorrisO *xorriso, off_t mem_limit, int flag) int Xorriso_new_node_array(struct XorrisO *xorriso, off_t mem_limit,
int addon_nodes, int flag)
{ {
int i; int i;
if(xorriso->node_counter <= 0) if(xorriso->node_counter <= 0)
return(1); return(1);
xorriso->node_array= calloc(xorriso->node_counter, sizeof(IsoNode *)); xorriso->node_array= calloc(xorriso->node_counter + addon_nodes,
sizeof(IsoNode *));
if(xorriso->node_array == NULL) { if(xorriso->node_array == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0); Xorriso_no_malloc_memory(xorriso, NULL, 0);
return(-1); return(-1);
} }
for(i= 0; i < xorriso->node_counter; i++) for(i= 0; i < xorriso->node_counter + addon_nodes; i++)
xorriso->node_array[i]= NULL; xorriso->node_array[i]= NULL;
xorriso->node_array_size= xorriso->node_counter; xorriso->node_array_size= xorriso->node_counter + addon_nodes;
xorriso->node_counter= 0; xorriso->node_counter= 0;
return(1); return(1);
} }
@ -284,6 +286,25 @@ int Xorriso__findi_sorted_ino_cmp(const void *p1, const void *p2)
} }
/* Not suitable for qsort() but for cross-array comparisons.
p1 and p2 are actually IsoNode *p1, IsoNode *p2
*/
int Xorriso__hln_cmp(const void *p1, const void *p2)
{
int ret;
ret= Xorriso__findi_sorted_ino_cmp(&p1, &p2);
if(ret)
return (ret > 0 ? 1 : -1);
if(p1 != p2)
return(p1 < p2 ? -1 : 1);
return(0);
}
/*
p1 and p2 are actually IsoNode **p1, IsoNode **p2
*/
int Xorriso__findi_sorted_cmp(const void *p1, const void *p2) int Xorriso__findi_sorted_cmp(const void *p1, const void *p2)
{ {
int ret; int ret;
@ -2416,7 +2437,6 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
IsoNode **node, int flag) IsoNode **node, int flag)
{ {
int ret, min_hl, max_hl, node_idx, i; int ret, min_hl, max_hl, node_idx, i;
char img_path[SfileadrL];
IsoImage *volume; IsoImage *volume;
memset((char *) stbuf, 0, sizeof(struct stat)); memset((char *) stbuf, 0, sizeof(struct stat));
@ -2492,10 +2512,7 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
if(i == node_idx) if(i == node_idx)
continue; continue;
/* Check whether node is still valid */ /* Check whether node is still valid */
ret= Xorriso_path_from_node(xorriso, xorriso->hln_array[i], img_path, 0); if(iso_node_get_parent(xorriso->hln_array[i]) != NULL)
if(ret < 0)
return(ret);
if(ret > 0)
stbuf->st_nlink++; stbuf->st_nlink++;
} }
} }
@ -2917,7 +2934,7 @@ cannot_lstat:;
Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
xorriso->pacifier_total, "", 0); xorriso->pacifier_total, "", 0);
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
if(source_is_dir) { if(source_is_dir) {
if(do_not_dive) { if(do_not_dive) {
sprintf(xorriso->info_text, "Did not follow mount point : %s", sprintf(xorriso->info_text, "Did not follow mount point : %s",
@ -3035,7 +3052,7 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
} }
Xorriso_transfer_properties(xorriso, &stbuf, disk_path, node, Xorriso_transfer_properties(xorriso, &stbuf, disk_path, node,
((flag & 2) >> 1) | ((flag & 1) << 5) | (flag & 4)); ((flag & 2) >> 1) | ((flag & 1) << 5) | (flag & 4));
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
return(1); return(1);
} }
@ -3217,7 +3234,7 @@ handle_path_node:;
return(0); return(0);
} }
dir= hdir; dir= hdir;
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
iso_node_set_ctime((IsoNode *) dir, time(NULL)); iso_node_set_ctime((IsoNode *) dir, time(NULL));
iso_node_set_uid((IsoNode *) dir, geteuid()); iso_node_set_uid((IsoNode *) dir, geteuid());
iso_node_set_gid((IsoNode *) dir, getegid()); iso_node_set_gid((IsoNode *) dir, getegid());
@ -3259,7 +3276,7 @@ attach_source:;
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0); return(0);
} }
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
iso_node_set_name(node, apt); iso_node_set_name(node, apt);
xorriso->pacifier_count++; xorriso->pacifier_count++;
@ -6238,7 +6255,7 @@ dir_not_removed:;
if(flag&16) if(flag&16)
xorriso->pacifier_count++; xorriso->pacifier_count++;
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
ret= 1+!!is_dir; ret= 1+!!is_dir;
ex:; ex:;
if(sfe!=NULL) if(sfe!=NULL)
@ -7181,7 +7198,7 @@ int Xorriso_set_st_mode(struct XorrisO *xorriso, char *in_path,
sprintf(xorriso->info_text,"Permissions now: %-5.5o %s", sprintf(xorriso->info_text,"Permissions now: %-5.5o %s",
(unsigned int) (mode & 0xffff), Text_shellsafe(path, sfe, 0)); (unsigned int) (mode & 0xffff), Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
return(1); return(1);
} }
@ -7198,7 +7215,7 @@ int Xorriso_set_uid(struct XorrisO *xorriso, char *in_path, uid_t uid,
return(ret); return(ret);
iso_node_set_uid(node, uid); iso_node_set_uid(node, uid);
iso_node_set_ctime(node, time(NULL)); iso_node_set_ctime(node, time(NULL));
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
return(1); return(1);
} }
@ -7215,7 +7232,7 @@ int Xorriso_set_gid(struct XorrisO *xorriso, char *in_path, gid_t gid,
return(ret); return(ret);
iso_node_set_gid(node, gid); iso_node_set_gid(node, gid);
iso_node_set_ctime(node, time(NULL)); iso_node_set_ctime(node, time(NULL));
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
return(1); return(1);
} }
@ -7239,7 +7256,7 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
iso_node_set_mtime(node, t); iso_node_set_mtime(node, t);
if(!(flag&(2|256))) if(!(flag&(2|256)))
iso_node_set_ctime(node, time(NULL)); iso_node_set_ctime(node, time(NULL));
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
return(1); return(1);
} }
@ -8121,6 +8138,21 @@ ex:;
} }
int Xorriso_node_is_valid(struct XorrisO *xorriso, IsoNode *in_node, int flag)
{
IsoNode *node, *parent;
for(node= in_node; 1; node= parent) {
parent= (IsoNode *) iso_node_get_parent(node);
if(parent == node)
break;
if(parent == NULL)
return(0); /* Node is not in the tree (any more) */
}
return(1);
}
int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *in_node, int Xorriso_path_from_node(struct XorrisO *xorriso, IsoNode *in_node,
char path[SfileadrL], int flag) char path[SfileadrL], int flag)
{ {
@ -8291,7 +8323,7 @@ int Xorriso_findi_sorted(struct XorrisO *xorriso, struct FindjoB *job,
} }
/* Copy matching nodes into allocated array */ /* Copy matching nodes into allocated array */
ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, 0); ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, 0, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
array_job.action= 31; /* internal: register */ array_job.action= 31; /* internal: register */
@ -8361,7 +8393,7 @@ int Xorriso_set_volid(struct XorrisO *xorriso, char *volid, int flag)
return(ret); return(ret);
iso_image_set_volume_id(volume, volid); iso_image_set_volume_id(volume, volid);
if(!(flag&1)) if(!(flag&1))
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Volume ID: '%s'",iso_image_get_volume_id(volume)); sprintf(xorriso->info_text,"Volume ID: '%s'",iso_image_get_volume_id(volume));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
@ -10560,7 +10592,7 @@ int Xorriso_setfacl(struct XorrisO *xorriso, void *in_node, char *path,
} }
ret= 0; goto ex; ret= 0; goto ex;
} }
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
ret= 1; ret= 1;
ex:; ex:;
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
@ -10690,7 +10722,7 @@ int Xorriso_setfattr(struct XorrisO *xorriso, void *in_node, char *path,
} }
ret= 0; goto ex; ret= 0; goto ex;
} }
xorriso->volset_change_pending= 1; Xorriso_set_change_pending(xorriso, 0);
ret= 1; ret= 1;
ex:; ex:;
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
@ -11725,7 +11757,7 @@ int Xorriso_status_zisofs(struct XorrisO *xorriso, char *filter, FILE *fp,
} }
int Xorriso_all_node_array(struct XorrisO *xorriso, int flag) int Xorriso_all_node_array(struct XorrisO *xorriso, int addon_nodes, int flag)
{ {
int ret; int ret;
struct FindjoB *job= NULL; struct FindjoB *job= NULL;
@ -11742,7 +11774,7 @@ int Xorriso_all_node_array(struct XorrisO *xorriso, int flag)
&dir_stbuf, 0, 0); &dir_stbuf, 0, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, 0); ret= Xorriso_new_node_array(xorriso, xorriso->temp_mem_limit, addon_nodes, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
Findjob_set_action_target(job, 31, NULL, 0); Findjob_set_action_target(job, 31, NULL, 0);
@ -11757,20 +11789,43 @@ ex:;
} }
/* @param flag bit0= overwrite existing hln_array (else return 2) int Xorriso_remake_hln_array(struct XorrisO *xorriso, int flag)
*/
int Xorriso_make_hln_array(struct XorrisO *xorriso, int flag)
{ {
int ret; int ret, addon_nodes= 0, i, old_count, old_pt, new_pt;
IsoNode **old_nodes;
char **old_targets;
if(xorriso->hln_array != NULL && !(flag & 1)) /* Count hln_targets of which the node has been deleted meanwhile */
return(2); for(i= 0; i < xorriso->hln_count; i++) {
Xorriso_destroy_hln_array(xorriso, 0); if(xorriso->hln_targets[i] == NULL)
continue;
ret= Xorriso_all_node_array(xorriso, 0); if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
continue;
addon_nodes++;
}
ret= Xorriso_all_node_array(xorriso, addon_nodes, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
if(addon_nodes > 0) {
/* Transfer delete nodes with hln_target to node array */
for(i= 0; i < xorriso->hln_count; i++) {
if(xorriso->hln_targets[i] == NULL)
continue;
if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
continue;
if(xorriso->node_counter < xorriso->node_array_size) {
xorriso->node_array[xorriso->node_counter++]= xorriso->hln_array[i];
iso_node_ref(xorriso->node_array[xorriso->node_counter - 1]);
}
}
}
Xorriso_sort_node_array(xorriso, 0); Xorriso_sort_node_array(xorriso, 0);
old_nodes= (IsoNode **) xorriso->hln_array;
old_targets= (char **) xorriso->hln_targets;
old_count= xorriso->hln_count;
xorriso->hln_array= 0;
xorriso->hln_targets= NULL;
/* Transfer node_array to di_array without unrefering nodes */ /* Transfer node_array to di_array without unrefering nodes */
xorriso->hln_count= xorriso->node_counter; xorriso->hln_count= xorriso->node_counter;
@ -11784,7 +11839,77 @@ int Xorriso_make_hln_array(struct XorrisO *xorriso, int flag)
if(ret<=0) if(ret<=0)
goto ex; goto ex;
xorriso->node_targets_availmem= xorriso->temp_mem_limit; xorriso->node_targets_availmem= xorriso->temp_mem_limit;
if(old_targets != NULL) {
/* Transfer targets from old target array */;
new_pt= old_pt= 0;
while(new_pt < xorriso->hln_count && old_pt < old_count) {
ret= Xorriso__hln_cmp(xorriso->hln_array[new_pt], old_nodes[old_pt]);
if(ret < 0) {
new_pt++;
} else if(ret > 0) {
old_pt++;
} else {
xorriso->hln_targets[new_pt]= old_targets[old_pt];
if(old_targets[old_pt] != NULL)
xorriso->temp_mem_limit-= strlen(old_targets[old_pt]) + 1;
old_targets[old_pt]= NULL;
new_pt++;
old_pt++;
}
}
for(old_pt= 0; old_pt < old_count; old_pt++)
if(old_targets[old_pt] != NULL) /* (should not happen) */
free(old_targets[old_pt]);
free((char *) old_targets);
}
if(old_nodes != NULL) {
for(old_pt= 0; old_pt < old_count; old_pt++)
if(old_nodes[old_pt] != NULL)
iso_node_unref(old_nodes[old_pt]);
free((char *) old_nodes);
}
xorriso->hln_change_pending= 0;
ret= 1;
ex:;
return(ret);
}
/* @param flag bit0= overwrite existing hln_array (else return 2)
*/
int Xorriso_make_hln_array(struct XorrisO *xorriso, int flag)
{
int ret;
if(xorriso->hln_array != NULL && !(flag & 1)) {
/* If no fresh image manipulations occured: keep old array */
if(!xorriso->hln_change_pending)
return(2);
ret= Xorriso_remake_hln_array(xorriso, 0);
return(ret);
}
Xorriso_destroy_hln_array(xorriso, 0);
ret= Xorriso_all_node_array(xorriso, 0, 0);
if(ret <= 0)
goto ex;
Xorriso_sort_node_array(xorriso, 0);
/* Transfer node_array to di_array without unrefering nodes */
xorriso->hln_count= xorriso->node_counter;
xorriso->hln_array= xorriso->node_array;
xorriso->node_counter= 0;
xorriso->node_array_size= 0;
xorriso->node_array= NULL;
/* Allocate hln_targets */
ret= Xorriso_new_hln_array(xorriso, xorriso->temp_mem_limit, 1);
if(ret<=0) {
Xorriso_destroy_hln_array(xorriso, 0);
goto ex;
}
xorriso->node_targets_availmem= xorriso->temp_mem_limit;
xorriso->hln_change_pending= 0;
ret= 1; ret= 1;
ex:; ex:;
return(ret); return(ret);
@ -11810,7 +11935,7 @@ int Xorriso_make_di_array(struct XorrisO *xorriso, int flag)
return(2); return(2);
Xorriso_finish_hl_update(xorriso, 0); Xorriso_finish_hl_update(xorriso, 0);
ret= Xorriso_all_node_array(xorriso, 0); ret= Xorriso_all_node_array(xorriso, 0, 0);
if(ret <= 0) if(ret <= 0)
goto ex; goto ex;
bytes= xorriso->node_array_size / 8 + 1; bytes= xorriso->node_array_size / 8 + 1;