#prepare part nr. Call only when prepnr = nr-1.

if [ $prepnr -ne $[$nr-1] ]; then
 echo
 echo "IRRECOVERABLE INTERNAL ERROR, please abort tbackup."
 echo
fi

#get part nr from the splitter.

#wait for splitter
if [ ! -e splitstatus ]; then
  echo "                         [waiting for part $nr to be completed]"
fi

while [ ! -e splitstatus ]; do 
  sleep 1; 
done

#splitter is ready

#we set prepnr this way to generate an internal error if floppywr and
#the splitter get out of sync.
 prepnr=`head -1 splitstatus`

if [ `tail -1 splitstatus` = "last" ]; then
  export lastpart=y
else
  export lastpart=n
#put helpful info in indexfile, if it is made
  if [ $makeindexfile = y ]; then
    echo "********** Approx. start of part $[$nr+1] **********" \
           >>$indexfilename
  fi

fi


#prepare part
# $dosname is the filename on the dos disk. $ecordosname for the ecor file
 dosname=`i2split -ppart $[$nr - 1]`
 dosname=`printf "%s.%03d\n" $dosname $[$nr % 1000]`

 ecordosname=`i2split -pecor $[$nr - 1]`
 ecordosname=`printf "%s.%03d\n" $ecordosname $[$nr % 1000]`

 mformat %:
 mcopy descr2k %:descr2k
 mcopy /tmp/tbup/bulk/part %:$dosname
 if [ $eccmethod != none ]; then
  mcopy /tmp/tbup/bulk/ecor %:$ecordosname
 fi

#indicate end of archive if needed.
 if [ $lastpart = y ]; then
  echo "$dosname" >part}
  mcopy part} %:part}
 fi

#signal splitter that part is read
rm splitstatus

