Skip to content

Instantly share code, notes, and snippets.

@foxiepaws
Created January 2, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxiepaws/2a3fd7d5c79d1165bd93 to your computer and use it in GitHub Desktop.
Save foxiepaws/2a3fd7d5c79d1165bd93 to your computer and use it in GitHub Desktop.
automatic file healing
hash the file, compare hash to known good file hash
if file bad, split file by negotiated max block size,
hash each block and find block(s) where hash failed.
for each block, there is a failures value, when that value reaches
MAX_FAILURES the entire block is considered bad and reloaded.
in normal mode, the block is split in approximate half, and then if
both halves of the block are hashed and found bad, the entire block is
reloaded. if one half is found bad, that block is split and hashed in
two until MIN_BLOCKS_BEFORE_SCAN is found or both sides of a block
fail, where it will reload that smaller block, if scanning takes
place, then the bad block is split into SMALL_BLOCKSIZE and each
small block is hashed and bad ones are redownloaded and stitched back
together.
in pedantic mode, the block is split as before, but all bad blocks are
run through to scan mode, this is good for fixing images where many
errors have been introduced to the file at random.
in scan mode, the file is split by small blocksize and each block is
hashed and redownloaded as needed linearly. This is good if you need
to ensure that the repairs are done as linearly as possible. each
small block is stored in memory when read off the good media, and
kept in memory until written out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment