#!/bin/bash -

set -e

# You'll need a modified libguestfs configured with:
# ./configure --with-extra-packages="sg3_utils"

#export LIBGUESTFS_DEBUG=1
export LIBGUESTFS_HV=/home/rjones/d/qemu/x86_64-softmmu/qemu-system-x86_64

run=/home/rjones/d/libguestfs/run
test1=/tmp/test1
test2=/tmp/test2
# bytes
size=$((16*1024*1024))
# logical blocks
unmap_start=0
unmap_size=8192

rm -f $test1 $test2

truncate -s 100M $test1
truncate -s 100M $test2

du -sh $test1 $test2

$run guestfish -a $test1 -a $test2 <<EOF
  run
  copy-device-to-device /dev/zero /dev/sda size:$size
  copy-device-to-device /dev/zero /dev/sdb size:$size
  sync

  debug sh "sg_readcap --16 /dev/sda"
  debug sh "sg_vpd --page=0xb0 /dev/sda"

  debug sh "sg_unmap --lba=$unmap_start --num=$unmap_size /dev/sda"
EOF

du -sh $test1 $test2
