Message-ID: <39D2FBBA.88193DDE@v-town.v-town.com>
From: Andrew Dennon <alex@v-town.v-town.com>
X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.17 i586)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.minix
Subject: Re: splitting up the usr.taz file...
References: <773y5.368$aH.51834@nntp1.chello.se> <slrn8smhea.bra.pino+comp_os_minix@mud.stack.nl> <39CC4180.84DB65EE@v-town.v-town.com> <slrn8srfke.hj.pino+comp_os_minix@mud.stack.nl> <t4ilq8.9b.ln@flotsam.cs.vu.nl> <39D1FD07.74B4E329@v-town.v-town.com> <slrn8t40av.9ga.pino+comp_os_minix@mud.stack.nl> <slrn8t410r.9ga.pino+comp_os_minix@mud.stack.nl>
Content-Type: multipart/mixed;
 boundary="------------65CC22C7CA722E57D21B0FE0"
Lines: 250
Date: Thu, 28 Sep 2000 01:05:14 -0700
NNTP-Posting-Host: 139.142.84.10
X-Trace: read1 970128675 139.142.84.10 (Thu, 28 Sep 2000 02:11:15 MDT)
NNTP-Posting-Date: Thu, 28 Sep 2000 02:11:15 MDT
Path: news.adfa.oz.au!clarion.carno.net.au!news0.optus.net.au!news1.optus.net.au!optus!intgwpad.nntp.telstra.net!news-hog.berkeley.edu!ucberkeley!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!west2.newsfeed.sprint-canada.net!feed1.cg.sfl.net!read1!139.142.84.10!206.29.186.228
Xref: news.adfa.oz.au comp.os.minix:35842

This is a multi-part message in MIME format.
--------------65CC22C7CA722E57D21B0FE0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Martijn van Buul wrote:
> ... which can be worked-around with something like
> 
> dd of=whatever bs=1k count=3x1440 skip=2x1440

With which the modification is less extensive.

I've implemented this and also a small optimization that has pushed it
half a second or so faster while distributing a large [21 MB] file on
the same disk.

Still however, the target is not just to fragment a file.  But to drag
it to [and from] a floppy.  This is where convenience counts.  And where
speed is measured in minutes...


Attached is; splitby, append, and the chop library with smarter
"Remove_ID" function.
--------------65CC22C7CA722E57D21B0FE0
Content-Type: text/plain; charset=us-ascii;
 name="splitby"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="splitby"

#!/bin/sh
#
# splitby - Split an input stream in equal sized packages.
#
# Written by Kees J. Bot.
# Workaround for GNU dd by Martijn van Buul.
# Workaround implement and slight optimization by Andrew Dennon.

case $# in
2)
	size="$1"
	name="$2"
	;;
*)
	echo "splitby <size-in-k> <name>" >&2
	exit 1
esac

i=1
even=`expr $size % 2`

case $even in
	0) bs=2; size=`expr $size / $bs` ;;
	*) bs=1
esac

while :; do
	dd of="$name.$i" bs="$bs"k count=$size || exit
	
	test -s "$name.$i" || break	# The last is of zero length.

	i=`expr $i + 1`
done

rm "$name.$i"	# Remove the zero length one.
# End.

--------------65CC22C7CA722E57D21B0FE0
Content-Type: text/plain; charset=us-ascii;
 name="append"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="append"

#!/bin/sh
# append - Append files with serial numeric extension.

i=1

test -a $1.$i || exit 1

while :; do
	cat $1.$i >>$1
	rm $1.$i
	i=`expr $i + 1`
	test -a $1.$i || break
done
# End.

--------------65CC22C7CA722E57D21B0FE0
Content-Type: text/plain; charset=us-ascii;
 name="chop.lib"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="chop.lib"

# chop.sh
# Function definitions for chop.

ERRMSG=([0]="No file to chop." \
	[1]="No stick length." \
	[2]="No chops to stick." \
	[3]="No mount point.")

SPOKE=(\| \/ \- \\)

function Abend()
{
	echo "Fatal error." >&2;
	FD_Umount;
	rm $NAMETAG;
	exit 2;
}

function Calc_Range()
{
	FILESIZE=$(( `ls -l $CHOPFILE |awk '{ print $5 }'` + ${#IDSTR} + 1 ));
	RANGE=$(( $FILESIZE / $LENGTH ));
	(( $FILESIZE % $LENGTH )) && RANGE=$(( RANGE + 1 ));
	return 0;
}

function Detect_ID()
{
	Run_dd ${MPOINT}/${i}.$EXT $STDOUT ${#IDSTR} 0 |grep -q $IDSTR;
	return $?;
}

function Errck()
{
	case $1 in
		(0) [[ -s $CHOPFILE ]]; return $?; ;;
		(1) [[ $LENGTH -gt 0 ]]; return $?; ;;
		(2) [[ -s ${MPOINT}/${i}.$EXT ]]; return $?; ;;
		(3) [[ -r $NAMETAG ]]; return $?; ;;
	esac;
}

function FD_Mount()
{
	FD_Umount;
	echo "Insert floppy disk "`number $((${1} + 1))`;
	echo "Press the Enter key when ready...";
	read;
	mount $DRIVE >/dev/null 2>&1 || { echo "Error." >&2; FD_Mount; }
	return 0;
}

function FD_Umount()
{
	umount $DRIVE >/dev/null 2>&1;
	return 0;
}

function Implant_ID()
{
	echo $IDSTR >${MPOINT}/${i}.$EXT;
	Run_dd $CHOPFILE $STDOUT $LENGTH $i |cat >>${MPOINT}/${i}.$EXT;
	return 0;
}

function Mul_Length()
{
	if (( $FL_ARG )); then LENGTH=$DISCAP; return 0; fi;
	case $MUL_ARG in
		(1) LENGTH=$(( LENGTH * 1024 )); ;;
		(2) LENGTH=$(( LENGTH * 1048576 )); ;;
		(3) LENGTH=$(( LENGTH * 1073741824 ));
	esac;
	[[ $LENGTH -le 0 ]] && LENGTH=$(( ~ LENGTH ));
	return 0;
}

function PrnHelp()
{
	echo "Usage: chop [-help] [-version] [-stick] [-flex] [-ro] file length"
	echo "            [-fl] [-k] [-m] [-g]"
	echo "       -help     = Print this help message."
	echo "       -version  = Print version information."
	echo "       -stick    = Stick a chopped file together."
	echo "       -flex     = Use the floppy exchanger."
	echo "       -ro       = Force non-destructive chopping [and sticking]."
	echo "       -fl       = Set length to floppy capacity [the default]."
	echo "       -k,-m,-g  = {Kilo,Mega,Giga}byte length multiplier."
	echo "        file     = Name of the file to chop."
	echo "        length   = Length in bytes of each stick to chop."
	echo "Note: The flex feature is expirimental, use cautiously."
	return 0;
}

function PrnVer()
{
	echo -e $SCRIPT $VERSION '\n'$AUTHOR;
	return 0;
}

function Remove_ID()
{
	Detect_ID;
	case $? in
	(0) cat ${MPOINT}/${i}.$EXT |sed /${IDSTR}/d >>$STICKFILE; ;;
	(*) return 1;
	esac;
	return 0;
}

function Run_dd()
{
	dd if=$1 of=$2 bs=$3 skip=$4 count=1 2>/dev/null;
	return 0; 
}

function SetArgs()
{
	case $1 in
		("-help") HELP_ARG=1; ;;
		("-version") VERSION_ARG=1; ;;
		("-stick") STICK_ARG=1; ;;
		("-flex") FLEX_ARG=1; ;;
		("-ro") RO_ARG=1; ;;
		("-fl") FL_ARG=1; ;;
		("-k") MUL_ARG=1; ;;
		("-m") MUL_ARG=2; ;;
		("-g") MUL_ARG=3; ;;
		(*) echo $1 |grep -q '[^0-9]';
		    if (( $? )); then LENGTH=$1; else CHOPFILE=$1; fi;
	esac;
	return 0;
}

function SetMPoint()
{
	case $FLEX_ARG in
		(1) MPOINT=`grep $DRIVE $FSTAB 2>/dev/null \
		    |awk '{ print $2 }'`;
		    [[ $MPOINT ]]; ;;
		(*) MPOINT=$PWD;
	esac;
	return $?;
}

function SpinWheel()
{
	echo -ne ${SPOKE[i % 3]}'\b';
	return 0;
}
# End.

--------------65CC22C7CA722E57D21B0FE0--

