tape copy [and disk format questions]

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Apr 29 13:09:14 AEST 1989


/*
	tcopy -- copy magnetic tape

	original version due to Ron Natalie
	last edit:	86/06/08	D A Gwyn

	Usage:	tcopy /dev/rmt12 /dev/rmt13	# for example

	Arguments must be names of non-rewinding magtape devices	
*/
#ifndef	lint
static char	SCCS_id[] = "@(#)tcopy.c	1.1";
#endif

#include	<stdio.h>

extern void	exit(), perror();
extern int	close(), open(), read(), write();

#define	MAXSIZE	20*1024
static char	buffer[MAXSIZE];

static void
error( msg )
	char	*msg;
	{
 	perror( msg );
	exit( 1 );
	}

main( argc, argv )
	int	argc;
	char	*argv[];
	{
	register int	from, to;	/* I/O file descriptors */
	register int	nc, wc;		/* # chars read/written */
	int	bs;			/* file blocksize */
	long	count;			/* file block counter */

	if ( argc != 3 )
		{
		(void)fprintf( stderr, "Usage: tcopy from-dev to-dev\n" );
		exit( 2 );
		}

	do	{
		if ( (from = open( argv[1], 0 )) < 0 )
			error( argv[1] );

		if ( (to = open( argv[2], 1 )) < 0 )
			error( argv[2] );

		count = 0L;
		do	{
			if ( (nc = read( from, buffer, MAXSIZE )) < 0 )
				error( argv[1] );

			if ( count == 0L )
				bs = nc;	/* use first blocksize */

			if ( nc > 0 )
				{
				++count;

				if ( (wc = write( to, buffer, nc )) != nc )
					error( argv[2] );
				}
			}
		while ( nc > 0 );

		if ( close( from ) != 0 )
			error( argv[1] );

		if ( close( to ) != 0 )
			error( argv[2] );

		if ( count == 0L )
			(void)fprintf( stderr, "EOF\n" );
		else
			(void)fprintf( stderr, "%ld records, blocksize %d\n",
				       count, bs
				     );
		}
	while ( count > 0L );

	return 0;
	}



More information about the Comp.unix.questions mailing list