xref: /freebsd/tools/test/stress2/misc/msdos16.sh (revision fd45b686f9d92f583366c75b22c04c7ee49709c0)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org>
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# msdosfs disk image fuzz test.
31# FAT32 version of msdos15.sh
32
33. ../default.cfg
34
35[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
36
37cc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1
38
39set -e
40u1=$mdstart
41u2=$((mdstart + 1))
42mp1=${mntpoint}$u1
43mp2=${mntpoint}$u2
44mkdir -p $mp1 $mp2
45log=$mp1/msdos16.sh.log
46diskimage=$mp1/msdos16.sh.diskimage
47cap=$((32 * 1024))		# Only fuzz the first 32k
48
49set +e
50mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1
51[ -c /dev/md$u1 ] && mdconfig -d -u $u1
52mdconfig -a -t swap -s 2g -u $u1
53newfs -U /dev/md$u1 > /dev/null
54mount /dev/md$u1 $mp1
55
56[ -c /dev/md$u2 ] && mdconfig -d -u $u2
57dd if=/dev/zero of=$diskimage bs=1g count=1 status=none
58mdconfig -a -t vnode -f $diskimage -u $u2
59newfs_msdos -F 32 -b 8192 /dev/md$u2 > /dev/null
60mount -t msdosfs /dev/md$u2 $mp2
61[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2
62umount $mp2
63
64cd $mp1
65start=`date +%s`
66while [ $((`date +%s` - start)) -lt 60 ]; do
67	mount -t msdosfs /dev/md$u2 $mp2 2>/dev/null || break
68	ls -lR $mp2 > /dev/null 2>&1 || break
69	rm -rf $mp2/* > /dev/null 2>&1 || break
70	touch $mp2/`jot -rc 8 a z | tr -d '\n'` || break
71	while mount | grep -q "on $mp2 "; do umount $mp2; done
72	echo * | grep -q core && break
73	sync
74	mdconfig -d -u $u2
75	/tmp/flip -n 10 -s $cap $diskimage
76	sync
77	mdconfig -a -t vnode -f $diskimage -u $u2
78done
79mount | grep -q "on $mp2 " && umount $mp2
80mdconfig -d -u $u2 || exit 1
81
82echo * | grep -q core && { ls -l *.core; cp $log /tmp; exit 106; } ||
83cd /tmp
84umount $mp1
85mdconfig -d -u $u1
86rm -f /tmp/flip
87exit 0
88