Hi folks, here is a patch to the excellent mfstools source code that allows mfsbackup and the rest to tolerate read errors. The drive in my TiVo was dying so I bought a new larger drive, wrote this patch, and successfully backed up and restored everything on the old drive to the new drive. I booted from the weaknees CD and ran these mfstools from a USB flash drive. The linux kernel spewed SCSI errors and the patched mfsbackup reported read failures -- but everything continued and it works great. Hope this helps someone else!
- Code: Select all
diff -ur mfstools/lib/readwrite.c mfstools.mod/lib/readwrite.c
--- mfstools.orig/lib/readwrite.c 2007-06-07 03:19:37.000000000 -0500
+++ mfstools/lib/readwrite.c 2008-10-20 21:41:54.000000000 -0500
@@ -90,6 +90,7 @@
loff_t result;
#endif
int retval;
+ unsigned int orig_sector = sector;
if (sector + count > tivo_partition_size (file))
{
@@ -143,6 +144,37 @@
}
retval = read (_tivo_partition_fd (file), buf, count * 512);
+/* rescue begin */
+ if (retval < 0 && errno == EIO) {
+ int error = errno;
+ if (count == 1) {
+ fprintf(stderr, "read failure at sector %u(%#x) of %d(%#x): %s; zeroing sector\n",
+ sector, sector, count*512, count*512, strerror(errno));
+ memset(buf, 0, count * 512);
+ retval = count * 512;
+ } else {
+ int i;
+
+ fprintf(stderr, "read failure at sector %u(%#x) of %d(%#x): %s; trying sector-by-sector\n",
+ sector, sector, count*512, count*512, strerror(errno));
+ for (i = 0; i < count; i++) {
+ int r;
+
+ r = tivo_partition_read(file, (char *) buf + i * 512, orig_sector + i, 1);
+ if (r < 0) {
+ fprintf(stderr, "sector scan failed\n");
+ errno = error;
+ break;
+ }
+ }
+ if (i >= count) {
+ fprintf(stderr, "sector scan done\n");
+ retval = count * 512;
+ }
+ }
+ }
+/* rescue end */
+
if (_tivo_partition_swab (file))
{
data_swab (buf, count * 512);