Search code examples
algorithmhardware

Ddrescue(GNU) algorithm


http://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html

The algorithm of ddrescue is as follows (the user may interrupt the process at any point, but be aware that a bad drive can block ddrescue for a long time until the kernel gives up):

1) Optionally read a logfile describing the status of a multi-part or previously interrupted rescue. If no logfile is specified or is empty or does not exist, mark all the rescue domain as non-tried.

2) (First phase; Copying) Read the non-tried parts of the input file, marking the failed blocks as non-trimmed and skipping beyond them, until all the rescue domain is tried. Only non-tried areas are read in large blocks. Trimming, splitting and retrying are done sector by sector. Each sector is tried at most two times; the first in this step as part of a large block read, the second in one of the steps below as a single sector read.

3) (Second phase; Trimming) Read forwards one sector at a time from the leading edge of the largest non-trimmed block, until a bad sector is found. Then read backwards one sector at a time from the trailing edge of the same block, until a bad sector is found. For each non-trimmed block, mark the bad sectors found as bad-sector and mark the rest of that block as non-split. Repeat until there are no more non-trimmed blocks.

4) (Third phase; Splitting) Read forwards one sector at a time from the center of the largest non-split block, until a bad sector is found. Then read backwards one sector at a time from the center of the same block, until a bad sector is found. If the logfile is larger than --logfile-size', read the smallest non-split blocks until the number of entries in the logfile drops below--logfile-size'. Repeat until all remaining non-split blocks have less than 5 sectors. Then read the remaining non-split blocks sequentially.

5) (Fourth phase; Retrying) Optionally try to read again the bad sectors until the specified number of retries is reached.

6) Optionally write a logfile for later use.

My understanding: ** When he is copying ** He just copies blocks one by one, never retreating to copy old blocks. Any block containing a defective sector is marked bad (the entire block). Bad blocks are marked untrimmed.

Legend:

=1 2 3= is a bad BLOCK
[1 2 3] is a good block
x is a bad sector
@ is the read cursor
in a =1 2 3= center sector(2) is always bad

When he is Trimming Read forwards one sector at a time from the leading edge of the largest non-trimmed block, until a bad sector is found.

=1 2 3= [4 5 6] =7 8 9=@ [10 11 12] =13 14 15=

=1 2 3= [4 5 6] =7 8 9= [10 11 12] =13 @14 15=

Then read backwards one sector at a time from the trailing edge of the same block, until a bad sector is found.

=1 2 3= [4 5 6] @=7 8 9= [10 11 12] =13 14 15=

=1 @2 3= [4 5 6] =7 8 9= [10 11 12] =13 14 15=

For each non-trimmed block, mark the bad sectors found as bad-sector and mark the rest of that block as non-split.

=1 x 3= [4 5 6] =7 8 9= [10 11 12] =13 x 15=
  1. Why is he doing this?? Why can't he just copy linearly and every time he encounters a bad sector, just skip it - seems to me all he's doing is extracting working sectors from a bad block.

  2. I got stuck in the 'Trimming' and Splitting is worse - can someone read that document explain it all!

  3. How can he even retry! He can retry the bad sectors but since he's already trimmed the blocks and written them out - how will he insert the recovered data that comes from retrying?


Solution

    1. bad sectors are naturally occur in groups...if i gently hit a working drive with a hammer, the heads are most likely scratch the surface...which is rotating...so it will create a nice concentrical circle on the storage surface. trying bad blocks after bad blocks is usually time wasting...and in most cases bad drives doesn't have much hours left...

    2. after trimming the unknown range most likely has bad sectors on the edges - that's why splitting starts in the center...which is probably healthy...

    3. it seeks to the target sector by using fseek() or something like that...ddrescue is like dd on steroids...it has the ability to "know" what data have been read, it leaves out all parts of the disk which are unreadable