#!/bin/sh
# DF-2874 record run (as root = dmsg peer position; unpriv path gated by
# diskopen's SYSCAP_RESTRICTEDROOT check, subr_disk.c:78-80):
#  - kernel opens raw disk FREAD|FWRITE with proc0.p_ucred on BLK_OPEN
#  - raw write + readback through the dmsg channel
DEV=/dev/vbd0
OFF=32206413824
LEN=4096
echo "=== F1: peer-position raw RW chain (root harness = cluster-peer stand-in) ==="
/tmp/dfpeer openwr $DEV 3
/tmp/dfpeer write $DEV $OFF $LEN 0x5a
/tmp/dfpeer read $DEV $OFF $LEN /tmp/peer_readback.bin
dd if=$DEV of=/tmp/root_readback.bin bs=4096 count=1 skip=7862464 2>/dev/null
md5 /tmp/root_readback.bin /tmp/magic.bin
cmp -s /tmp/root_readback.bin /tmp/magic.bin && echo PEER_WRITE_LANDED_ON_RAW_DISK
dd if=/tmp/orig.bin of=$DEV bs=4096 count=1 seek=7862464 conv=notrunc 2>/dev/null
echo "=== F1: unpriv gate check ==="
su -l poc -c "/tmp/dfpeer openwr $DEV 3" 2>&1 | grep -E "open\(dev\)|Operation"
echo "=== done ==="
