Skip to content

Commit

Permalink
ZTS: Remove non-standard awk hex numbers usage
Browse files Browse the repository at this point in the history
FreeBSD recently removed non-standard hex numbers support from awk.
Neither it supports -n argument, enabling it in gawk.  Instead of
depending on those rewrite list_file_blocks() fuction to handle the
hex math in shell instead of awk.

Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
  • Loading branch information
amotin committed Dec 20, 2024
1 parent 219a89c commit ab353a0
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions tests/zfs-tests/include/blkdev.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -556,27 +556,15 @@ function list_file_blocks # input_file
# 512B blocks for ease of use with dd.
#
typeset level vdev path offset length
if awk -n '' 2>/dev/null; then
# gawk needs -n to decode hex
AWK='awk -n'
else
AWK='awk'
fi
sync_all_pools true
zdb -dddddd $ds $objnum | $AWK -v pad=$((4<<20)) -v bs=512 '
zdb -dddddd $ds $objnum | awk '
/^$/ { looking = 0 }
looking {
level = $2
field = 3
while (split($field, dva, ":") == 3) {
# top level vdev id
vdev = int(dva[1])
# offset + 4M label/boot pad in 512B blocks
offset = (int("0x"dva[2]) + pad) / bs
# length in 512B blocks
len = int("0x"dva[3]) / bs

print level, vdev, offset, len
print level, int(dva[1]), "0x"dva[2], "0x"dva[3]

++field
}
Expand All @@ -585,7 +573,8 @@ function list_file_blocks # input_file
' | \
while read level vdev offset length; do
for path in ${VDEV_MAP[$vdev][@]}; do
echo "$level $path $offset $length"
echo "$level $path $(( ($offset + 4<<20) / 512 ))" \
"$(( $length / 512 ))"
done
done 2>/dev/null
}
Expand Down

0 comments on commit ab353a0

Please sign in to comment.