| #!/usr/bin/env bash | |
| # This file is part of util-linux. | |
| # SPDX-License-Identifier: GPL-2.0-or-later | |
| TS_TOPDIR="${0%/*}/../.." | |
| TS_DESC="sparse holes with multiple inputs" | |
| . "$TS_TOPDIR"/functions.sh | |
| ts_init "$*" | |
| ts_check_test_command "$TS_CMD_HEXDUMP" | |
| ts_check_prog "truncate" | |
| # The FIEMAP optimization reads the extent map of the current file, but the | |
| # printed address is an offset within all the input files. Dumping a list of | |
| # files has to give the same result as dumping their concatenation. | |
| # | |
| # Note that the optimization is silently disabled on filesystems without | |
| # FIEMAP support (for example tmpfs), where this test checks nothing. | |
| SMALL="$TS_OUTDIR/${TS_TESTNAME}-small" | |
| SPARSE="$TS_OUTDIR/${TS_TESTNAME}-sparse" | |
| WHOLE="$TS_OUTDIR/${TS_TESTNAME}-whole" | |
| # zeros only, to make hexdump enter the squeeze mode before the next file | |
| head -c 40 /dev/zero > "$SMALL" | |
| # 1 MiB hole followed by data | |
| truncate -s 1048576 "$SPARSE" | |
| printf '\252%.0s' {1..32} >> "$SPARSE" | |
| cat "$SMALL" "$SPARSE" > "$WHOLE" | |
| echo "no output expected" > "$TS_OUTPUT" | |
| for opt in "-C" "-C -v" "-C -n 100" "-C -s 30" "-C -s 30 -n 100" "-C -s 1048600"; do | |
| diff -u <($TS_CMD_HEXDUMP $opt "$WHOLE") \ | |
| <($TS_CMD_HEXDUMP $opt "$SMALL" "$SPARSE") || | |
| echo "failed for [$opt]" | |
| done >> "$TS_OUTPUT" 2>> "$TS_ERRLOG" | |
| rm -f "$SMALL" "$SPARSE" "$WHOLE" | |
| ts_finalize |