1799db59eSPeter Holm#!/bin/sh 2799db59eSPeter Holm 3799db59eSPeter Holm# 4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 5799db59eSPeter Holm# 6799db59eSPeter Holm# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org> 7799db59eSPeter Holm# 8799db59eSPeter Holm# Redistribution and use in source and binary forms, with or without 9799db59eSPeter Holm# modification, are permitted provided that the following conditions 10799db59eSPeter Holm# are met: 11799db59eSPeter Holm# 1. Redistributions of source code must retain the above copyright 12799db59eSPeter Holm# notice, this list of conditions and the following disclaimer. 13799db59eSPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 14799db59eSPeter Holm# notice, this list of conditions and the following disclaimer in the 15799db59eSPeter Holm# documentation and/or other materials provided with the distribution. 16799db59eSPeter Holm# 17799db59eSPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18799db59eSPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19799db59eSPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20799db59eSPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21799db59eSPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22799db59eSPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23799db59eSPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24799db59eSPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25799db59eSPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26799db59eSPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27799db59eSPeter Holm# SUCH DAMAGE. 28799db59eSPeter Holm# 29799db59eSPeter Holm 30799db59eSPeter Holm# A SEEK_HOLE / SEEK_DATA test scenario 31799db59eSPeter Holm 32799db59eSPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 33799db59eSPeter Holm 34799db59eSPeter Holm. ../default.cfg 35799db59eSPeter Holm 36799db59eSPeter Holmprog=$(basename "$0" .sh) 37799db59eSPeter Holmexp=/tmp/$prog.exp 38799db59eSPeter Holmhere=`pwd` 39799db59eSPeter Holmlog=/tmp/$prog.log 40799db59eSPeter Holm 41799db59eSPeter Holmcc -o /tmp/lsholes -Wall -Wextra -O2 $here/../tools/lsholes.c | exit 1 42799db59eSPeter Holmcat > $exp <<EXP 43799db59eSPeter HolmMin hole size is 32768, file size is 524288000. 44799db59eSPeter Holmdata #1 @ 0, size=32768) 45799db59eSPeter Holmhole #2 @ 32768, size=32768 46799db59eSPeter Holmdata #3 @ 65536, size=32768) 47799db59eSPeter Holmhole #4 @ 98304, size=32768 48799db59eSPeter Holmdata #5 @ 131072, size=32768) 49799db59eSPeter Holmhole #6 @ 163840, size=524091392 50799db59eSPeter Holmdata #7 @ 524255232, size=32768) 51799db59eSPeter Holmhole #8 @ 524288000, size=0 52799db59eSPeter HolmEXP 53799db59eSPeter Holm 54799db59eSPeter Holmset -eu 55799db59eSPeter Holmmdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 56799db59eSPeter Holmmdconfig -s 2g -u $mdstart 57799db59eSPeter Holmnewfs -U /dev/md$mdstart > /dev/null 58799db59eSPeter Holmmount /dev/md$mdstart $mntpoint 59799db59eSPeter Holmset +e 60799db59eSPeter Holm 61799db59eSPeter Holmfile=$mntpoint/file 62799db59eSPeter Holmtruncate -s 500m $file 63799db59eSPeter Holmbs=`getconf MIN_HOLE_SIZE $file` 64799db59eSPeter Holmprintf "\001" | dd of=$file seek=$((0*bs)) bs=1 count=1 conv=notrunc status=none 65799db59eSPeter Holmprintf "\002" | dd of=$file seek=$((2*bs)) bs=1 count=1 conv=notrunc status=none 66799db59eSPeter Holmprintf "\003" | dd of=$file seek=$((4*bs)) bs=1 count=1 conv=notrunc status=none 67799db59eSPeter Holms1=0 68799db59eSPeter Holms2=0 69799db59eSPeter Holm/tmp/lsholes $file > $log 2>&1; s1=$? 70799db59eSPeter Holm 71799db59eSPeter Holmcat $log 72799db59eSPeter Holmcmp -s $exp $log || s2=1 73799db59eSPeter Holm 74799db59eSPeter Holmumount $mntpoint 75799db59eSPeter Holmmdconfig -d -u $mdstart 76799db59eSPeter Holmrm -f /tmp/lsholes $exp $log 77799db59eSPeter Holmexit $((s1 + s2)) 78