summaryrefslogtreecommitdiff
path: root/tools/atari-hd-image.sh
diff options
context:
space:
mode:
authorEero Tamminen <eerot@users.berlios.de>2009-03-23 22:00:21 (GMT)
committerEero Tamminen <eerot@users.berlios.de>2009-03-23 22:00:21 (GMT)
commit4b3e16bea1e093fc1d11dac1d57fc7c8a02d4643 (patch)
tree60ed66b788f65092fdafe2fe7ee77a2a5bc0b850 /tools/atari-hd-image.sh
parent62aea40c79a19e41b43696be39c524d4bccf9ea8 (diff)
downloadhatari-4b3e16bea1e093fc1d11dac1d57fc7c8a02d4643.zip
hatari-4b3e16bea1e093fc1d11dac1d57fc7c8a02d4643.tar.gz
major hd image creation updates:
- use "sfdisk" instead of "parted" as for that the partition type can be specified exactly (DOS FAT16, not VFAT) -> partitions are now compatible with Cecile - Create files originally as sparse to reduce disk churn - More error checks and verbosity - minimum working disk size can be 5MB
Diffstat (limited to 'tools/atari-hd-image.sh')
-rwxr-xr-xtools/atari-hd-image.sh98
1 files changed, 70 insertions, 28 deletions
diff --git a/tools/atari-hd-image.sh b/tools/atari-hd-image.sh
index eadf18b..741d173 100755
--- a/tools/atari-hd-image.sh
+++ b/tools/atari-hd-image.sh
@@ -27,26 +27,36 @@ if [ $# -lt 1 ]; then
exit 1
fi
-# parted/mkdosfs reside in /sbin
+# sfdisk/mkdosfs reside in /sbin
PATH=/sbin:$PATH
export PATH
# check tools
-if [ -z $(which parted) ] || [ -z $(which mkdosfs) ]; then
- echo "ERROR: either parted or mkdosfs missing!"
+if [ -z $(which sfdisk) ] || [ -z $(which mkdosfs) ]; then
+ echo "ERROR: either sfdisk or mkdosfs missing!"
exit 1
fi
-# check arguments
-if [ $1 -lt 8 ]; then
- echo "ERROR: disk size needs to be at least 8 (MB) to work properly."
+# check disk size
+if [ $1 -lt 5 ]; then
+ echo "ERROR: disk size needs to be at least 5 (MB) to work properly."
exit 1
fi
if [ $1 -gt 256 ]; then
echo "ERROR: EmuTOS supports only partitions up to 256 (MB)."
exit 1
fi
-disksize=$1
+# disk geometry
+cylinders=$((4*$1)) # 16*32*512 is 1/4MB
+diskheads=16
+tracksectors=32 # same as used by mkdosfs
+sectorsize=512
+partsize=$(($cylinders*$diskheads*$tracksectors*$sectorsize))
+
+# counts in sectors with correct disk geometry
+sfdisk="sfdisk -uS -C $cylinders -H $diskheads -S $tracksectors"
+
+# check optional arguments
if [ \! -z $2 ]; then
diskfile=$2
fi
@@ -54,6 +64,10 @@ if [ \! -z $3 ]; then
partname=$3
fi
if [ \! -z $4 ]; then
+ if [ -z $(which mcopy) ]; then
+ echo "ERROR: mcopy (from Mtools) missing!"
+ exit 1
+ fi
contentdir=$4
fi
@@ -87,44 +101,64 @@ trap exit_cleanup EXIT
echo
step=1
-# create disk image
-echo "$step) Creating disk image..."
-echo "dd if=/dev/zero of=$diskfile bs=1M count=$disksize"
-dd if=/dev/zero of=$diskfile bs=1M count=$disksize
+echo "$step) Creating $1MB sparse disk image..."
+echo "dd if=/dev/zero of=$diskfile bs=1 count=0 seek=$((512+partsize))"
+dd if=/dev/zero of=$diskfile bs=$((512+partsize)) count=1
echo
step=$(($step+1))
-# create DOS partition table and a bootable primary FAT16 partition to image
-echo "$step) Creating partition table + primary partition to the disk image..."
-echo "parted $diskfile mklabel msdos mkpart primary fat16 0 $disksize set 1 boot on"
-parted $diskfile mklabel msdos mkpart primary fat16 0 $disksize set 1 boot on || exit 2
+echo "$step) Creating DOS Master Boot Record partition table..."
+echo "Add DOS MBR signature needed by sfdisk:"
+echo -e "\0125\0252" | dd of=$diskfile bs=1 seek=510 count=2
+
+echo "Add partition table to MBR with single FAT16 partition:"
+clusters=$(($partsize/1024))
+if [ $clusters -le 32765 ]; then
+ fatbits=16
+ parttype="0x4"
+else
+ fatbits=16
+ parttype="0x6"
+fi
+echo "Using FAT$fatbits partition type $parttype"
+echo "$sfdisk --no-reread $diskfile: ,,$parttype,*"
+$sfdisk --no-reread $diskfile << EOF
+,,$parttype,*
+EOF
+if [ $? -ne 0 ]; then
+ exit 2
+fi
echo
step=$(($step+1))
-# create an Atari compatible DOS partition that fits to disk
-# size is in 1/2KB sectors, mkdosfs takes in kilobytes
-echo "$step) Creating Atari partition..."
-sectors=$(parted $diskfile unit s print | awk '/ 1 /{print $4}' | tr -d s)
-# mkdosfs keeps cluster count below 32765 when -A is used by increasing
-# the sector size (this is for TOS <1.04 compatibility, -A guarantees
-# also 2 sectors / cluster and Atari serial number etc). mtools barfs
-# if partition size doesn't divide evenly with track size which is by
-# default 32 sectors. Decrease file system size to make sure everything
-# is evenly aligned.
+echo "$step) Creating Atari TOS compatible DOS partition..."
+sectors=$($sfdisk -l $diskfile|awk '/\*/{print $5}')
+if [ -z "$sectors" ] || [ $sectors -eq 0 ]; then
+ echo "ERROR: couldn't get partition size information."
+ exit 2
+fi
+# mkdosfs keeps the sector count below 32765 when -A is used by increasing
+# the logical sector size (this is for TOS compatibility, -A guarantees
+# also 2 sectors / cluster and Atari serial number etc). Mtools barfs
+# if partition size doesn't divide evenly with its track size. Determine
+# suitable cluster count & corresponding track size and align (decrease)
+# the file system sector count accordingly.
tracksize=32
clustertmp=$((sectors/2))
+echo "Sectors: $sectors, sectors/track: $tracksize, clusters: $clustertmp"
while [ $clustertmp -gt 32765 ]; do
clustertmp=$((clustertmp/2))
tracksize=$(($tracksize*2))
+ echo "Doubling sector size as >32765 clusters -> $clustertmp clusters"
done
origsectors=$sectors
sectors=$(($sectors/$tracksize))
sectors=$(($sectors*$tracksize))
kilobytes=$(($sectors/2))
if [ $sectors -ne $origsectors ]; then
- echo "Align sector count with track size: $origsectors -> $sectors ($kilobytes kB)"
+ echo "Align sector count with clusters/sectors/track: $origsectors -> $sectors ($kilobytes kB)"
fi
-echo "mkdosfs -A -n $partname -C $tmppart $kilobytes"
+echo "mkdosfs -A -F $fatbits -n $partname -C $tmppart $kilobytes"
mkdosfs -A -n $partname -C $tmppart $kilobytes
if [ \! -z $contentdir ]; then
@@ -134,13 +168,21 @@ if [ \! -z $contentdir ]; then
echo "$step) Copying the initial content to the partition..."
echo "MTOOLS_NO_VFAT=1 mcopy -i $tmppart -spmv $contentdir/* ::"
MTOOLS_NO_VFAT=1 mcopy -i $tmppart -spmv $contentdir/* ::
+ if [ $? -ne 0 ]; then
+ echo "ERROR: failed."
+ exit 2
+ fi
fi
echo
step=$(($step+1))
# copy the partition into disk
echo "$step) Copying the partition to disk image..."
-start=$(parted $diskfile unit s print | awk '/ 1 /{print $2}' | tr -d s)
+start=$($sfdisk -l $diskfile|awk '/\*/{print $3}')
+if [ -z "$sectors" ] || [ $sectors -eq 0 ]; then
+ echo "ERROR: couldn't get partition start information."
+ exit 2
+fi
echo "dd if=$tmppart of=$diskfile bs=512 seek=$start count=$sectors"
dd if=$tmppart of=$diskfile bs=512 seek=$start count=$sectors