47012a36ef1b8cd118e359135b7c67e97cd98e6a
[xfstests-dev.git] / tests / xfs / 278
1 #! /bin/bash
2 # FS QA Test No. 278
3 #
4 # Test xfs_repair to ensure it fixes the lost+found link count
5 # at the first run. See also commit 198b747f255346bca64408875763b6ca0ed3d57d
6 # from xfsprogs tree.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2011 Red Hat, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46 _supported_fs xfs
47 _supported_os Linux
48 _require_scratch
49
50 rm -f $seqres.full
51 _scratch_mkfs >$seqres.full 2>&1
52 _scratch_mount
53
54 mkdir -p $SCRATCH_MNT/dir/subdir
55
56 #get inodes to be changed
57 DIR_INO=`ls -i $SCRATCH_MNT |awk '{print $1}'`
58 SUBDIR_INO=`ls -i $SCRATCH_MNT/dir |awk '{print $1}'`
59
60 _scratch_unmount
61
62 echo "Silence is goodness..."
63
64 get_sfdir_prefix() {
65         local dir_ino="$1"
66
67         for prefix in "u.sfdir3" "u.sfdir2" "u3.sfdir3"; do
68                 if [ -n "$(_scratch_xfs_get_metadata_field \
69                                 "${prefix}.hdr.parent.i4" \
70                                 "inode ${dir_ino}")" ]; then
71                         echo "${prefix}"
72                         return 0
73                 fi
74         done
75         _scratch_xfs_db -c "inode ${dir_ino}" -c 'p' >> $seqres.full
76         return 1
77 }
78 set_ifield() {
79         _scratch_xfs_set_metadata_field "$1" 0 "inode $2" >> $seqres.full
80 }
81
82 sfdir_prefix="$(get_sfdir_prefix "$DIR_INO" || \
83         _fail "Cannot determine sfdir prefix")"
84
85 # Corrupt DIR
86
87 set_ifield "${sfdir_prefix}.list[0].inumber.i4" "$DIR_INO"
88 set_ifield "${sfdir_prefix}.list[0].name" "$DIR_INO"
89 set_ifield "${sfdir_prefix}.list[0].offset" "$DIR_INO"
90 set_ifield "${sfdir_prefix}.list[0].namelen" "$DIR_INO"
91 set_ifield "${sfdir_prefix}.hdr.parent.i4" "$DIR_INO"
92 set_ifield "core.nlinkv2" "$DIR_INO"
93
94 # Corrupt SUBDIR
95 set_ifield "${sfdir_prefix}.hdr.parent.i4" "$SUBDIR_INO"
96 set_ifield "core.nlinkv2" "$SUBDIR_INO"
97
98 echo "===== BEGIN of xfs_repair =====" >> $seqres.full
99 echo "" >>$seqres.full
100
101 xfs_repair  $SCRATCH_DEV >> $seqres.full 2>&1
102 echo "===== END of xfs_repair =====" >> $seqres.full
103
104 exit