ryzhov_al

Remove sparse parts from binary

Apr 13th, 2020
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.50 KB | None | 0 0
  1. #!/bin/bash
  2. LANG='C'
  3.  
  4. BLOCK_SIZE=512
  5. SPARE_SIZE=16
  6. IN_FILE=file.in
  7. OUT_FILE=file.out
  8.  
  9. rm -f $OUT_FILE
  10. # Read per block+spare and write block, skipping spare part
  11. i=0
  12. while [ -z "`dd if=$IN_FILE of=block.file bs=$((BLOCK_SIZE + SPARE_SIZE)) count=1 skip=$i 2> \
  13.        >(grep 'cannot skip to specified offset')`" ]; do
  14.     echo "Processing $i block at $(((BLOCK_SIZE + SPARE_SIZE) * i)) offset..."
  15.     dd if=block.file bs=$BLOCK_SIZE count=1 status=none >> $OUT_FILE
  16.     ((i++))
  17. done
  18. rm block.file
Advertisement
Add Comment
Please, Sign In to add comment