New -check_media option -patch_lba0=
This commit is contained in:
@ -3125,6 +3125,19 @@ int Sectorbitmap_is_set(struct SectorbitmaP *o, int sector, int flag)
|
||||
}
|
||||
|
||||
|
||||
int Sectorbitmap_bytes_are_set(struct SectorbitmaP *o,
|
||||
off_t start_byte, off_t end_byte, int flag)
|
||||
{
|
||||
int end_sector, i;
|
||||
|
||||
end_sector= end_byte / o->sector_size;
|
||||
for(i= start_byte / o->sector_size; i <= end_sector; i++)
|
||||
if(!Sectorbitmap_is_set(o, i, 0))
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Sectorbitmap_get_layout(struct SectorbitmaP *o,
|
||||
int *sectors, int *sector_size, int flag)
|
||||
{
|
||||
@ -3140,7 +3153,8 @@ int Sectorbitmap_copy(struct SectorbitmaP *from, struct SectorbitmaP *to,
|
||||
int i, run_start, run_value, start_sec, limit_sec, start_aligned;
|
||||
int end_complete;
|
||||
|
||||
if(from->sectors * from->sector_size > to->sectors * to->sector_size)
|
||||
if(((off_t) from->sectors) * ((off_t) from->sector_size) >
|
||||
((off_t) to->sectors) * ((off_t) to->sector_size))
|
||||
return(-1);
|
||||
if(from->sector_size == to->sector_size) {
|
||||
for(i= 0; i < from->map_size; i++)
|
||||
@ -3175,6 +3189,21 @@ int Sectorbitmap_copy(struct SectorbitmaP *from, struct SectorbitmaP *to,
|
||||
}
|
||||
|
||||
|
||||
int Sectorbitmap_clone(struct SectorbitmaP *from, struct SectorbitmaP **clone,
|
||||
int flag)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret= Sectorbitmap_new(clone, from->sectors, from->sector_size, 0);
|
||||
if(ret <= 0)
|
||||
return(ret);
|
||||
ret= Sectorbitmap_copy(from, *clone, 0);
|
||||
if(ret <= 0)
|
||||
Sectorbitmap_destroy(clone, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------- End SectorbitmaP ---------------------------- */
|
||||
|
||||
/* ---------------------------- CheckmediajoB ----------------------------- */
|
||||
@ -3198,6 +3227,8 @@ int Checkmediajob_new(struct CheckmediajoB **o, int flag)
|
||||
strcpy(m->abort_file_path, "/var/opt/xorriso/do_abort_check_media");
|
||||
m->data_to_path[0]= 0;
|
||||
m->data_to_fd= -1;
|
||||
m->patch_lba0= 0;
|
||||
m->patch_lba0_msc1= -1;
|
||||
m->sector_map_path[0]= 0;
|
||||
m->sector_map= NULL;
|
||||
m->map_with_volid= 0;
|
||||
@ -3211,6 +3242,8 @@ int Checkmediajob_destroy(struct CheckmediajoB **o, int flag)
|
||||
{
|
||||
if((*o) == NULL)
|
||||
return(0);
|
||||
if((*o)->data_to_fd != -1)
|
||||
close((*o)->data_to_fd);
|
||||
Sectorbitmap_destroy(&((*o)->sector_map), 0);
|
||||
free((char *) *o);
|
||||
*o= NULL;
|
||||
@ -8862,6 +8895,12 @@ int Xorriso_spotlist_to_sectormap(struct XorrisO *xorriso,
|
||||
map_sector_size == sector_size)
|
||||
m= *map;
|
||||
else {
|
||||
if(*map != NULL) {
|
||||
if(((off_t) (*map)->sectors) * ((off_t) (*map)->sector_size) >
|
||||
((off_t) list_sectors) * ((off_t) sector_size))
|
||||
list_sectors= (((off_t) (*map)->sectors) *
|
||||
((off_t) (*map)->sector_size)) / sector_size + 1;
|
||||
}
|
||||
ret= Sectorbitmap_new(&m, list_sectors, sector_size, 0);
|
||||
if(ret <= 0)
|
||||
return(-1);
|
||||
@ -9037,6 +9076,25 @@ ex:;
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_open_job_data_to(struct XorrisO *xorriso,
|
||||
struct CheckmediajoB *job, int flag)
|
||||
{
|
||||
char sfe[5*SfileadrL];
|
||||
|
||||
if(job->data_to_path[0] == 0)
|
||||
return(2);
|
||||
job->data_to_fd= open(job->data_to_path, O_RDWR | O_CREAT,
|
||||
S_IRUSR | S_IWUSR);
|
||||
if(job->data_to_fd == -1) {
|
||||
sprintf(xorriso->info_text, "Cannot open path %s",
|
||||
Text_shellsafe(job->data_to_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------- Options API ------------------------ */
|
||||
|
||||
|
||||
@ -9542,7 +9600,7 @@ int Xorriso_option_check_media(struct XorrisO *xorriso,
|
||||
{
|
||||
int ret, i, count, lba, blocks, quality;
|
||||
int end_idx, old_idx, os_errno;
|
||||
char quality_name[80];
|
||||
char quality_name[80], head_buffer[64*1024];
|
||||
double num;
|
||||
struct SpotlisT *spotlist= NULL;
|
||||
struct CheckmediajoB *job= NULL;
|
||||
@ -9583,6 +9641,23 @@ int Xorriso_option_check_media(struct XorrisO *xorriso,
|
||||
job->max_lba= num;
|
||||
else
|
||||
job->min_lba= num;
|
||||
} else if(strncmp(argv[i], "patch_lba0=", 11) == 0) {
|
||||
job->patch_lba0_msc1= -1;
|
||||
if(strcmp(argv[i] + 11, "on") == 0)
|
||||
job->patch_lba0= 1;
|
||||
else if(strcmp(argv[i] + 11, "off") == 0)
|
||||
job->patch_lba0= 0;
|
||||
else if(strcmp(argv[i] + 11, "force") == 0)
|
||||
job->patch_lba0= 2;
|
||||
else if(argv[i][11] >= '1' && argv[i][11] <= '9') {
|
||||
num= -1;
|
||||
sscanf(argv[i] + 11, "%lf", &num);
|
||||
if(num > 0x7fffffff || num < 0)
|
||||
goto unknown_value;
|
||||
job->patch_lba0_msc1= num;
|
||||
job->patch_lba0= (num >= 32) + (strstr(argv[i] + 11, ":force") != NULL);
|
||||
} else
|
||||
goto unknown_value;
|
||||
} else if(strncmp(argv[i], "report=", 7) == 0) {
|
||||
if(strcmp(argv[i] + 7, "blocks") == 0)
|
||||
job->report_mode= 0;
|
||||
@ -9644,9 +9719,16 @@ unknown_value:;
|
||||
}
|
||||
|
||||
if((job->report_mode == 1 || job->report_mode == 2) && job->use_dev == 1) {
|
||||
|
||||
/* >>> this combination makes no sense */;
|
||||
|
||||
sprintf(xorriso->info_text,
|
||||
"-check_media: cannot report=*files while use=outdef");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
if(job->patch_lba0 && job->data_to_path[0] == 0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-check_media: cannot apply patch_lba0= while data_to= has empty value");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
if(job->use_dev == 2) {
|
||||
@ -9668,14 +9750,29 @@ unknown_value:;
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
|
||||
xorriso->in_sector_map= job->sector_map;
|
||||
job->sector_map= NULL;
|
||||
ret= Sectorbitmap_clone(job->sector_map, &(xorriso->in_sector_map), 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
} else {
|
||||
ret= Xorriso_check_media(xorriso, &spotlist, job, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
}
|
||||
|
||||
if(job->patch_lba0) {
|
||||
ret= Xorriso_open_job_data_to(xorriso, job, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
if(ret == 1) {
|
||||
ret= Xorriso_update_iso_lba0(xorriso, job->patch_lba0_msc1, 0,
|
||||
head_buffer, job,
|
||||
(8 * (job->patch_lba0 == 1)) |
|
||||
4 | (job->patch_lba0_msc1 < 0));
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
}
|
||||
}
|
||||
|
||||
if(job->report_mode == 0 || job->report_mode == 2) { /* report blocks */
|
||||
sprintf(xorriso->result_line,
|
||||
"MCL layout : lba , size , quality\n");
|
||||
|
Reference in New Issue
Block a user