Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: tape copy [and disk format questions] Message-ID: <10168@smoke.BRL.MIL> Date: 29 Apr 89 03:09:14 GMT References: <4601@drivax.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 87 /* 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 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; }