1# vim: filetype=sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)clean_mirror_common.kshlib	1.4	07/10/09 SMI"
30#
31
32# Most of the code related to the clearing of mirrors is duplicated in all
33# the test cases below this directory, barring a few minor changes
34# involving the device to be affected and the 'object' to use to mangle
35# the contents of the mirror.
36# This code is sourced into each of these test cases.
37
38function overwrite_verify_mirror
39{
40	typeset AFFECTED_DEVICE=$1
41	typeset OVERWRITING_DEVICE=$2
42
43	typeset atfile=0
44	set -A cksums
45	set -A newcksums
46
47	populate_dir $TESTDIR/file $FILE_COUNT $WRITE_COUNT $BLOCKSZ 0
48	while (( atfile < FILE_COUNT )); do
49		cksums[$atfile]=$($CKSUM ${TESTDIR}/file.${atfile})
50		(( atfile = atfile + 1 ))
51	done
52
53	# unmount and export before dd
54	log_must $UMOUNT $TESTDIR
55	log_must $ZPOOL export $TESTPOOL
56
57	# dd the primary side of the mirror
58	log_must $DD if=$OVERWRITING_DEVICE of=$(bsddevmap $AFFECTED_DEVICE) \
59		seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc
60
61	# now remount
62	log_must $ZPOOL import $TESTPOOL
63
64	atfile=0
65	typeset -i failedcount=0
66	while (( atfile < FILE_COUNT )); do
67		newcksum=$($CKSUM $TESTDIR/file.${atfile})
68		if [[ $newcksum != ${cksums[$atfile]} ]]; then
69			(( failedcount = failedcount + 1 ))
70		fi
71		$RM -f ${files[$atfile]}
72		(( atfile = atfile + 1 ))
73	done
74
75	if (( $failedcount > 0 )); then
76		log_fail "of the $FILE_COUNT files $failedcount did not " \
77		    "have the same checksum before and after."
78	fi
79}
80