-find tests -damaged and -lba_range, new -find action report_damage
This commit is contained in:
@@ -219,6 +219,7 @@ int Xorriso_detach_libraries(struct XorrisO *xorriso, int flag)
|
||||
if(xorriso->in_volset_handle!=NULL) { /* standalone image */
|
||||
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
||||
xorriso->in_volset_handle= NULL;
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
}
|
||||
if(flag&1) {
|
||||
if(xorriso->libs_are_started==0)
|
||||
@@ -375,6 +376,7 @@ int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
|
||||
if(xorriso->in_volset_handle!=NULL) {
|
||||
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
||||
xorriso->in_volset_handle= NULL;
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
xorriso->loaded_volid[0]= 0;
|
||||
xorriso->volset_change_pending= 0;
|
||||
xorriso->no_volset_present= 0;
|
||||
@@ -397,6 +399,7 @@ int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
|
||||
return(-1);
|
||||
}
|
||||
xorriso->in_volset_handle= (void *) volset;
|
||||
xorriso->in_sector_map= NULL;
|
||||
Xorriso_update_volid(xorriso, 0);
|
||||
xorriso->volset_change_pending= 0;
|
||||
xorriso->no_volset_present= 0;
|
||||
@@ -544,6 +547,7 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
|
||||
if(xorriso->in_volset_handle!=NULL)
|
||||
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
||||
xorriso->in_volset_handle= NULL;
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
|
||||
/* check for invalid state */
|
||||
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE &&
|
||||
@@ -595,6 +599,7 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
|
||||
Xorriso_pacifier_callback(xorriso, "nodes read", xorriso->pacifier_count, 0,
|
||||
"", 1); /* report end count */
|
||||
xorriso->in_volset_handle= (void *) volset;
|
||||
xorriso->in_sector_map= NULL;
|
||||
Xorriso_set_image_severities(xorriso, 0);
|
||||
Xorriso_update_volid(xorriso, 0);
|
||||
|
||||
@@ -686,6 +691,7 @@ int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
|
||||
if(xorriso->in_volset_handle!=NULL)
|
||||
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
||||
xorriso->in_volset_handle= NULL;
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
xorriso->loaded_volid[0]= 0;
|
||||
xorriso->volset_change_pending= 0;
|
||||
xorriso->no_volset_present= 0;
|
||||
@@ -3538,8 +3544,12 @@ int Xorriso_toc(struct XorrisO *xorriso, int flag)
|
||||
return(1);
|
||||
|
||||
disc= isoburn_toc_drive_get_disc(drive);
|
||||
sprintf(respt, "TOC layout : %3s , %9s , %10s , %s\n",
|
||||
"Idx", "sbsector", "Size", "Volume Id");
|
||||
if(flag & 4)
|
||||
sprintf(respt, "TOC layout : %3s , %9s , %10s\n",
|
||||
"Idx", "sbsector", "Size");
|
||||
else
|
||||
sprintf(respt, "TOC layout : %3s , %9s , %10s , %s\n",
|
||||
"Idx", "sbsector", "Size", "Volume Id");
|
||||
if(!(flag&1))
|
||||
Xorriso_result(xorriso,0);
|
||||
|
||||
@@ -5524,6 +5534,168 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_start_end_lba(struct XorrisO *xorriso, IsoNode *node,
|
||||
int *start_lba, int *end_lba, off_t *size, int flag)
|
||||
{
|
||||
uint32_t iso_start_lba;
|
||||
int ret;
|
||||
|
||||
*size= 0;
|
||||
*start_lba= *end_lba= -1;
|
||||
ret= iso_node_get_old_image_lba(node, &iso_start_lba, 0);
|
||||
if(ret < 0)
|
||||
return(-1);
|
||||
if(ret != 1)
|
||||
return(0);
|
||||
*start_lba= iso_start_lba;
|
||||
if(LIBISO_ISREG(node))
|
||||
*size= iso_file_get_size((IsoFile *) node);
|
||||
*end_lba= *start_lba + *size / 2048;
|
||||
if((*size % 2048) == 0 && *end_lba > *start_lba)
|
||||
(*end_lba)--;
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param damage_start Returns first damaged byte address
|
||||
@param damage_end Returns first byte address after last damaged byte
|
||||
@return <0 error, 0=undamaged , 1=damaged
|
||||
*/
|
||||
int Xorriso_file_eval_damage(struct XorrisO *xorriso, IsoNode *node,
|
||||
off_t *damage_start, off_t *damage_end,
|
||||
int flag)
|
||||
{
|
||||
int start_lba, end_lba, i, sectors, sector_size, damaged= 0, ret;
|
||||
int next_good_lba, first_bad_lba= -1;
|
||||
off_t size= 0;
|
||||
struct SectorbitmaP *map;
|
||||
|
||||
*damage_start= *damage_end= -1;
|
||||
map= xorriso->in_sector_map;
|
||||
if(map == NULL)
|
||||
return(0);
|
||||
|
||||
ret= Xorriso_start_end_lba(xorriso, node, &start_lba, &end_lba, &size, 0);
|
||||
if(ret <= 0)
|
||||
return(ret);
|
||||
Sectorbitmap_get_layout(map, §ors, §or_size, 0);
|
||||
sector_size/= 2048;
|
||||
for(i= start_lba; i <= end_lba; i+= sector_size)
|
||||
if(Sectorbitmap_is_set(map, i / sector_size, 0) == 0) {
|
||||
damaged= 1;
|
||||
if(first_bad_lba < 0)
|
||||
first_bad_lba= i;
|
||||
next_good_lba= (i / sector_size + 1) * sector_size;
|
||||
}
|
||||
|
||||
if(damaged) {
|
||||
*damage_start= (first_bad_lba - start_lba) * 2048;
|
||||
*damage_end= (next_good_lba - start_lba) * 2048;
|
||||
if(*damage_end > size)
|
||||
*damage_end= size;
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_report_damage(struct XorrisO *xorriso, char *show_path,
|
||||
IsoNode *node, int flag)
|
||||
{
|
||||
int ret;
|
||||
off_t size= 0, damage_start, damage_end;
|
||||
char sfe[5*SfileadrL];
|
||||
|
||||
ret= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end, 0);
|
||||
if(ret < 0)
|
||||
return(0);
|
||||
|
||||
if(LIBISO_ISREG(node))
|
||||
size= iso_file_get_size((IsoFile *) node);
|
||||
if(ret > 0) {
|
||||
sprintf(xorriso->result_line, "File damaged : %8.f , %8.f , %8.f , %s\n",
|
||||
(double) damage_start, (double) (damage_end - damage_start) ,
|
||||
(double) size, Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
} else {
|
||||
sprintf(xorriso->result_line, "File seems ok: %8.f , %8.f , %8.f , %s\n",
|
||||
-1.0, -1.0, (double) size, Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* <<< shall be replaced by tests and -exec report_damage
|
||||
#define Xorriso_check_find_as_exeC 1
|
||||
*/
|
||||
|
||||
#ifdef Xorriso_check_find_as_exeC
|
||||
|
||||
/* @param flag bit0= report about undamaged files
|
||||
*/
|
||||
int Xorriso_file_vs_bitmap(struct XorrisO *xorriso, char *show_path,
|
||||
IsoNode *node, int flag)
|
||||
{
|
||||
uint32_t start_lba;
|
||||
int end_lba, i, sectors, sector_size, damaged= 0, ret;
|
||||
int next_good_lba, first_bad_lba= -1;
|
||||
off_t size= 0, damage_start, damage_count;
|
||||
struct SectorbitmaP *map;
|
||||
char sfe[5*SfileadrL];
|
||||
|
||||
ret= iso_node_get_old_image_lba(node, &start_lba, 0);
|
||||
if(ret < 0)
|
||||
return(0);
|
||||
if(ret == 0) {
|
||||
if(flag & 1)
|
||||
goto undamaged;
|
||||
return(2);
|
||||
}
|
||||
map= xorriso->in_sector_map;
|
||||
if(map == NULL) {
|
||||
if(flag & 1)
|
||||
goto undamaged;
|
||||
return(2);
|
||||
}
|
||||
if(LIBISO_ISREG(node))
|
||||
size= iso_file_get_size((IsoFile *) node);
|
||||
end_lba= start_lba + size / 2048;
|
||||
if(size % 2048)
|
||||
end_lba++;
|
||||
|
||||
Sectorbitmap_get_layout(map, §ors, §or_size, 0);
|
||||
sector_size/= 2048;
|
||||
for(i= start_lba; i < end_lba; i+= sector_size)
|
||||
if(Sectorbitmap_is_set(map, i / sector_size, 0) == 0) {
|
||||
damaged= 1;
|
||||
if(first_bad_lba < 0)
|
||||
first_bad_lba= i;
|
||||
next_good_lba= (i / sector_size + 1) * sector_size;
|
||||
}
|
||||
|
||||
if(damaged && !(flag & 1)) {
|
||||
damage_start= (first_bad_lba - start_lba) * 2048;
|
||||
damage_count= (next_good_lba - start_lba) * 2048;
|
||||
if(damage_count > size)
|
||||
damage_count= size;
|
||||
damage_count-= damage_start;
|
||||
sprintf(xorriso->result_line, "File damage : %13.f , %13.f , %13.f , %s\n",
|
||||
(double) damage_start, (double) damage_count, (double) size,
|
||||
Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
} else if((flag & 1) && !damaged) {
|
||||
undamaged:;
|
||||
sprintf(xorriso->result_line, "File seems ok: %s\n",
|
||||
Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
#endif /* Xorriso_check_find_as_exeC */
|
||||
|
||||
|
||||
/* @param flag bit0= not a command parameter (directory iteration or recursion)
|
||||
bit1= do not count deleted files with rm and rm_r
|
||||
@return <=0 error,
|
||||
@@ -5592,6 +5764,24 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
ret= 1;
|
||||
} else if(action==16 || action==18) { /* not_in_iso , add_missing */
|
||||
;
|
||||
|
||||
#ifdef Xorriso_check_find_as_exeC
|
||||
|
||||
} else if(action == 21) { /* is_damaged */
|
||||
ret= Xorriso_file_vs_bitmap(xorriso, show_path, node, 0);
|
||||
} else if(action == 22) { /* is_undamaged */
|
||||
ret= Xorriso_file_vs_bitmap(xorriso, show_path, node, 1);
|
||||
|
||||
#else
|
||||
|
||||
} else if(action == 21) { /* report_damage */
|
||||
ret= Xorriso_report_damage(xorriso, show_path, node, 0);
|
||||
} else if(action == 22) {
|
||||
/* >>> report_lba */;
|
||||
|
||||
#endif /* ! Xorriso_check_find_as_exeC */
|
||||
|
||||
|
||||
} else { /* includes : 15 in_iso */
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
@@ -5607,6 +5797,39 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_findi_test(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
IsoNode *node, char *name,
|
||||
struct stat *boss_stbuf, struct stat *stbuf,
|
||||
int depth, int flag)
|
||||
{
|
||||
int ret, start_lba, end_lba, damage_filter, file_end_lba, file_start_lba;
|
||||
off_t damage_start, damage_end, size;
|
||||
|
||||
ret= Findjob_test(job, name, boss_stbuf, stbuf, depth, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
|
||||
Findjob_get_lba_damage_filter(job, &start_lba, &end_lba, &damage_filter, 0);
|
||||
if(damage_filter != 0) {
|
||||
ret= Xorriso_file_eval_damage(xorriso, node, &damage_start, &damage_end, 0);
|
||||
if(ret < 0)
|
||||
return(ret);
|
||||
if((damage_filter > 0) != (ret > 0))
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(start_lba >= 0 && end_lba >= 0) {
|
||||
ret= Xorriso_start_end_lba(xorriso, node, &file_start_lba, &file_end_lba,
|
||||
&size, 0);
|
||||
if(ret <= 0)
|
||||
return(ret);
|
||||
if(file_end_lba < start_lba || file_start_lba > end_lba)
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= recursion
|
||||
bit1= do not count deleted files with rm and rm_r
|
||||
@return <=0 error, 1= ok , 2= dir node and path has been deleted
|
||||
@@ -5642,6 +5865,11 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
action= Findjob_get_action(job, 0);
|
||||
if(action<0)
|
||||
action= 0;
|
||||
if(action == 21 && !(flag & 1)) {
|
||||
sprintf(xorriso->result_line, "Report layout: %8s , %8s , %8s , %s\n",
|
||||
"at byte", "range", "filesize", "ISO image path");
|
||||
Xorriso_result(xorriso, 0);
|
||||
}
|
||||
|
||||
dir_node= (IsoDir *) dir_node_generic;
|
||||
if(dir_node==NULL) {
|
||||
@@ -5664,7 +5892,18 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
name= dir_path;
|
||||
else
|
||||
name++;
|
||||
|
||||
#ifdef Xorriso_check_find_as_exeC
|
||||
|
||||
ret= Findjob_test(job, name, NULL, dir_stbuf, depth, 0);
|
||||
|
||||
#else
|
||||
|
||||
ret= Xorriso_findi_test(xorriso, job, iso_node, name, NULL, dir_stbuf,
|
||||
depth, 0);
|
||||
|
||||
#endif /* ! Xorriso_check_find_as_exeC */
|
||||
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
@@ -5731,7 +5970,18 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
--- Seems that the current configuration represents the special
|
||||
handling of the find start path with mount points. Dangerous to change.
|
||||
*/
|
||||
|
||||
#ifdef Xorriso_check_find_as_exeC
|
||||
|
||||
ret= Findjob_test(job, name, dir_stbuf, &stbuf, depth, 0);
|
||||
|
||||
#else
|
||||
|
||||
ret= Xorriso_findi_test(xorriso, job, node, name, dir_stbuf, &stbuf,
|
||||
depth, 0);
|
||||
|
||||
#endif /* ! Xorriso_check_find_as_exeC */
|
||||
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
@@ -6792,13 +7042,41 @@ ex:
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_update_in_sector_map(struct XorrisO *xorriso,
|
||||
struct SpotlisT *spotlist, int read_chunk,
|
||||
struct CheckmediajoB *job, int flag)
|
||||
{
|
||||
int sectors, sector_size, sector_blocks, ret;
|
||||
struct SectorbitmaP *map;
|
||||
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
if(job->use_dev == 1)
|
||||
return(1);
|
||||
map= job->sector_map;
|
||||
sectors= Spotlist_block_count(spotlist, 0);
|
||||
if(sectors <= 0)
|
||||
return(0);
|
||||
sector_size= Spotlist_sector_size(spotlist, read_chunk, 0);
|
||||
sector_blocks= sector_size / 2048;
|
||||
if(sector_blocks > 1)
|
||||
sectors= sectors / sector_blocks + !!(sectors % sector_blocks);
|
||||
ret= Sectorbitmap_new(&(xorriso->in_sector_map), sectors, sector_size, 0);
|
||||
if(ret <= 0)
|
||||
return(ret);
|
||||
if(map != NULL)
|
||||
Sectorbitmap_copy(map, xorriso->in_sector_map, 0);
|
||||
ret= Xorriso_spotlist_to_sectormap(xorriso, spotlist, read_chunk,
|
||||
&(xorriso->in_sector_map), 1);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_check_media(struct XorrisO *xorriso, struct SpotlisT **spotlist,
|
||||
struct CheckmediajoB *job, int flag)
|
||||
{
|
||||
int media_blocks= 0, read_chunk= 16, ret, mode, start_lba= 0;
|
||||
int blocks, os_errno, i, j, last_track_end= -1, track_blocks, track_lba;
|
||||
int num_sessions, num_tracks, declare_untested= 0, sector_size, count;
|
||||
int lba, quality;
|
||||
int num_sessions, num_tracks, declare_untested= 0;
|
||||
char sfe[5*SfileadrL], *toc_info= NULL;
|
||||
struct burn_drive *drive;
|
||||
struct burn_drive_info *dinfo;
|
||||
@@ -6815,10 +7093,9 @@ int Xorriso_check_media(struct XorrisO *xorriso, struct SpotlisT **spotlist,
|
||||
!!job->use_dev);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
|
||||
|
||||
/* >>> determine media type dependent blocking factor:
|
||||
32 kB for CD (with 2kB retry) iand DVD, 64 kB for BD
|
||||
32 kB for CD (with 2kB retry) and DVD, 64 kB for BD
|
||||
eventually adjust read_chunk
|
||||
*/;
|
||||
|
||||
@@ -6948,19 +7225,12 @@ no_content_visible:;
|
||||
ex:;
|
||||
if(job->data_to_fd != -1)
|
||||
close(job->data_to_fd);
|
||||
|
||||
if(ret > 0)
|
||||
ret= Xorriso_update_in_sector_map(xorriso, *spotlist, read_chunk, job, 0);
|
||||
|
||||
if(ret > 0 && job->sector_map_path[0]) {
|
||||
sector_size= read_chunk * 2048;
|
||||
count= Spotlist_count(*spotlist, 0);
|
||||
for(i= 0; i < count; i++) {
|
||||
ret= Spotlist_get_item(*spotlist, i, &lba, &blocks, &quality, 0);
|
||||
if(ret <= 0)
|
||||
continue;
|
||||
if(lba % read_chunk) {
|
||||
sector_size= 2048;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret= Xorriso_spotlist_to_sectormap(xorriso, *spotlist, sector_size,
|
||||
ret= Xorriso_spotlist_to_sectormap(xorriso, *spotlist, read_chunk,
|
||||
&(job->sector_map), 0);
|
||||
if(ret > 0) {
|
||||
ret= Sectorbitmap_to_file(job->sector_map, job->sector_map_path, toc_info,
|
||||
|
Reference in New Issue
Block a user