Skip to content

Instantly share code, notes, and snippets.

@shaon
Forked from risaacson/efficent_dd_with_start_and_count.sh
Created April 18, 2013 01:30
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 shaon/5409223 to your computer and use it in GitHub Desktop.
Save shaon/5409223 to your computer and use it in GitHub Desktop.
!/usr/bin/env bash
# set -x
get_next_multiplier() {
current_multiplier=$1
multiplier=$(( ${current_multiplier} * 2 ))
}
set_variables() {
start=$1
count=$2
byte_size=$3
}
multiplier=1
input_file=$1
output_file=$2
initial_start=$3
initial_count=$4
start=0
count=0
byte_size=${multiplier}
while true; do
start_divided=$(( ${initial_start} / ${multiplier} ))
start_remainder=$(( ${initial_start} % ${multiplier} ))
count_divided=$(( ${initial_count} / ${multiplier} ))
count_remainder=$(( ${initial_count} % ${multiplier} ))
[ "${start_divided}" -eq "0" ] && break
[ "${start_remainder}" -ne "0" ] && break
[ "${count_divided}" -eq "0" ] && break
[ "${count_remainder}" -ne "0" ] && break
[ "${start_remainder}" -eq "0" ] && [ "${count_remainder}" -eq "0" ] && set_variables ${start_divided} ${count_divided} ${multiplier}
get_next_multiplier ${multiplier}
done
echo "dd if=${input_file} of=${output_file} bs=${byte_size} start=${start} count=${count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment