#!/bin/sh
# DF-4900 phase 1 (non-fatal): correct recycle below the 512-unit boundary,
# then 512 live devices (units 0..511) -- no collision yet.
kldload dm
echo "== Part A: create/remove/create -> minor must be recycled =="
dmsetup create xa --notable
echo "xa: $(ls -lH /dev/mapper/xa | awk '{print $5 $6}')"
dmsetup remove xa
dmsetup create ya --notable
echo "ya: $(ls -lH /dev/mapper/ya | awk '{print $5 $6}')  (equal => correct recycle)"
dmsetup remove ya
echo "== Part B: 512 live devices =="
i=0
while [ $i -lt 512 ]; do
	dmsetup create $(printf d%04d $i) --notable >/dev/null 2>&1 || { echo "FAIL at $i"; exit 1; }
	i=$((i+1))
done
echo "created 512 devices"
ls -lH /dev/mapper/d0000 /dev/mapper/d0511 | awk '{print $9, $5 $6}'
echo "nodes in /dev/mapper: $(ls /dev/mapper | wc -l)"
echo "phase1 OK (no panic)"
