1#!/bin/sh 2# $FreeBSD$ 3 4TMP=/tmp/$$. 5set -e 6MD=`mdconfig -a -t malloc -s 2m` 7trap "exec 7</dev/null; rm -f ${TMP}* ; mdconfig -d -u ${MD}" EXIT INT TERM 8 9./sunlabel -r -w $MD auto 10 11dd if=/dev/$MD of=${TMP}i0 count=16 > /dev/null 2>&1 12./sunlabel $MD > ${TMP}l0 13 14sed ' 15/ c:/{ 16p 17s/c:/a:/ 18s/3969/1024/ 19} 20' ${TMP}l0 > ${TMP}l1 21 22./sunlabel -R $MD ${TMP}l1 23if [ -c /dev/${MD}a ] ; then 24 echo "PASS: Created a: partition" 1>&2 25else 26 echo "FAIL: Did not create a: partition" 1>&2 27 exit 2 28fi 29 30# Spoil and rediscover 31 32true > /dev/${MD} 33if [ -c /dev/${MD}a ] ; then 34 echo "PASS: Recreated a: partition after spoilage" 1>&2 35else 36 echo "FAIL: Did not recreate a: partition after spoilage" 1>&2 37 exit 2 38fi 39 40dd if=/dev/$MD of=${TMP}i1 count=16 > /dev/null 2>&1 41sed ' 42/ c:/{ 43p 44s/c:/a:/ 45s/3969/2048/ 46} 47' ${TMP}l0 > ${TMP}l2 48 49./sunlabel -R $MD ${TMP}l2 50dd if=/dev/$MD of=${TMP}i2 count=16 > /dev/null 2>&1 51 52exec 7< /dev/${MD}a 53 54for t in a c 55do 56 if dd if=${TMP}i2 of=/dev/${MD}$t 2>/dev/null ; then 57 echo "PASS: Could rewrite same label to ...$t while ...a open" 1>&2 58 else 59 echo "FAIL: Could not rewrite same label to ...$t while ...a open" 1>&2 60 exit 2 61 fi 62 63 if dd if=${TMP}i1 of=/dev/${MD}$t 2>/dev/null ; then 64 echo "FAIL: Could label with smaller ...a to ...$t while ...a open" 1>&2 65 exit 2 66 else 67 echo "PASS: Could not label with smaller ...a to ...$t while ...a open" 1>&2 68 fi 69 70 if dd if=${TMP}i0 of=/dev/${MD}$t 2>/dev/null ; then 71 echo "FAIL: Could write label missing ...a to ...$t while ...a open" 1>&2 72 exit 2 73 else 74 echo "PASS: Could not write label missing ...a to ...$t while ...a open" 1>&2 75 fi 76done 77 78exec 7< /dev/null 79 80if dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then 81 echo "PASS: Could write missing ...a label to ...c" 1>&2 82else 83 echo "FAIL: Could not write missing ...a label to ...c" 1>&2 84 exit 2 85fi 86 87if dd if=${TMP}i2 of=/dev/${MD}c 2>/dev/null ; then 88 echo "PASS: Could write large ...a label to ...c" 1>&2 89else 90 echo "FAIL: Could not write large ...a label to ...c" 1>&2 91 exit 2 92fi 93 94if dd if=${TMP}i1 of=/dev/${MD}c 2>/dev/null ; then 95 echo "PASS: Could write small ...a label to ...c" 1>&2 96else 97 echo "FAIL: Could not write small ...a label to ...c" 1>&2 98 exit 2 99fi 100 101if dd if=${TMP}i2 of=/dev/${MD}a 2>/dev/null ; then 102 echo "PASS: Could increase size of ...a by writing to ...a" 1>&2 103else 104 echo "FAIL: Could not increase size of ...a by writing to ...a" 1>&2 105 exit 2 106fi 107 108if dd if=${TMP}i1 of=/dev/${MD}a 2>/dev/null ; then 109 echo "FAIL: Could decrease size of ...a by writing to ...a" 1>&2 110 exit 2 111else 112 echo "PASS: Could not decrease size of ...a by writing to ...a" 1>&2 113fi 114 115if dd if=${TMP}i0 of=/dev/${MD}a 2>/dev/null ; then 116 echo "FAIL: Could delete ...a by writing to ...a" 1>&2 117 exit 2 118else 119 echo "PASS: Could not delete ...a by writing to ...a" 1>&2 120fi 121 122if ./sunlabel -B -b ${TMP}i0 ${MD} ; then 123 if [ ! -c /dev/${MD}a ] ; then 124 echo "FAILED: Writing bootcode killed ...a" 1>&2 125 exit 2 126 else 127 echo "PASS: Could write bootcode while closed" 1>&2 128 fi 129else 130 echo "FAILED: Could not write bootcode while closed" 1>&2 131 exit 2 132fi 133 134exec 7> /dev/${MD}c 135if ktrace ./sunlabel -B -b ${TMP}i0 ${MD} ; then 136 if [ ! -c /dev/${MD}a ] ; then 137 echo "FAILED: Writing bootcode killed ...a" 1>&2 138 exit 2 139 else 140 echo "PASS: Could write bootcode while open" 1>&2 141 fi 142else 143 echo "FAILED: Could not write bootcode while open" 1>&2 144 exit 2 145fi 146exec 7> /dev/null 147 148if dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then 149 echo "PASS: Could delete ...a by writing to ...c" 1>&2 150else 151 echo "FAIL: Could not delete ...a by writing to ...c" 1>&2 152 exit 2 153fi 154 155# XXX: need to add a 'b' partition and check for overlaps. 156 157exit 0 158