#
# $Header: /home/kbackup/CVSROOT/KBackup/src/write_data_src,v 1.16 1996/10/06 16:12:40 kbackup Exp $
#
# This file is Copyright (C) 1995 by Karsten Ballder
#				Karsten.Ballueder@stud.uni-karlsruhe.de
#
# It is part of the KBackup package, see the file COPYING for details.
#
#
#	function to reliably write data to tape, including double buffering
#	and multi-volume handling [DB+multivol w/ multibuf only]
#

WriteData_src_loaded=YES

write_data()
{
	if [ "$1" = "-raw" ]
	then
		shift
		if [ "$1" != "" ]
		then
			wdfile="$1"
		else
			wdfile="$device"
		fi
		multibuf_cmd=`echo $DD of=$wdfile ibs=$syncto conv=sync`
	else
		if [ "$1" != "" ]
		then
			wdfile="$1"
		else
			wdfile="$device"
		fi
		if [ "$use_multibuf" = "YES" ]
		then
			set_multibuf_options WRITE
			multibuf_cmd=`echo "$MULTIBUF $multibuf_options -b $multibuf_blksize -n $multibuf_nblocks $wdfile" `
		else
			multibuf_cmd=`echo $DD of=$wdfile ibs=$syncto conv=sync `
		fi
	fi	
	

	if [ "$remote_mode" = "YES" ]
	then
		last_command="su in write_data()"
		cat $TMP/$MBUF_SCRIPT1 | su $remote_uid -c "rsh $remote_host \"cat >$TMP/$MBUF_SCRIPT1\"" 
		cat $TMP/$MBUF_SCRIPT2 | su $remote_uid -c "rsh $remote_host \"cat >$TMP/$MBUF_SCRIPT2\"" 
		cat $TMP/$MBUF_SCRIPTR | su $remote_uid -c "rsh $remote_host \"cat >$TMP/$MBUF_SCRIPTR\"" 
		su $remote_uid -c "rsh $remote_host \"$DD ibs=$multibuf_blksize conv=sync | $multibuf_cmd ; sleep 10\""
	else
		last_command="$DD and multibuf in write_data()"
		`echo $multibuf_cmd` 2>$STDERR
		check_error
	fi
	mysleep 5	# for tpqic02
}



