Skip to content

Commit

Permalink
Register the bad read before bailing on terminal errors.
Browse files Browse the repository at this point in the history
This way running recoverdisk in a loop will not get stuck on a bad
block which causes the disk or SD card detach.
  • Loading branch information
bsdphk committed Feb 2, 2021
1 parent 40407d3 commit d21ce74
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions sbin/recoverdisk/recoverdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ static void
set_verbose(void)
{
struct winsize wsz;
time_t t0;

if (!isatty(STDIN_FILENO) || ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz))
return;
verbose = 1;
t0 = time(NULL);
}

static void
Expand Down Expand Up @@ -587,6 +585,13 @@ if (!(random() & 0xf)) {
lp->start, sz, lp->state, strerror(error));
if (verbose)
report(lp, sz);
if (fdw >= 0 && strlen(unreadable_pattern)) {
fill_buf(buf, sz, unreadable_pattern);
write_buf(fdw, buf, sz, lp->start);
}
new_lump(lp->start, sz, lp->state + 1);
lp->start += sz;
lp->len -= sz;
if (error == EINVAL) {
printf("Try with -b 131072 or lower ?\n");
aborting = 1;
Expand All @@ -597,13 +602,6 @@ if (!(random() & 0xf)) {
aborting = 1;
break;
}
if (fdw >= 0 && strlen(unreadable_pattern)) {
fill_buf(buf, sz, unreadable_pattern);
write_buf(fdw, buf, sz, lp->start);
}
new_lump(lp->start, sz, lp->state + 1);
lp->start += sz;
lp->len -= sz;
}
if (aborting)
save_worklist();
Expand Down

0 comments on commit d21ce74

Please sign in to comment.