Intercept reads to CR0, CR3, CR4 and writes to CR0, CR3, CR4, and CR8.
[freebsd-src/fkvm-freebsd.git] / release / scripts / doFS.sh
blobcb8cb92931933baf67dd87ce9628e5dd000ed0ea
1 #!/bin/sh
3 # $FreeBSD$
6 set -ex
8 export BLOCKSIZE=512
10 DISKLABEL=$1; shift
11 MACHINE=${1:+"-m $1"}; shift
12 FSIMG=$1; shift
13 RD=$1 ; shift
14 MNT=$1 ; shift
15 FSSIZE=$1 ; shift
16 FSPROTO=$1 ; shift
17 FSINODE=$1 ; shift
18 FSLABEL=$1 ; shift
21 # If we've been told to, compute the required file system size
22 # and average inode size automatically.
24 if [ ${FSSIZE} -eq 0 -a ${FSLABEL} = "auto" ]; then
25 roundup() echo $((($1+$2-1)-($1+$2-1)%$2))
26 nf=$(find ${FSPROTO} |wc -l)
27 sk=$(du -sk ${FSPROTO} |cut -f1)
28 FSINODE=$(roundup $(($sk*1024/$nf)) ${FSINODE})
29 FSSIZE=$(roundup $(($sk*12/10)) 1024)
32 dofs_vn () {
33 if [ "x$VNDEVICE" = "x" ] ; then
34 VNDEVICE=vn0
36 u=`expr $VNDEVICE : 'vn\([0-9]*\)' || true`
37 VNDEVICE=vnn$u
39 rm -f /dev/*vnn*
40 mknod /dev/rvnn${u} c 43 `expr 65538 + $u '*' 8`
41 mknod /dev/rvnn${u}c c 43 `expr 2 + $u '*' 8`
42 mknod /dev/vnn${u} b 15 `expr 65538 + $u '*' 8`
43 mknod /dev/vnn${u}c b 15 `expr 2 + $u '*' 8`
45 umount /dev/${VNDEVICE} 2>/dev/null || true
46 umount ${MNT} 2>/dev/null || true
47 vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true
49 vnconfig -s labels -c /dev/r${VNDEVICE} ${FSIMG}
51 trap "umount ${MNT}; vnconfig -u /dev/r${VNDEVICE}; rm -f /dev/*vnn*" EXIT
53 disklabel -w ${BOOT} ${VNDEVICE} ${FSLABEL}
54 newfs -i ${FSINODE} -o space -m 0 /dev/r${VNDEVICE}c
56 mount /dev/${VNDEVICE}c ${MNT}
59 dofs_md () {
60 if [ "x${MDDEVICE}" != "x" ] ; then
61 umount /dev/${MDDEVICE} 2>/dev/null || true
62 umount ${MNT} 2>/dev/null || true
63 mdconfig -d -u ${MDDEVICE} 2>/dev/null || true
66 MDDEVICE=`mdconfig -a -t vnode -f ${FSIMG}`
67 if [ ! -c /dev/${MDDEVICE} ] ; then
68 echo "No /dev/$MDDEVICE" 1>&2
69 exit 1
72 trap "umount ${MNT}; mdconfig -d -u ${MDDEVICE}" EXIT
74 if [ "x${DISKLABEL}" != "x" ] ; then
75 ${DISKLABEL} ${MACHINE} -w ${BOOT} ${MDDEVICE} ${FSLABEL}
76 newfs -O1 -i ${FSINODE} -o space -m 0 /dev/${MDDEVICE}c
77 mount /dev/${MDDEVICE}c ${MNT}
78 else
79 newfs -O1 -i ${FSINODE} -o space -m 0 /dev/${MDDEVICE}
80 mount /dev/${MDDEVICE} ${MNT}
84 rm -f ${FSIMG}
85 dd of=${FSIMG} if=/dev/zero count=${FSSIZE} bs=1k 2>/dev/null
88 # We don't have any bootblocks on ia64. Note that -B implies -r,
89 # so we have to specifically specify -r when we don't have -B.
90 # bsdlabel fails otherwise.
92 case `uname -r` in
93 4.*)
94 if [ -f "${RD}/trees/base/boot/boot1" ]; then
95 BOOT="-B -b ${RD}/trees/base/boot/boot1"
96 if [ -f "${RD}/trees/base/boot/boot2" ]; then
97 BOOT="${BOOT} -s ${RD}/trees/base/boot/boot2"
99 else
100 BOOT="-r"
102 dofs_vn
105 if [ -f "${RD}/trees/base/boot/boot" ]; then
106 BOOT="-B -b ${RD}/trees/base/boot/boot"
107 else
108 BOOT="-r"
110 dofs_md
112 esac
114 if [ -d ${FSPROTO} ]; then
115 (set -e && cd ${FSPROTO} && find . -print | cpio -dump ${MNT})
116 else
117 cp -p ${FSPROTO} ${MNT}
120 df -ki ${MNT}
122 set `df -ki ${MNT} | tail -1`
124 echo "*** File system is ${FSSIZE} K, $4 left"
125 echo "*** ${FSINODE} bytes/inode, $7 left"