-find tests -damaged and -lba_range, new -find action report_damage

This commit is contained in:
2008-08-17 22:05:48 +00:00
parent a7734d4d58
commit 294a55d552
6 changed files with 511 additions and 67 deletions

View File

@ -1874,6 +1874,9 @@ struct FindjoB {
*/
char file_type;
int start_lba;
int end_lba;
int damage_filter; /* -1=only undamaged , 0=all , 1=only damaged */
/* 0= echo
1= rm (also rmdir)
@ -1896,6 +1899,8 @@ struct FindjoB {
18= add_missing iso_rr_equiv
19= empty_iso_dir iso_rr_equiv
20= is_full_in_iso iso_rr_equiv
21= report_damage
>>>22= report_lba
*/
int action;
char *target;
@ -1905,7 +1910,6 @@ struct FindjoB {
int type; /* see Xorriso_set_time flag */
time_t date;
struct FindjoB *subjob;
};
int Findjob_destroy(struct FindjoB **job, int flag);
@ -1921,6 +1925,9 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
m->start_path= NULL;
m->name_expr= NULL;
m->file_type= 0;
m->start_lba= -1;
m->end_lba= -1;
m->damage_filter= 0;
m->action= 0; /* print */
m->target= NULL; /* a mere pointer, not managed memory */
m->user= 0;
@ -2012,6 +2019,39 @@ int Findjob_set_file_type(struct FindjoB *o, char file_type, int flag)
}
int Findjob_set_lba_range(struct FindjoB *o, int start_lba, int count,
int flag)
{
o->start_lba= start_lba;
o->end_lba= start_lba + count - 1;
return(1);
}
/* @param value -1= only undamaged files, 0= all files, 1= only damaged files
*/
int Findjob_set_damage_filter(struct FindjoB *o, int value, int flag)
{
if(value < 0)
o->damage_filter= -1;
else if(value > 0)
o->damage_filter= 1;
else
o->damage_filter= 0;
return(1);
}
int Findjob_get_lba_damage_filter(struct FindjoB *o, int *start_lba,
int *end_lba, int *damage_filter, int flag)
{
*start_lba= o->start_lba;
*end_lba= o->end_lba;
*damage_filter= o->damage_filter;
return(1);
}
/* @return 0=no match , 1=match , <0 = error
*/
int Findjob_test(struct FindjoB *o, char *name,
@ -2763,6 +2803,35 @@ int Spotlist_count(struct SpotlisT *o, int flag)
}
int Spotlist_block_count(struct SpotlisT *o, int flag)
{
int list_blocks= 0;
struct SpotlistiteM *li;
for(li= o->list_start; li != NULL; li= li->next) {
if(li->start_lba + li->blocks > list_blocks)
list_blocks= li->start_lba + li->blocks;
}
return(list_blocks);
}
int Spotlist_sector_size(struct SpotlisT *o, int read_chunk, int flag)
{
int sector_size;
struct SpotlistiteM *li;
sector_size= read_chunk * 2048;
for(li= o->list_start; li != NULL; li= li->next) {
if((li->start_lba % read_chunk) || (li->blocks % read_chunk)) {
sector_size= 2048;
break;
}
}
return(sector_size);
}
int Spotlist_get_item(struct SpotlisT *o, int idx,
int *start_lba, int *blocks, int *quality, int flag)
{
@ -3133,6 +3202,7 @@ int Checkmediajob_new(struct CheckmediajoB **o, int flag)
m->sector_map= NULL;
m->map_with_volid= 0;
m->retry= 0;
m->report_mode= 0;
return(1);
}
@ -3221,6 +3291,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->in_volset_handle= NULL;
m->volset_change_pending= 0;
m->no_volset_present= 0;
m->in_sector_map= NULL;
m->outdev[0]= 0;
m->out_drive_handle= NULL;
m->dev_fd_1= -1;
@ -8753,31 +8824,27 @@ int Xorriso_auto_chmod(struct XorrisO *xorriso, char *disk_path, int flag)
}
/* @param flag bit0= mark untested areas as valid
*/
int Xorriso_spotlist_to_sectormap(struct XorrisO *xorriso,
struct SpotlisT *spotlist,
int sector_size,
int read_chunk,
struct SectorbitmaP **map,
int flag)
{
struct SectorbitmaP *m;
int map_sectors= -1, map_sector_size= -1;
int list_sectors, list_blocks, sector_blocks;
int list_sectors, list_blocks, sector_size, sector_blocks;
int replace_map= 0, count, i, lba, blocks, quality, ret;
sector_size= Spotlist_sector_size(spotlist, read_chunk, 0);
sector_blocks= sector_size / 2048;
if(*map != NULL)
Sectorbitmap_get_layout(*map, &map_sectors, &map_sector_size, 0);
count= Spotlist_count(spotlist, 0);
list_blocks= 0;
for(i= 0; i < count; i++) {
ret= Spotlist_get_item(spotlist, i, &lba, &blocks, &quality, 0);
if(ret <= 0)
continue;
if(lba + blocks > list_blocks)
list_blocks= lba + blocks;
}
list_blocks= Spotlist_block_count(spotlist, 0);
/* >>> ??? insist in list_blocks % sector_blocks == 0 */
list_sectors= list_blocks / sector_blocks;
@ -8805,10 +8872,10 @@ int Xorriso_spotlist_to_sectormap(struct XorrisO *xorriso,
ret= Spotlist_get_item(spotlist, i, &lba, &blocks, &quality, 0);
if(ret <= 0)
continue;
if(quality == Xorriso_read_quality_untesteD)
if(quality == Xorriso_read_quality_untesteD && !(flag & 1))
continue;
Sectorbitmap_set_range(m, lba / sector_blocks, blocks / sector_blocks,
quality >= Xorriso_read_quality_valiD);
quality >= Xorriso_read_quality_untesteD);
}
if(replace_map) {
Sectorbitmap_destroy(map, 0);
@ -9471,6 +9538,8 @@ int Xorriso_option_check_media(struct XorrisO *xorriso,
double num;
struct SpotlisT *spotlist= NULL;
struct CheckmediajoB *job= NULL;
struct FindjoB *findjob= NULL;
struct stat dir_stbuf;
old_idx= *idx;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
@ -9506,6 +9575,15 @@ int Xorriso_option_check_media(struct XorrisO *xorriso,
job->max_lba= num;
else
job->min_lba= num;
} else if(strncmp(argv[i], "report=", 7) == 0) {
if(strcmp(argv[i] + 7, "blocks") == 0)
job->report_mode= 0;
else if(strcmp(argv[i] + 7, "files") == 0)
job->report_mode= 1;
else if(strcmp(argv[i] + 7, "blocks_files") == 0)
job->report_mode= 2;
else
goto unknown_value;
} else if(strncmp(argv[i], "retry=", 6) == 0) {
if(strcmp(argv[i] + 6, "on") == 0)
job->retry= 1;
@ -9557,6 +9635,12 @@ unknown_value:;
}
}
if((job->report_mode == 1 || job->report_mode == 2) && job->use_dev == 1) {
/* >>> this combination makes no sense */;
}
if(job->use_dev == 2) {
if(job->sector_map_path[0] == 0) {
sprintf(xorriso->info_text,
@ -9575,25 +9659,43 @@ unknown_value:;
ret= Xorriso_sectormap_to_spotlist(xorriso, job, &spotlist, 0);
if(ret <= 0)
goto ex;
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
xorriso->in_sector_map= job->sector_map;
job->sector_map= NULL;
} else {
ret= Xorriso_check_media(xorriso, &spotlist, job, 0);
if(ret <= 0)
goto ex;
}
sprintf(xorriso->result_line,
"MCL layout : lba , size , quality\n");
Xorriso_result(xorriso,0);
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;
sprintf(xorriso->result_line, "MCL item : %10d , %10d , %s\n",
lba, blocks, Spotlist__quality_name(quality, quality_name, 0));
if(job->report_mode == 0 || job->report_mode == 2) { /* report blocks */
sprintf(xorriso->result_line,
"MCL layout : lba , size , quality\n");
Xorriso_result(xorriso,0);
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;
sprintf(xorriso->result_line, "MCL item : %10d , %10d , %s\n",
lba, blocks, Spotlist__quality_name(quality, quality_name, 0));
Xorriso_result(xorriso,0);
}
}
if(job->report_mode == 1 || job->report_mode == 2) { /* report files */
ret= Findjob_new(&findjob, "/", 0);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "-check_media report=files", 0);
{ret= -1; goto ex;}
}
Findjob_set_damage_filter(findjob, 1, 0);
Findjob_set_action_target(findjob, 21, NULL, 0);
ret= Xorriso_findi(xorriso, findjob, NULL, (off_t) 0,
NULL, "/", &dir_stbuf, 0, 0);
Findjob_destroy(&findjob, 0);
if(ret <= 0)
goto ex;
}
ret= 1;
ex:;
Spotlist_destroy(&spotlist, 0);
@ -10558,7 +10660,7 @@ sorry_ex:
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret, i, end_idx, type= 0, action, deleter= 0;
int ret, i, end_idx, type= 0, action, deleter= 0, start_lba, count;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, sfe[5*SfileadrL], *cpt, other_path_start[SfileadrL];
struct stat dir_stbuf;
@ -10596,6 +10698,26 @@ not_enough_arguments:;
Text_shellsafe(argv[i], sfe, 0));
goto sorry_ex;
}
} else if(strcmp(argv[i], "-type")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Findjob_set_file_type(job, argv[i][0], 0);
if(ret<=0) {
sprintf(xorriso->info_text, "-find[ix]: unknown -type '%c'",argv[i][0]);
goto sorry_ex;
}
} else if(strcmp(argv[i], "-damaged")==0) {
Findjob_set_damage_filter(job, 1, 0);
} else if(strcmp(argv[i], "-undamaged")==0) {
Findjob_set_damage_filter(job, -1, 0);
} else if(strcmp(argv[i], "-lba_range")==0) {
if(i+2>=end_idx)
goto not_enough_arguments;
i+= 2;
sscanf(argv[i-1], "%d", &start_lba);
sscanf(argv[i], "%d", &count);
Findjob_set_lba_range(job, start_lba, count, 0);
} else if(strcmp(argv[i], "-exec")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
@ -10732,20 +10854,15 @@ not_enough_arguments:;
goto ex;
Findjob_set_start_path(job, sfe, 0);
} else if(strcmp(cpt, "report_damage")==0) {
Findjob_set_action_target(job, 21, NULL, 0);
} else if(strcmp(cpt, "report_lba")==0) {
Findjob_set_action_target(job, 22, NULL, 0);
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
Text_shellsafe(argv[i], sfe, 0));
goto sorry_ex;
}
} else if(strcmp(argv[i], "-type")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Findjob_set_file_type(job, argv[i][0], 0);
if(ret<=0) {
sprintf(xorriso->info_text, "-find[ix]: unknown -type '%c'",argv[i][0]);
goto sorry_ex;
}
} else {
sprintf(xorriso->info_text, "-find[ix]: unknown option %s",
Text_shellsafe(argv[i], sfe, 0));
@ -10955,17 +11072,18 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" access time, modification time, both times.",
" -alter_date_r type timestring iso_rr_path [***]",
" Like -alter_date but affecting all files below directories.",
" -find iso_rr_path [-name pattern] [-type t] [-exec action [params]]",
" -find iso_rr_path [test [test ...]] [-exec action [params]]",
" performs an action on files below the current working",
" directory in the ISO image. If -name pattern is given",
" then only files with matching leaf names are processed.",
" If -type is given then only files with matching type are",
" processed. Types: block,char,dir,pipe,file,link,socket.",
" Further tests: -damaged, -undamaged, -lba_range start count",
" action may be one of: echo, chown, chown_r, chgrp, chgrp_r",
" chmod, chmod_r, alter_date, alter_date_r, lsdl, compare,",
" rm, rm_r, compare, update, find.",
" rm, rm_r, compare, update, report_damage, find.",
" params are their arguments except iso_rr_path.",
" I.e. echo, lsdl, rm, rm_r have no params at all.",
" echo, lsdl, rm, rm_r, report_damage have no params at all.",
" -mkdir iso_rr_path [...]",
" Create empty directories if they do not exist yet.",
" -rmdir iso_rr_path [***]",