#!/bin/sh
#
# $Header: /home/kbackup/CVSROOT/KBackup/src/write_data_src,v 1.20 1997/09/19 19:49:25 kbackup Exp $
#
# This file is Copyright (C) 1995-1997 by Karsten Ballder (Ballueder@usa.net)
#
# It is part of the KBackup package, see the file COPYING for details.
# KBackup and all files included in this package are licensed and protected
# under the terms and conditions of the GNU General Public License Version 2.
#
#	If you want to contact the current maintainer of this software, please
#	send e-mail to: KBackup@usa.net
#
#	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
}



