X-Git-Url: https://git.distorted.org.uk/~mdw/dvdrip/blobdiff_plain/dc53ebfaa3fb887f962b574c6bafa45b160fc765..c1d37fc841b5d334dc30fc8b70504b084f8e1fe2:/dvd-sector-copy.c diff --git a/dvd-sector-copy.c b/dvd-sector-copy.c index 7b7e674..76dfa13 100644 --- a/dvd-sector-copy.c +++ b/dvd-sector-copy.c @@ -1,7 +1,5 @@ #include "lib.h" -static int status = 0; - static void usage(FILE *fp) { fprintf(fp, @@ -315,6 +313,8 @@ static void render_badblock_progress(struct progress_item *item, progress_shownotice(render, bg, 7); } +static double alpha = 0.1; + static void update_progress(secaddr pos) { struct timeval now; @@ -323,8 +323,7 @@ static void update_progress(secaddr pos) gettimeofday(&now, 0); t = tvdiff(&last_time, &now); -#define ALPHA 0.1 -#define BETA (1 - ALPHA) +#define BETA (1 - alpha) if (t) { g = wcount ? pow(BETA, t) : 0.0; f = (1 - g)/(1 - BETA); @@ -334,7 +333,6 @@ static void update_progress(secaddr pos) last_time = now; last_pos = pos; } -#undef ALPHA #undef BETA throbix++; if (!throbber[throbix]) throbix = 0; @@ -437,11 +435,12 @@ static void record_bad_sectors(secaddr bad_lo, secaddr bad_hi) if (!mapfile) return; open_file_on_demand(mapfile, &mapfp, "bad-sector region map"); - fprintf(mapfp, "%"PRIuSEC" %"PRIuSEC"", bad_lo, bad_hi); + fprintf(mapfp, "%"PRIuSEC" %"PRIuSEC" # %"PRIuSEC" sectors", + bad_lo, bad_hi, bad_hi - bad_lo); if (file && id_kind(file->id) != RAW) { store_filename(fn, file->id); - fprintf(mapfp, " # `%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC"", + fprintf(mapfp, "; `%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC"", fn, bad_lo - file->start, bad_hi - file->start, file->end - file->start); } @@ -737,11 +736,11 @@ static ssize_t find_good_sector(secaddr *pos_inout, secaddr end, recovered(bad_lo, end); *pos_inout = end; return (0); } - step = step_factor*(bad_hi - bad_lo); + step = (step_factor - 1)*(bad_hi - bad_lo); if (step < step_min) step = step_min; if (step_max && step > step_max) step = step_max; - if (step > end - bad_lo) step = end - bad_lo; - pos = bad_lo + step - 1; + if (step > end - bad_hi) step = end - bad_hi; + pos = bad_hi + step - 1; want = run_length_wanted(pos, step, end); n = recovery_read(&r, pos, want); #ifdef DEBUG @@ -1036,6 +1035,8 @@ int main(int argc, char *argv[]) step_max = parse_int(&p, 1, SECLIMIT - 1, "step maximum"); else if (SKIP_PREFIX("retry")) max_retries = parse_int(&p, 0, INT_MAX, "retries"); + else if (SKIP_PREFIX("alpha")) + alpha = parse_float(&p, 0, 1, "average decay factor"); else if (SKIP_PREFIX("_badwait")) bad_block_delay = parse_float(&p, 0, DBL_MAX, "bad-block delay"); else if (SKIP_PREFIX("_blkwait")) @@ -1210,8 +1211,7 @@ int main(int argc, char *argv[]) ev = &eventq.v[i]; switch (ev->ev) { case EV_WRITE: start = ev->pos; f |= f_write; break; - case EV_STOP: - nsectors += ev->pos - start; f &= ~f_write; break; + case EV_STOP: nsectors += ev->pos - start; f &= ~f_write; break; } if (ev->pos >= limit) break; if (f&f_fixup) start = ev->pos; @@ -1228,7 +1228,9 @@ int main(int argc, char *argv[]) copy_progress.render = render_copy_progress; progress_additem(&progress, ©_progress); - if (nsectors != limit) { + if (nsectors == limit - start) + { ndone = start; nsectors = limit; } + else { disc_progress.render = render_disc_progress; progress_additem(&progress, &disc_progress); } @@ -1297,6 +1299,7 @@ int main(int argc, char *argv[]) if (f&f_stats) { gettimeofday(&tv1, 0); t = tvdiff(&tv0, &tv1); + if (nsectors == limit - start) { ndone -= start; nsectors -= start; } tot = scale_bytes((double)nsectors*SECTORSZ, &totunit); rate = scale_bytes((double)nsectors*SECTORSZ/t, &rateunit); moan("all done: %.1f %sB in %s -- %.1f %sB/s", @@ -1316,5 +1319,5 @@ int main(int argc, char *argv[]) #undef f_stats #undef f_write - return (status); + return (0); }