#!/bin/sh deleteimage () { if [ ! -b "$ZFSDEVICE" ] then rm $ZFSDEVICE sleep 1 fi } destroypool () { zpool destroy zfstest rmdir /zfstest deleteimage } print_corruption () { set +e zpool status zfstest | grep -i corruption > /dev/null if [ $? -eq 0 ] then echo "zfs detected corruption" RET=1 else echo "zfs detected no corruption" RET=0 fi set -e return $RET } empty () { sleep 0 } if [ "$#" -ne 1 ] then echo "Usage: $0 device" fi ZFSDEVICE="$1" RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' set -e modprobe -v zfs if [ ! -b "$ZFSDEVICE" ] then truncate -s 1G $ZFSDEVICE fi trap deleteimage EXIT #set -o xtrace zpool create -f -m /zfstest zfstest `readlink -f $ZFSDEVICE` trap destroypool EXIT dd if=/dev/zero of=/zfstest/testfile bs=1M count=800 2> /dev/null SUM_A=`shasum /zfstest/testfile` echo "$SUM_A" print_corruption echo "corrupting filesystem" echo -n -e '\x34' | dd of=$ZFSDEVICE seek=290000003 bs=1 conv=notrunc 2> /dev/null #./disktest $ZFSDEVICE 34 290000003 sync echo 3 > /proc/sys/vm/drop_caches echo "trying to read a file from corrupted filesysten with shasum" set +e SUM_B=`shasum /zfstest/testfile` echo "$SUM_B" set -e print_corruption CORRUPTED=$? if [ "$SUM_A" != "$SUM_B" ] then if [ $CORRUPTED -eq 0 ] then echo "${RED}the pool is silently corrupted${NC}" trap empty EXIT exit 0 else echo "${RED}zfs detected the corruption${NC}" fi else echo "no corruption in file" fi