#!/bin/sh
# DF-3168 stage 1: build a legitimate HAMMER1 filesystem image with a
# multi-leaf B-Tree (root internal node + several leaf children).
#
# ~2500 dirents force multiple leaf splits so that internal parents with
# >= 2 leaf children exist.  The leaf we forge is chosen by patch_leaf_rebal
# (walk mode) after this stage.
set -e
rm -f /build/poc.img
truncate -s 12G /build/poc.img
vnconfig -c -T -S 12g vn0 /build/poc.img
newfs_hammer -L POC /dev/vn0
mount -t hammer /dev/vn0 /mnt
mkdir -p /mnt/d
i=0
while [ $i -lt 2500 ]; do
  : > /mnt/d/f$i
  i=$((i+1))
done
sync
umount /mnt
vnconfig -u vn0
echo MKIMAGE-OK
