Message-ID: <39D1FD07.74B4E329@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>
Content-Type: multipart/mixed;
 boundary="------------34BBB9B4BDF7BBCFBEFBC3A2"
Lines: 310
Date: Wed, 27 Sep 2000 06:58:31 -0700
NNTP-Posting-Host: 139.142.84.10
X-Trace: read1 970063568 139.142.84.10 (Wed, 27 Sep 2000 08:06:08 MDT)
NNTP-Posting-Date: Wed, 27 Sep 2000 08:06:08 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!news.uunet.ca!feed1.cg.sfl.net!read1!139.142.84.10!206.29.186.234
Xref: news.adfa.oz.au comp.os.minix:35838

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

Kees J Bot wrote:
> #!/bin/sh
> #
> # Split an input stream in equal sized packages.

What version of dd was splitby written for?  Our system's dd is 4.0 from
GNU fileutils.
And refuses to write blocks from stdin over 4096 bytes.

Hence, splitby is close to useless for most applications without being
modified.  And these changes would be quite structural.

You might be interested in some results of a recent expiriment:

------
Guinea pig:
-rw-r--r--   1 root   root   22464295 Aug 30 01:04
linux-2.4.0-test7.tar.gz

Units:
1457664 bytes

Timings:

file / disk ratio 16:1
mean of 20 runs
Distribution     Combination
------------     -----------
real  0m8.137s   0m9.710s
user  0m0.370s   0m1.380s
sys   0m2.850s   0m6.770s

file / disk ratio 1:1
mean of 4 runs
Distribution     Combination
------------     ----------
real  15m38.630s 17m43.371s
user  0m0.870s   0m1.970s
sys   0m7.420s   0m8.370s

Operating conditions:
6:25am  up 2 days, 10:34,  5 users,  load average: 0.10, 0.14, 0.29
------

The above was accomplished with the revision attached below.  I believe
it shows economy...
--------------34BBB9B4BDF7BBCFBEFBC3A2
Content-Type: text/plain; charset=us-ascii;
 name="chop"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="chop"

#!/bin/bash
# chop - Chop any disk file into sticks of any length (except 0).

declare INCLUDE="/usr/local/lib/chop.sh" # Modify for your setting.
declare DRIVE="/dev/fd0h1440"		 # ditto. 
declare FSTAB="/etc/fstab"		 # ditto.
declare STDOUT="/dev/stdout"		 # ditto. 
declare -i i=0
declare -i DISCAP=1457664
declare -r MINMAJ="2"
declare -r MINMIN="03"
declare -r MINPAT="0"
declare -r EXT="+++"
declare -r NEXT="new"
declare -r NAMETAG="name.tag"
declare -r DEFNAME="chop.stuck"
declare -r IDSTR="CHOP"
declare -r SCRIPT="chop"
declare -r VERSION="0.08"
declare -r AUTHOR="root@slug"

let " ${BASH_VERSION%%.*} < $MINMAJ " &&
{ echo "$SCRIPT requires GNU bash ${MINMAJ}.${MINMIN}.${MINPAT}." >&2; exit 1; }
 
source $INCLUDE

case $# in
	(0) HELP_ARG=1; ;;
	(*) for j; do
		SetArgs $j;
	    done;
esac;

[[ $VERSION_ARG -ne 0 ]] &&
{
	PrnVer;
	exit 0;
}

[[ $HELP_ARG -ne 0 ]] &&
{
	PrnHelp;
	exit 0;
}

[[ $STICK_ARG -eq 0 ]] &&
{
	Errck 0 || { echo ${ERRMSG[0]} >&2; exit 1; }
	Errck 1 || FL_ARG=1;
	Mul_Length;
	Calc_Range;
	SetMPoint || { echo ${ERRMSG[3]}; exit 1; }
	while :; do
		case $FLEX_ARG in
			(1) FD_Mount $i; ;;
			(*) SpinWheel;
		esac;
		(( $i == $RANGE - 1 )) && break;
		Run_dd $CHOPFILE ${MPOINT}/${i}.$EXT $LENGTH $i;
		i=$(( i + 1 ));
	done;
	Implant_ID;
	FD_Umount;
	[[ $RO_ARG -ne 0 ]] || rm $CHOPFILE;
	echo $CHOPFILE >$NAMETAG;
	echo "$CHOPFILE was chopped into $RANGE sticks.";
	exit 0;
}

SetMPoint || { echo ${ERRMSG[3]} >&2; exit 1; }
Errck 3 || echo $DEFNAME >$NAMETAG;
STICKFILE=`cat $NAMETAG`;
[[ -a $STICKFILE ]] && STICKFILE=${STICKFILE}.${NEXT};
while :; do
	case $FLEX_ARG in
		(1) FD_Mount $i; ;;
		(*) SpinWheel;
	esac;
	Errck 2 || { echo ${ERRMSG[2]}; Abend; }
	Remove_ID && break;
	cat ${MPOINT}/${i}.$EXT >>$STICKFILE;
	[[ $RO_ARG -ne 0 ]] || rm ${MPOINT}/${i}.$EXT;
	i=$(( i + 1 ));
done;
[[ $RO_ARG -ne 0 ]] || rm ${MPOINT}/${i}.$EXT;
rm $NAMETAG;
FD_Umount;
echo "$(( i + 1 )) chops were stuck into ${STICKFILE}.";
# End.

--------------34BBB9B4BDF7BBCFBEFBC3A2
Content-Type: application/x-sh;
 name="chop.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="chop.sh"

# 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} );
	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 -n $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) dd if=${MPOINT}/${i}.$EXT bs=${#IDSTR} skip=1 2>/dev/null \
	    >>$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.

--------------34BBB9B4BDF7BBCFBEFBC3A2--

