#!/bin/bash
#
#	writefsz {fs.z|-} [blocks]
#
#	This script writes the specified compressed file system image to
#	$fil (default=/dev/fd0).  It assumes that you've already done a
#	`make zdisk' (or copied the kernel with dd or cat onto the floppy
#	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
kernel=zImage

# If you're working on a file instead of /dev/fd0, 
# set this "fil" variable to the name of your file.
#
fil=/dev/fd0
# fil=cram

[ $# -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 | cut -d " " -f2`
 
rdev -r $fil $[16384+$start]  && {
	rdev -R $fil 0
	rdev $fil /dev/fd0
	dd ${fs:+if=}$fs of=$fil bs=1024 seek=$start
}
