1#!/bin/ksh -p
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 https://opensource.org/licenses/CDDL-1.0.
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#
24# Copyright (c) 2023, Klara Inc.
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29function have_same_content
30{
31	typeset hash1=$(md5digest $1)
32	typeset hash2=$(md5digest $2)
33
34	log_must [ "$hash1" = "$hash2" ]
35}
36
37#
38# get_same_blocks dataset1 path/to/file1 dataset2 path/to/file2
39#
40# Returns a space-separated list of the indexes (starting at 0) of the L0
41# blocks that are shared between both files (by first DVA and checksum).
42# Assumes that the two files have the same content, use have_same_content to
43# confirm that.
44#
45function get_same_blocks
46{
47    KEY=$5
48    if [ ${#KEY} -gt 0 ]; then
49        KEY="--key=$KEY"
50    fi
51	typeset zdbout=${TMPDIR:-$TEST_BASE_DIR}/zdbout.$$
52	zdb $KEY -vvvvv $1 -O $2 | \
53	    awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.a
54	zdb $KEY -vvvvv $3 -O $4 | \
55	    awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.b
56	echo $(sort -n $zdbout.a $zdbout.b | uniq -d | cut -f1 -d' ')
57}
58
59