#!/bin/sh
# DF-2584 — run as root INSIDE the DragonFly guest (clean boot).
# Builds a pristine 2GB hammer2 image containing /f (32KB file => two
# non-embedded 16KB data blocks, first at key 0), then unmounts.
# The crafted deep-indirect copies are produced on the audit host by
# craft_deep.py and pushed back as /root/h2c.img (depth 60) and
# /root/h2c55.img (sub-limit control, depth 55).
set -e
umount /mnt/h2 2>/dev/null || true
vnconfig -u vn0 2>/dev/null || true
mkdir -p /mnt/h2
rm -f /root/h2.img
truncate -s 2147483648 /root/h2.img
vnconfig -c -S -T vn0 /root/h2.img
newfs_hammer2 -L TESTFS /dev/vn0 >/dev/null 2>&1
mount -t hammer2 /dev/vn0@TESTFS /mnt/h2
dd if=/dev/urandom of=/mnt/h2/f bs=32768 count=1 2>/dev/null
sync
stat -f "inum=%i size=%z %N" /mnt/h2/f
sync
umount /mnt/h2
vnconfig -u vn0
echo BUILD-OK
