prog);
}
+#define PRF_HYPHEN 1u
+static int parse_range(const char *p, unsigned f,
+ secaddr *start_out, secaddr *end_out)
+{
+ char *q;
+ int err, rc;
+ unsigned long start, end;
+
+ err = errno;
+
+ if (ISDIGIT(*p)) {
+ start = strtoul(p, &q, 0);
+ if (errno || start >= SECLIMIT) { rc = -1; goto end; }
+ *start_out = start; p = q;
+ } else if (!(f&PRF_HYPHEN))
+ { rc = -1; goto end; }
+ else
+ start = 0;
+
+ if (f&PRF_HYPHEN) {
+ if (*p != '-') { rc = -1; goto end; }
+ p++;
+ } else {
+ if (!ISSPACE(*p)) { rc = -1; goto end; }
+ do p++; while (ISSPACE(*p));
+ }
+
+ if (ISDIGIT(*p)) {
+ end = strtoul(p, &q, 0);
+ if (errno || end > SECLIMIT || end < start) { rc = -1; goto end; }
+ *end_out = end; p = q;
+ } else if (!(f&PRF_HYPHEN))
+ { rc = -1; goto end; }
+
+ if (!(f&PRF_HYPHEN)) while (ISSPACE(*p)) p++;
+ if (*p && ((f&PRF_HYPHEN) || *p != '#')) { rc = -1; goto end; }
+
+ rc = 0;
+end:
+ errno = err;
+ return (rc);
+}
+
#define MAXFILES (1 + 2*99 + 1)
struct file {
ident id;
return (0);
}
+#ifdef DEBUG
+static void dump_eventq(const char *what)
+{
+ unsigned i;
+ const struct event *ev;
+ char fn[MAXFNSZ];
+
+ printf("\n;; event dump (%s):\n", what);
+ for (i = 0; i < eventq.n; i++) {
+ ev = &eventq.v[i];
+ switch (ev->ev) {
+ case EV_BEGIN:
+ store_filename(fn, filetab.v[ev->file].id);
+ printf(";; %8"PRIuSEC": begin %s\n", ev->pos, fn);
+ break;
+ case EV_END:
+ store_filename(fn, filetab.v[ev->file].id);
+ printf(";; %8"PRIuSEC": end %s\n", ev->pos, fn);
+ break;
+ case EV_WRITE:
+ printf(";; %8"PRIuSEC": write\n", ev->pos);
+ break;
+ case EV_STOP:
+ printf(";; %8"PRIuSEC": stop\n", ev->pos);
+ break;
+ default:
+ printf(";; %8"PRIuSEC": ?%u\n", ev->pos, ev->ev);
+ break;
+ }
+ }
+}
+#endif
+
typedef uint_least32_t bits;
static bits live[(MAXFILES + 31)/32];
start[0], start[npart - 1] + SECTORS(len[npart - 1]));
}
-static secaddr last_pos, limit, nsectors, ndone;
-static struct timeval last_time;
-static double wsum, wcount;
+static dvd_reader_t *dvd;
+static int dvdfd = -1, outfd = -1;
static struct file *file;
+static dvd_file_t *vob;
+static const char *mapfile; static FILE *mapfp;
+static const char *errfile; static FILE *errfp;
+static secaddr limit;
static secaddr bad_start;
static unsigned retry, max_retries = 4;
+
+static secaddr nsectors, ndone;
+static secaddr last_pos;
+static struct timeval last_time;
+static double alpha = 0.1;
+static double wsum, wcount;
static int bad_err;
static const char throbber[] = "|<-<|>->";
static unsigned throbix = 0;
+static struct progress_item
+ copy_progress, disc_progress,
+ file_progress, badblock_progress;
+
static double scale_bytes(double n, const char **unit_out)
{
const char *unit = "";
if (n > 1600) { n /= 1024; unit = "M"; }
if (n > 1600) { n /= 1024; unit = "G"; }
if (n > 1600) { n /= 1024; unit = "T"; }
-
*unit_out = unit; return (n);
}
-static struct progress_item
- copy_progress, disc_progress,
- file_progress, badblock_progress;
-
#define TIMESTRMAX 16
static char *fmttime(unsigned long t, char *buf)
{
progress_shownotice(render, bg, 7);
}
-static double alpha = 0.1;
-
static void update_progress(secaddr pos)
{
struct timeval now;
static void report_progress(secaddr pos)
{ update_progress(pos); progress_update(&progress); }
-static dvd_reader_t *dvd;
-static int dvdfd = -1, outfd = -1;
-static dvd_file_t *vob;
-static const char *mapfile; static FILE *mapfp;
-static const char *errfile; static FILE *errfp;
-
struct badblock { secaddr start, end; };
DEFVEC(badblock_v, struct badblock);
static badblock_v badblocks = VEC_INIT;
return (!done && errno ? -1 : done);
}
-static void recovered(secaddr bad_lo, secaddr bad_hi)
-{
- char fn[MAXFNSZ];
-
- progress_clear(&progress);
-
- if (!file || id_kind(file->id) == RAW)
- moan("skipping %"PRIuSEC" bad sectors (%"PRIuSEC" .. %"PRIuSEC")",
- bad_hi - bad_lo, bad_lo, bad_hi);
- else {
- store_filename(fn, file->id);
- moan("skipping %"PRIuSEC" bad sectors (%"PRIuSEC" .. %"PRIuSEC"; "
- "`%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC")",
- bad_hi - bad_lo, bad_lo, bad_hi,
- fn, bad_lo - file->start, bad_hi - file->start,
- file->end - file->start);
- }
-
- if (mapfile) {
- open_file_on_demand(mapfile, &mapfp, "bad-sector region map");
- fprintf(mapfp, "%"PRIuSEC" %"PRIuSEC" # %"PRIuSEC" sectors",
- bad_lo, bad_hi, bad_hi - bad_lo);
-
- if (file && id_kind(file->id) != RAW)
- fprintf(mapfp, "; `%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC"",
- fn, bad_lo - file->start, bad_hi - file->start,
- file->end - file->start);
-
- fputc('\n', mapfp);
- check_write(mapfp, "bad-sector region map");
- }
-
- if (lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0)
- bail_syserr(errno, "failed to seek past bad sectors");
-
- progress_removeitem(&progress, &badblock_progress);
- progress_update(&progress);
-}
-
struct recoverybuf {
unsigned char *buf;
secaddr sz, pos, start, end;
static void rearrange_sectors(struct recoverybuf *r,
secaddr dest, secaddr src, secaddr len)
{
- assert(dest + len <= r->sz);
- assert(src + len <= r->sz);
+ assert(dest + len <= r->sz); assert(src + len <= r->sz);
memmove(r->buf + dest*SECTORSZ, r->buf + src*SECTORSZ, len*SECTORSZ);
}
static double step_factor = 2.0;
static secaddr step_min = 1, step_max = 0;
+static void recovered(secaddr bad_lo, secaddr bad_hi)
+{
+ char fn[MAXFNSZ];
+
+ progress_clear(&progress);
+
+ if (!file || id_kind(file->id) == RAW)
+ moan("skipping %"PRIuSEC" bad sectors (%"PRIuSEC" .. %"PRIuSEC")",
+ bad_hi - bad_lo, bad_lo, bad_hi);
+ else {
+ store_filename(fn, file->id);
+ moan("skipping %"PRIuSEC" bad sectors (%"PRIuSEC" .. %"PRIuSEC"; "
+ "`%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC")",
+ bad_hi - bad_lo, bad_lo, bad_hi,
+ fn, bad_lo - file->start, bad_hi - file->start,
+ file->end - file->start);
+ }
+
+ if (mapfile) {
+ open_file_on_demand(mapfile, &mapfp, "bad-sector region map");
+ fprintf(mapfp, "%"PRIuSEC" %"PRIuSEC" # %"PRIuSEC" sectors",
+ bad_lo, bad_hi, bad_hi - bad_lo);
+
+ if (file && id_kind(file->id) != RAW)
+ fprintf(mapfp, "; `%s' %"PRIuSEC" .. %"PRIuSEC" of %"PRIuSEC"",
+ fn, bad_lo - file->start, bad_hi - file->start,
+ file->end - file->start);
+
+ fputc('\n', mapfp);
+ check_write(mapfp, "bad-sector region map");
+ }
+
+ if (lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0)
+ bail_syserr(errno, "failed to seek past bad sectors");
+
+ progress_removeitem(&progress, &badblock_progress);
+ progress_update(&progress);
+}
+
static secaddr run_length_wanted(secaddr pos, secaddr badlen, secaddr end)
{
secaddr want;
#undef BUFSECTORS
}
-#define PRF_HYPHEN 1u
-static int parse_range(const char *p, unsigned f,
- secaddr *start_out, secaddr *end_out)
-{
- char *q;
- int err, rc;
- unsigned long start, end;
-
- err = errno;
-
- if (ISDIGIT(*p)) {
- start = strtoul(p, &q, 0);
- if (errno || start >= SECLIMIT) { rc = -1; goto end; }
- *start_out = start; p = q;
- } else if (!(f&PRF_HYPHEN))
- { rc = -1; goto end; }
- else
- start = 0;
-
- if (f&PRF_HYPHEN) {
- if (*p != '-') { rc = -1; goto end; }
- p++;
- } else {
- if (!ISSPACE(*p)) { rc = -1; goto end; }
- do p++; while (ISSPACE(*p));
- }
-
- if (ISDIGIT(*p)) {
- end = strtoul(p, &q, 0);
- if (errno || end > SECLIMIT || end < start) { rc = -1; goto end; }
- *end_out = end; p = q;
- } else if (!(f&PRF_HYPHEN))
- { rc = -1; goto end; }
-
- if (!(f&PRF_HYPHEN)) while (ISSPACE(*p)) p++;
- if (*p && ((f&PRF_HYPHEN) || *p != '#')) { rc = -1; goto end; }
-
- rc = 0;
-end:
- errno = err;
- return (rc);
-}
-
-#ifdef DEBUG
-static void dump_eventq(const char *what)
-{
- unsigned i;
- const struct event *ev;
- char fn[MAXFNSZ];
-
- printf("\n;; event dump (%s):\n", what);
- for (i = 0; i < eventq.n; i++) {
- ev = &eventq.v[i];
- switch (ev->ev) {
- case EV_BEGIN:
- store_filename(fn, filetab.v[ev->file].id);
- printf(";; %8"PRIuSEC": begin %s\n", ev->pos, fn);
- break;
- case EV_END:
- store_filename(fn, filetab.v[ev->file].id);
- printf(";; %8"PRIuSEC": end %s\n", ev->pos, fn);
- break;
- case EV_WRITE:
- printf(";; %8"PRIuSEC": write\n", ev->pos);
- break;
- case EV_STOP:
- printf(";; %8"PRIuSEC": stop\n", ev->pos);
- break;
- default:
- printf(";; %8"PRIuSEC": ?%u\n", ev->pos, ev->ev);
- break;
- }
- }
-}
-#endif
-
int main(int argc, char *argv[])
{
unsigned f = 0;