40d278981c356edf56d5cf7d5ef48af2cf8cde45
[xfstests-dev.git] / tests / shared / 032
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 032
6 #
7 # cross check mkfs detection of foreign filesystems
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
17 rm -f $seqres.full
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22
23 # real QA test starts here
24 _supported_fs xfs btrfs
25
26 _require_scratch_nocheck
27 _require_no_large_scratch_dev
28
29 # mkfs.btrfs did not have overwrite detection at first
30 if [ "$FSTYP" == "btrfs" ]; then
31         grep -q 'force overwrite' `echo $MKFS_BTRFS_PROG | awk '{print $1}'` || \
32                 _notrun "Installed mkfs.btrfs does not support -f option"
33 fi
34
35 echo "Silence is golden."
36 for fs in `echo ${MKFS_PROG}.* | sed -e "s:${MKFS_PROG}.::g"`
37 do
38         preop=""        # for special input needs
39         preargs=""      # for any special pre-device options
40         postargs=""     # for any special post-device options
41
42         # minix, msdos and vfat mkfs fails for large devices, restrict to 2000 blocks
43         [ $fs = minix ] && postargs=2000
44         [ $fs = msdos ] && postargs=2000
45         [ $fs = vfat ] && postargs=2000
46         # these folks prompt before writing
47         [ $fs = jfs ] && preop="echo Y |"
48         [ $fs = gfs ] && preop="echo y |" && preargs="-p lock_nolock -j 1"
49         [ $fs = gfs2 ] && preop="echo y |" && preargs="-p lock_nolock -j 1"
50         [ $fs = reiserfs ] && preop="echo y |" && preargs="-f"
51         [ $fs = reiser4 ] && preop="echo y |" && preargs="-f"
52         # cramfs mkfs requires a directory argument
53         [ $fs = cramfs ] && preargs=/proc/fs
54         [ $fs = ext2 ] && preargs="-F"
55         [ $fs = ext3 ] && preargs="-F"
56         [ $fs = ext4 ] && preargs="-F"
57         [ $fs = ext4dev ] && preargs="-F"
58
59         # overwite the first few Kb - should blow away superblocks
60         $here/src/devzero -n 20 $SCRATCH_DEV >/dev/null
61
62         # create a filesystem of this type
63         echo "=== Creating $fs filesystem..." >>$seqres.full
64         echo "    ( $preop mkfs -t $fs $preargs $SCRATCH_DEV $postargs )" >>$seqres.full
65         eval $preop mkfs -t $fs $preargs $SCRATCH_DEV $postargs >>$seqres.full 2>&1
66
67         if [ $? -eq 0 ] ; then
68                 # next, ensure we don't overwrite it
69                 echo "=== Attempting $FSTYP overwrite of $fs..." >>$seqres.full
70                 ${MKFS_PROG}.$FSTYP $SCRATCH_DEV >>$seqres.full 2>&1
71
72                 [ $? -eq 0 ] && echo "Failed - overwrote fs type ${fs}!"
73         else
74                 echo "mkfs of type ${fs} failed" >>$seqres.full
75         fi
76 done
77
78 # success, all done
79 status=0
80 exit