xref: /freebsd/tools/test/stress2/misc/fsck3.sh (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5#
6# Copyright (c) 2018 Dell EMC Isilon
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# fsck_ffs test.
31# Test scenario broken superblock, use backup SB.
32
33. ../default.cfg
34set -e
35u1=$mdstart
36u2=$((mdstart + 1))
37mp1=${mntpoint}$u1
38mp2=${mntpoint}$u2
39mkdir -p $mp1 $mp2
40log=$mp1/fsck3.sh.log
41diskimage=$mp1/diskimage
42
43max=$((10 * 1024 * 1024))
44[ "$newfs_flags" = "-j" ] &&
45    max=$((20 * 1024 * 1024))
46
47set -e
48mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1
49[ -c /dev/md$u1 ] && mdconfig -d -u $u1
50mdconfig -a -t swap -s 1g -u $u1
51newfs $newfs_flags /dev/md$u1 > /dev/null
52mount /dev/md$u1 $mp1
53
54[ -c /dev/md$u2 ] && mdconfig -d -u $u2
55dd if=/dev/zero of=$diskimage bs=$max count=1 status=none
56mdconfig -a -t vnode -f $diskimage -u $u2
57backups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \
58    tail -1 | sed 's/,//g'`
59newfs $newfs_flags md$u2 > /dev/null
60sblock=`dumpfs md$u2 | grep -m1 "superblock location" | awk '{print $3}'`
61mount /dev/md$u2 $mp2 || s=100
62touch $mp2/file
63umount $mp2
64set +e
65
66s=0
67fsck_ffs -y /dev/md$u2 > $log 2>&1
68r=$?
69for i in $backups; do
70	dd if=/dev/random of=$diskimage oseek=$sblock bs=1 count=8 \
71	    conv=notrunc status=none
72	fsck_ffs -y /dev/md$u2 > $log 2>&1
73	r=$?
74	echo "fsck_ffs -b $i -y /dev/md$u2"
75	fsck_ffs -b $i -y /dev/md$u2 > $log 2>&1
76	r=$?
77	mount /dev/md$u2 $mp2 || s=100
78	[ -f $mp2/file ] || { echo "$mp2/file not found"; s=101; }
79	umount $mp2
80done
81
82mdconfig -d -u $u2
83[ -f fsck_ffs.core ] && { ls -l fsck_ffs.core; s=102; }
84
85umount $mp1
86mdconfig -d -u $u1
87rm -f $diskimage
88exit $s
89