FREE_BLOCKS=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
                | awk '/Free blocks:/{print $3}'`
 
-# nb: kernels today don't count journal blocks  as overhead, but should.
-# For most filesystems this will still be within tolerance.
-# Overhead is all the blocks (already) used by the fs itself:
-OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS))
+# ext3 doesn't count journal blocks as overhead, ext4 does.
+if [ $FSTYP = "ext3" ]; then
+       JOURNAL_SIZE=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+               | awk '/Journal size:/{print $3}' | _filter_size_to_bytes`
+       BLOCK_SIZE=`dumpe2fs -h $SCRATCH_DEV 2>/dev/null \
+               | awk '/Block size:/{print $3}'`
+       JOURNAL_BLOCKS=$(($JOURNAL_SIZE/$BLOCK_SIZE))
+else
+       JOURNAL_BLOCKS=0
+fi
+
+OVERHEAD=$(($TOTAL_BLOCKS-$FREE_BLOCKS-$JOURNAL_BLOCKS))
 
 #  bsddf|minixdf
 #         Set the behaviour  for  the  statfs  system  call.  The  minixdf
 
        sed -e "s/[0-9\.]\+\s\?[b|k|m|g|t][b]\?/<SIZE>/ig"
 }
 
+# Convert string read from stdin like 128K to bytes and print it to stdout
+_filter_size_to_bytes()
+{
+       read size
+       suffix=${size:${#size}-1}
+       mul=1
+       case $suffix in
+               k|K) mul=1024 ;;
+               m|M) mul=$((1024*1024)) ;;
+               g|G) mul=$((1024*1024*1024)) ;;
+               t|T) mul=$((1024*1024*1024*1024)) ;;
+       esac
+       echo $((${size:0:${#size}-1}*$mul))
+}
+
 # make sure this script returns success
 /bin/true