Converting .tap files to real tapes

From: Andreas Holz <asholz_at_topinform.com>
Date: Wed Jun 18 10:38:00 2003

Christopher,

some questions to your program:

what does the statement do:

read(infile,&reclen,4); ?

this syntax does not conform to UNIX (POSIX) read (e.g. HP/UX):

ssize_t read(int filedes, void *buf, size_t nbyte);

Are these ".tap" files some kind of a standard format?

Background: I got some files which are claiming to be in a ".tap" format
and I would like to write the to tape!

Andreas




Christopher McNabb wrote:

>I've hacked together a 2.11 BSD C program (nothing special, should work
>on other *nixen) that takes a .tap tape file and spits it onto a real
>tape. I've tested it with both a TK50 and a TS05 tape drive. It even
>successfully wrote a bootable TK50 format XXDP 2.5 tape. I'm going to
>be cleaning up the code and posting it on the web, but for those who
>can't wait, here is the raw code. It is left as an exercise to the
>reader to figure out where my MUA breaks the source code lines.
>
>------------ Cut Here --------------------
>/* detap.c - 2003 by Christopher L McNabb */
>
>#include <stdio.h>
>#include <strings.h>
>#include <stdlib.h>
>#include <fcntl.h>
>#include <sys/file.h>
>#include <sys/inode.h>
>#include <sys/ioctl.h>
>#include <sys/mtio.h>
>
>main(argc, argv)
>int argc;
>char *argv[];
>{
> int infile,outfile,ctr;
> long int offset;
> long int records=1;
> long int filecnt=1;
> long int reclen;
> long int reclen2;
> void* buffer;
> struct mtop tapeeof,taperew;
>
> ctr = 0;
> taperew.mt_op = MTREW;
> taperew.mt_count = 1;
> tapeeof.mt_op = MTWEOF;
> tapeeof.mt_count = 1;
> if(argc < 3)
> {
> printf("Usage: %s infile outdev\n",argv[0]);
> exit(-1);
> }
> infile=open(argv[1],O_RDONLY);
> if(infile < 0)
> {
> printf("Could not open %s\n",argv[1]);
> exit(-1);
> }
> outfile=open(argv[2],O_CREAT | O_RDWR | O_TRUNC,IREAD | IWRITE);
> if(outfile < 0)
> {
> printf("Could not open %s\n",argv[2]);
> exit(-1);
> }
> printf("Rewinding Tape\n");
> if( 0 > ioctl(outfile,MTIOCTOP,&taperew))
> {
> printf("\nMTIOCOP REW ERROR\n");
> exit(-1);
> }
> offset = 0;
> read(infile,&reclen,4);
> while(1)
> {
> ctr ++;
> if(reclen == 0)
> {
> filecnt++;
> if(0 > ioctl(outfile,MTIOCTOP,&tapeeof))
> {
> printf("\nMTIOCTOP EOF ERR\n");
> exit(-1);
> }
> read(infile,&reclen,4);
> if(reclen == 0)
> {
> printf("\nEnd of Tape\n");
> close(outfile);
> ioctl(outfile,MTIOCTOP,&taperew);
> break;
> }
> records=1;
> continue;
> }
> buffer = malloc(reclen);
> read(infile,buffer,reclen);
> read(infile,&reclen2,4);
> if(reclen != reclen2)
> {
> lseek(infile,-3,L_INCR);
> read(infile,&reclen2,4);
> if(reclen != reclen2)
> {
> printf("\nHdr1 and Hdr2 do not match\n");
> exit(-1);
> }
> }
> write(outfile,buffer,reclen);
> fprintf(stdout,"Total Records: %6d File: %6ld Record: %6ld Record
>Length: %6u\r",ctr,filecnt,records,reclen);
> fflush(stdout);
> free(buffer);
> records++;
> read(infile,&reclen,4);
> }
> close(infile);
> close(outfile);
>}
>
>------------------- SNIP --------------------------
Received on Wed Jun 18 2003 - 10:38:00 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:36:08 BST