1#!/bin/sh 2 3# 4# Copyright (c) 2025 Peter Holm <pho@FreeBSD.org> 5# 6# SPDX-License-Identifier: BSD-2-Clause 7# 8 9# A SEEK_HOLE / SEEK_DATA test scenario, FFS version 10 11[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 12 13. ../default.cfg 14 15prog=$(basename "$0" .sh) 16exp=/tmp/$prog.exp 17here=`pwd` 18log=/tmp/$prog.log 19 20cc -o /tmp/lsholes -Wall -Wextra -O2 $here/../tools/lsholes.c | exit 1 21cat > $exp <<EXP 22Min hole size is 32768, file size is 524288000. 23data #1 @ 0, size=32768) 24hole #2 @ 32768, size=32768 25data #3 @ 65536, size=32768) 26hole #4 @ 98304, size=32768 27data #5 @ 131072, size=32768) 28hole #6 @ 163840, size=524091392 29data #7 @ 524255232, size=32768) 30hole #8 @ 524288000, size=0 31EXP 32 33set -eu 34mount | grep "on $mntpoint " | grep -q /dev/md && umount -f $mntpoint 35[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 36mdconfig -a -t swap -s 2g -u $mdstart 37newfs $newfs_flags md$mdstart > /dev/null 38mount /dev/md$mdstart $mntpoint 39set +e 40 41file=$mntpoint/file 42copy=$mntpoint/copy 43truncate -s 500m $file 44bs=`getconf MIN_HOLE_SIZE $file` 45printf "\001" | dd of=$file seek=$((0*bs)) bs=1 count=1 conv=notrunc status=none 46printf "\002" | dd of=$file seek=$((2*bs)) bs=1 count=1 conv=notrunc status=none 47printf "\003" | dd of=$file seek=$((4*bs)) bs=1 count=1 conv=notrunc status=none 48s1=0 49s2=0 50s3=0 51/tmp/lsholes $file > $log 2>&1; s1=$? 52 53sdiff -s $exp $log || s2=1 54 55$here/../testcases/swap/swap -t 2m -i 20 -h > /dev/null & 56sleep 10 57cp $file $copy 58while pkill swap; do :; done 59wait 60cmp $file $copy || { echo "copy error"; s3=1; } 61 62umount $mntpoint 63mdconfig -d -u $mdstart 64rm -f /tmp/lsholes $exp $log 65exit $((s1 + s2 + s3)) 66