Files

11 lines
538 B
Bash
Executable File

#!/usr/bin/env bash
# Wrap real dd: drop oflag=direct (unsupported on tmpfs), log, inject faults.
echo "dd $*" >> "${FAKE_OPS_LOG:-/dev/null}"
[[ -z "${FAKE_DD_FAIL:-}" ]] || { echo "dd: error writing: Input/output error" >&2; exit 1; }
args=(); for a in "$@"; do [[ "$a" == oflag=direct ]] || args+=("$a"); done
/usr/bin/dd "${args[@]}" || exit $?
if [[ -n "${FAKE_DD_CORRUPT:-}" ]]; then
for a in "$@"; do [[ "$a" == of=* ]] && of="${a#of=}"; done
printf '\xff' | /usr/bin/dd of="$of" bs=1 seek=1000 conv=notrunc status=none
fi