xfs/278: find sfdir inode field prefix
[xfstests-dev.git] / tests / xfs / 278
index 4e3bbe26a617d2f31d6fe9097524cc93de049b0c..47012a36ef1b8cd118e359135b7c67e97cd98e6a 100755 (executable)
@@ -5,7 +5,6 @@
 # at the first run. See also commit 198b747f255346bca64408875763b6ca0ed3d57d
 # from xfsprogs tree.
 #
-#
 #-----------------------------------------------------------------------
 # Copyright (c) 2011 Red Hat, Inc.  All Rights Reserved.
 #
@@ -26,8 +25,6 @@
 
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
-seqres=$RESULT_DIR/$seq
-seqres=$RESULT_DIR/$seq
 echo "QA output created by $seq"
 
 here=`pwd`
@@ -42,14 +39,16 @@ _cleanup()
 }
 
 # get standard environment, filters and checks
-. ./common.rc
-. ./common.filter
+. ./common/rc
+. ./common/filter
 
 # real QA test starts here
 _supported_fs xfs
 _supported_os Linux
 _require_scratch
-_scratch_mkfs >/dev/null 2>&1
+
+rm -f $seqres.full
+_scratch_mkfs >$seqres.full 2>&1
 _scratch_mount
 
 mkdir -p $SCRATCH_MNT/dir/subdir
@@ -62,17 +61,39 @@ _scratch_unmount
 
 echo "Silence is goodness..."
 
+get_sfdir_prefix() {
+       local dir_ino="$1"
+
+       for prefix in "u.sfdir3" "u.sfdir2" "u3.sfdir3"; do
+               if [ -n "$(_scratch_xfs_get_metadata_field \
+                               "${prefix}.hdr.parent.i4" \
+                               "inode ${dir_ino}")" ]; then
+                       echo "${prefix}"
+                       return 0
+               fi
+       done
+       _scratch_xfs_db -c "inode ${dir_ino}" -c 'p' >> $seqres.full
+       return 1
+}
+set_ifield() {
+       _scratch_xfs_set_metadata_field "$1" 0 "inode $2" >> $seqres.full
+}
+
+sfdir_prefix="$(get_sfdir_prefix "$DIR_INO" || \
+       _fail "Cannot determine sfdir prefix")"
+
 # Corrupt DIR
-xfs_db -x -c "inode $DIR_INO" -c "write u.sfdir2.list[0].inumber.i4 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $DIR_INO" -c "write u.sfdir2.list[0].name 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $DIR_INO" -c "write u.sfdir2.list[0].offset 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $DIR_INO" -c "write u.sfdir2.list[0].namelen 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $DIR_INO" -c "write u.sfdir2.hdr.parent.i4 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $DIR_INO" -c "write core.nlinkv2 0" $SCRATCH_DEV >> $seqres.full
+
+set_ifield "${sfdir_prefix}.list[0].inumber.i4" "$DIR_INO"
+set_ifield "${sfdir_prefix}.list[0].name" "$DIR_INO"
+set_ifield "${sfdir_prefix}.list[0].offset" "$DIR_INO"
+set_ifield "${sfdir_prefix}.list[0].namelen" "$DIR_INO"
+set_ifield "${sfdir_prefix}.hdr.parent.i4" "$DIR_INO"
+set_ifield "core.nlinkv2" "$DIR_INO"
 
 # Corrupt SUBDIR
-xfs_db -x -c "inode $SUBDIR_INO" -c "write u.sfdir2.hdr.parent.i4 0" $SCRATCH_DEV >> $seqres.full
-xfs_db -x -c "inode $SUBDIR_INO" -c "write core.nlinkv2 0" $SCRATCH_DEV >> $seqres.full
+set_ifield "${sfdir_prefix}.hdr.parent.i4" "$SUBDIR_INO"
+set_ifield "core.nlinkv2" "$SUBDIR_INO"
 
 echo "===== BEGIN of xfs_repair =====" >> $seqres.full
 echo "" >>$seqres.full
@@ -80,9 +101,4 @@ echo "" >>$seqres.full
 xfs_repair  $SCRATCH_DEV >> $seqres.full 2>&1
 echo "===== END of xfs_repair =====" >> $seqres.full
 
-#if _check_scratch_fs; then
-#      status=0
-#else
-#      status=1
-#fi
 exit