768b7f03db7246028d7db6baf248e127f0d9cce9
[xfstests-dev.git] / 032
1 #! /bin/bash
2 # FS QA Test No. 032
3 #
4 # cross check mkfs detection of foreign filesystems
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
32 rm -f $seq.full
33
34 # get standard environment, filters and checks
35 . ./common.rc
36 . ./common.filter
37
38 # real QA test starts here
39 _supported_fs xfs btrfs
40 _supported_os Linux
41
42 _require_scratch
43 _require_no_large_scratch_dev
44
45 # mkfs.btrfs did not have overwrite detection at first
46 if [ "$FSTYP" == "btrfs" ]; then
47         grep -q 'force overwrite' `echo $MKFS_BTRFS_PROG | awk '{print $1}'` || \
48                 _notrun "Installed mkfs.btrfs does not support -f option"
49 fi
50
51 echo "Silence is golden."
52 for fs in `echo ${MKFS_PROG}.* | sed -e 's/.sbin.mkfs.//g'`
53 do
54         preop=""        # for special input needs
55         preargs=""      # for any special pre-device options
56         postargs=""     # for any special post-device options
57
58         # minix, msdos and vfat mkfs fails for large devices, restrict to 2000 blocks
59         [ $fs = minix ] && postargs=2000
60         [ $fs = msdos ] && postargs=2000
61         [ $fs = vfat ] && postargs=2000
62         # these folks prompt before writing
63         [ $fs = jfs ] && preop="echo Y |"
64         [ $fs = gfs ] && preop="echo y |" && preargs="-p lock_nolock -j 1"
65         [ $fs = gfs2 ] && preop="echo y |" && preargs="-p lock_nolock -j 1"
66         [ $fs = reiserfs ] && preop="echo y |" && preargs="-f"
67         # cramfs mkfs requires a directory argument
68         [ $fs = cramfs ] && preargs=/proc/fs
69         [ $fs = ext2 ] && preargs="-F"
70         [ $fs = ext3 ] && preargs="-F"
71         [ $fs = ext4 ] && preargs="-F"
72         [ $fs = ext4dev ] && preargs="-F"
73
74         # overwite the first few Kb - should blow away superblocks
75         src/devzero -n 20 $SCRATCH_DEV >/dev/null
76
77         # create a filesystem of this type
78         echo "=== Creating $fs filesystem..." >>$seq.full
79         echo "    ( $preop mkfs -t $fs $preargs $SCRATCH_DEV $postargs )" >>$seq.full
80         eval $preop mkfs -t $fs $preargs $SCRATCH_DEV $postargs >>$seq.full 2>&1
81
82         if [ $? -eq 0 ] ; then
83                 # next, ensure we don't overwrite it
84                 echo "=== Attempting $FSTYP overwrite of $fs..." >>$seq.full
85                 ${MKFS_PROG}.$FSTYP $SCRATCH_DEV >>$seq.full 2>&1
86
87                 [ $? -eq 0 ] && echo "Failed - overwrote fs type ${fs}!"
88         else
89                 echo "mkfs of type ${fs} failed" >>$seq.full
90         fi
91 done
92
93 # success, all done
94 status=0
95 exit