#!/bin/sh
# mkpartition - for dosemu 0.51
#    Robert Sanders, gt8134b@prism.gatech.edu
#
# $Date: 1994/04/16 01:30:17 $
# $Source: /home/src/dosemu0.60/periph/RCS/mkpartition,v $
# $Revision: 1.3 $
# $State: Exp $
#
# For details about Direct Partition Access (DPA) read the manual
# of the Linux DOS-emulator.
#

ME=`basename $0`                    # Name of the command
DRIVE=$1                            # complete hard-disk-device
PARTNUM=$2                          # number of the partition on $DRIVE
PART=${DRIVE}${PARTNUM}             # complete name of the partition
ETCD=/etc/dosemu                    # Directory, where the partition-file is
PFILE=${ETCD}/partition             # Partial name of the partition file

echo "MKPARTITION for the Linux DOS-emulator "
echo

if [  $# != 2 ] ; then
    echo "$ME needs two parameters to work right:"
    echo
    echo "usage:    $ME <drive> <partition>"
    echo
    echo "example:"
    echo "  If you'd like to access you DOS-partition /dev/hda2 with"
    echo "  dosemu's DPA (direct partition access), issue the command"
    echo
    echo "          $ME /dev/hda 2             (as root)"
    echo
    echo "For details about Direct Partition Access (DPA) read the manual"
    echo "of the Linux DOS-emulator."
    echo

    exit 1
fi

PFILE=${PFILE}.`basename $PART`    # Name of the real file

echo "Setting up dosemu to use partition $PART from drive $DRIVE..."

if [ $PARTNUM -gt 8 ]
then
	echo "$ME: $PARTNUM outside range; the highest partition is 8"
	exit 1
fi

if [ ! -r "$DRIVE" -o ! -r "$PART" ]
then
	echo "$ME: drive <$DRIVE> or partition <$PART> non-readable or absent"
	exit 1
fi

if [ -r "$PFILE" ]
then
	echo "Backing up $PFILE to $PFILE.old"
	mv $PFILE ${PFILE}.old
fi

# Filename of the partition-file contains now the partition to be used.
# This should enable us to use more that one partition on one disk.
# The resulting file should have permissions 644 (any comments?)

dd if=$DRIVE of=$PFILE bs=512 count=1

chmod 644 $PFILE

# End of mkpartition from the Linux DOS-emulator
