3 # Copyright (c) 2009 Eric Sandeen
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # Functions useful for defragmentation tests
27 DEFRAG_PROG="$XFS_FSR_PROG"
30 DEFRAG_PROG="$E4DEFRAG_PROG"
33 DEFRAG_PROG="$BTRFS_UTIL_PROG filesystem defragment"
36 _notrun "defragmentation not supported for fstype \"$FSTYP\""
40 _require_command $DEFRAG_PROG
41 _require_xfs_io_fiemap
46 $XFS_IO_PROG -c "fiemap" $1 | tail -n +2 | grep -v hole | wc -l
47 $XFS_IO_PROG -c "fiemap" $1 >> $seqres.full 2>&1
50 # Defrag file, check it, and remove it.
55 CSUM_BEFORE=`md5sum $1`
56 STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
57 $DEFRAG_PROG -v $1 >> $seqres.full 2>&1
59 STAT_AFTER=`stat -c "a: %x m: %y c: %z" $1`
60 CSUM_AFTER=`md5sum $1`
63 if [ "$CSUM_BEFORE" != "$CSUM_AFTER" ]; then
64 _fail "file checksum changed post-defrag ($CSUM_BEFORE/$CSUM_AFTER)"
66 if [ "$STAT_BEFORE" != "$STAT_AFTER" ]; then
67 _fail "file timestamps changed post-defrag:\n$STAT_BEFORE\n$STAT_AFTER"