#!/bin/bash
#
#	writefsz {fs.z|-} [blocks]
#
#	This script writes the specified compressed file system image to
#	/dev/fd0.  It assumes that you've already done a `make zdisk' in
#	order to put a kernel on the disk.  The `blocks' parameter
#	specifies how big the ramdisk is to be.  By default, it's 4096
#	blocks, or 4Mb.  Specify either the compressed file system, or use
#	`-' for stdin.
#

kernel=/usr/src/linux/arch/i386/boot/zImage

[ $# -lt 1 -o $# -gt 2 ] && {
	echo "Usage: `basename $0` {fs.z|-} [blocks]"
	exit 1
}

[ "$1" != - -a ! -f "$1" ] && {
	echo "`basename $0`: $1 not found"
	exit 2
}

fs=$1
[ "$fs" = - ] && fs=

[ ! -f $kernel ] && {
	echo "`basename $0`: $kernel not found"
	exit 3
}

start=`ls -s $kernel | awk '{print $1}'`
rdev -r /dev/fd0 ${2:-4096} && {
	rdev -R /dev/fd0 1
	rdev /dev/fd0 /dev/fd0
	echo $start | awk '{printf"%c%c",$1%256,$1/256}' | dd of=/dev/fd0 bs=1 count=2 seek=502
	dd ${fs:+if=}$fs of=/dev/fd0 bs=1024 seek=$start
}
