diff --git a/tools/sparsecmp.sh b/tools/sparsecmp.sh new file mode 100644 index 0000000..a702747 --- /dev/null +++ b/tools/sparsecmp.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Function to get size of file or block device +get_size() { + if [ -b "$1" ]; then # Check if input is a block device + size=$(sudo blockdev --getsize64 "$1") + else # Assume input is a file + size=$(stat --format="%s" "$1") + fi + echo $size +} + +# Check if at least two arguments are provided +if [ $# -lt 2 ]; then + echo "Usage: $0 [test count]" + exit 1 +fi + +source="$1" +target="$2" +count="${3:-100}" # Default to 100 tests if not specified + +# Ensure the source and target exist +if [ ! -e "$source" ] || [ ! -e "$target" ]; then + echo "Error: Source or target does not exist." + exit 1 +fi + +size=$(get_size "$source") # Get size in bytes +if [ $? -ne 0 ] || [ -z "$size" ] || [ "$size" -eq 0 ]; then + echo "Error: Failed to get size of the source." + exit 1 +fi + +interval=$((size / count)) + +for ((i=0; i /dev/null 2>&1; then + echo -e "\nMismatch or error at offset $offset" + exit 1 # Exit after the first mismatch + fi +done + +# Clear the line after the loop finishes successfully and print success message +printf "\r%$(tput cols)s\r" +echo "No mismatches found."