1#!/bin/sh 2# $FreeBSD$ 3 4. $(dirname $0)/conf.sh 5 6echo 1..27 7 8BLK=512 9BLKS_PER_MB=2048 10 11md=$(attach_md -t malloc -s40m) 12i=1 13 14fsck_md() 15{ 16 local is_clean 17 18 out=$(fsck_ffs -Ffy ${md}a.eli) 19 if [ $? -eq 0 -o $? -eq 7 ]; then 20 echo "ok $i - fsck says ${md}a.eli is clean" 21 else 22 echo "not ok $i - fsck says ${md}a.eli is dirty" 23 fi 24 i=$((i + 1)) 25} 26 27setsize() { 28 partszMB=$1 29 30 gpart resize -i 1 -s ${partszMB}m ${md} 31} 32 33# Initialise 34 35gpart create -s BSD ${md} 36gpart add -t freebsd-ufs -s 10m ${md} 37setsize 10 || echo -n "not " 38echo ok $i - "Sized ${md}a to 10m" 39i=$((i + 1)) 40 41echo secret >tmp.key 42geli init -Bnone -PKtmp.key ${md}a || echo -n "not " 43echo ok $i - "Initialised geli on ${md}a" 44i=$((i + 1)) 45geli attach -pk tmp.key ${md}a || echo -n "not " 46echo ok $i - "Attached ${md}a as ${md}a.eli" 47i=$((i + 1)) 48 49newfs -U ${md}a.eli >/dev/null || echo -n "not " 50echo ok $i - "Initialised the filesystem on ${md}a.eli" 51i=$((i + 1)) 52fsck_md 53 54# Doing a backup, resize & restore must be forced (with -f) as geli 55# verifies that the provider size in the metadata matches the consumer. 56 57geli backup ${md}a tmp.meta || echo -n "not " 58echo ok $i - "Backed up ${md}a metadata" 59i=$((i + 1)) 60 61geli detach ${md}a.eli || echo -n "not " 62echo ok $i - "Detached ${md}a.eli" 63i=$((i + 1)) 64 65setsize 20 || echo -n "not " 66echo ok $i - "Sized ${md}a to 20m" 67i=$((i + 1)) 68geli attach -pktmp.key ${md}a && echo -n "not " 69echo ok $i - "Attaching ${md}a fails after resizing the consumer" 70i=$((i + 1)) 71 72geli restore tmp.meta ${md}a && echo -n "not " 73echo ok $i - "Restoring metadata on ${md}a.eli fails without -f" 74i=$((i + 1)) 75geli restore -f tmp.meta ${md}a || echo -n "not " 76echo ok $i - "Restoring metadata on ${md}a.eli can be forced" 77i=$((i + 1)) 78 79geli attach -pktmp.key ${md}a || echo -n "not " 80echo ok $i - "Attaching ${md}a is now possible" 81i=$((i + 1)) 82 83growfs -y ${md}a.eli >/dev/null || echo -n "not " 84echo ok $i - "Extended the filesystem on ${md}a.eli" 85i=$((i + 1)) 86 87fsck_md 88 89# Now do the resize properly 90 91geli detach ${md}a.eli || echo -n "not " 92echo ok $i - "Detached ${md}a.eli" 93i=$((i + 1)) 94 95setsize 30 || echo -n "not " 96echo ok $i - "Sized ${md}a to 30m" 97i=$((i + 1)) 98 99geli resize -s20m ${md}a || echo -n "not " 100echo ok $i - "Resizing works ok" 101i=$((i + 1)) 102geli resize -s20m ${md}a && echo -n "not " 103echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)" 104i=$((i + 1)) 105 106geli attach -pktmp.key ${md}a || echo -n "not " 107echo ok $i - "Attaching ${md}a works ok" 108i=$((i + 1)) 109 110growfs -y ${md}a.eli >/dev/null || echo -n "not " 111echo ok $i - "Extended the filesystem on ${md}a.eli" 112i=$((i + 1)) 113 114fsck_md 115 116geli detach ${md}a.eli 117gpart destroy -F $md >/dev/null 118 119 120# Verify that the man page example works, changing ada0 to $md, 121# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none 122# to geli init. 123 124gpart create -s GPT $md || echo -n "not " 125echo ok $i - "Installed a GPT on ${md}" 126i=$((i + 1)) 127gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not " 128echo ok $i - "Added a 20m partition in slot 1" 129i=$((i + 1)) 130geli init -B none -K tmp.key -P ${md}p1 || echo -n "not " 131echo ok $i - "Initialised geli on ${md}p1" 132i=$((i + 1)) 133gpart resize -s 30m -i 1 $md || echo -n "not " 134echo ok $i - "Resized partition ${md}p1 to 30m" 135i=$((i + 1)) 136geli resize -s 20m ${md}p1 || echo -n "not " 137echo ok $i - "Resized geli on ${md}p1 to 30m" 138i=$((i + 1)) 139geli attach -k tmp.key -p ${md}p1 || echo -n "not " 140echo ok $i - "Attached ${md}p1.eli" 141i=$((i + 1)) 142 143geli detach ${md}p1.eli 144 145rm tmp.* 146